2 * Copyright (c) 2017 Pantheon Technologies s.r.o. 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
9 package org.opendaylight.mdsal.binding.javav2.dom.adapter.extractor;
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertTrue;
13 import static org.junit.Assert.fail;
14 import static org.mockito.Mockito.mock;
16 import java.lang.reflect.Method;
17 import org.junit.Test;
18 import org.opendaylight.mdsal.binding.javav2.spec.base.InstanceIdentifier;
19 import org.opendaylight.mdsal.binding.javav2.spec.base.TreeNode;
21 public class DirectGetterRouteContextExtractorTest {
23 private static final InstanceIdentifier INSTANCE_IDENTIFIER = InstanceIdentifier.create(TreeNode.class);
24 private static final String EXCEPTION_TEXT = "testException";
27 public void basicTest() throws Exception {
28 final Method testMthd = this.getClass().getDeclaredMethod("testMethod", TreeNode.class);
29 testMthd.setAccessible(true);
30 final ContextReferenceExtractor referenceExtractor = DirectGetterRouteContextExtractor.create(testMthd);
31 assertEquals(testMethod(mock(TreeNode.class)), referenceExtractor.extract(mock(TreeNode.class)));
34 referenceExtractor.extract(null);
35 fail("Expected exception");
36 } catch (NullPointerException e) {
37 assertTrue(e.getMessage().equals(EXCEPTION_TEXT));
41 private static InstanceIdentifier testMethod(TreeNode data) {
43 throw new NullPointerException(EXCEPTION_TEXT);
45 return INSTANCE_IDENTIFIER;