2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.mdsal.binding.dom.adapter;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertThrows;
12 import static org.mockito.Mockito.mock;
14 import org.junit.Test;
15 import org.opendaylight.yang.gen.v1.urn.yang.foo.rev160101.BooleanContainer;
16 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
18 public class DirectGetterRouteContextExtractorTest {
19 private static final InstanceIdentifier<?> INSTANCE_IDENTIFIER = InstanceIdentifier.create(BooleanContainer.class);
20 private static final String EXCEPTION_TEXT = "testException";
23 public void basicTest() throws IllegalAccessException, NoSuchMethodException {
24 final ContextReferenceExtractor referenceExtractor = DirectGetterRouteContextExtractor.create(
25 getClass().getDeclaredMethod("testMethod", BooleanContainer.class));
26 assertEquals(INSTANCE_IDENTIFIER, referenceExtractor.extract(mock(BooleanContainer.class)));
28 assertEquals(EXCEPTION_TEXT,
29 assertThrows(NullPointerException.class, () -> referenceExtractor.extract(null)).getMessage());
32 public static InstanceIdentifier<?> testMethod(final BooleanContainer data) {
34 throw new NullPointerException(EXCEPTION_TEXT);
36 return INSTANCE_IDENTIFIER;