Binding2-dom-adapter JUnit code coverage increase
[mdsal.git] / binding2 / mdsal-binding2-dom-adapter / src / test / java / org / opendaylight / mdsal / binding / javav2 / dom / adapter / extractor / DirectGetterRouteContextExtractorTest.java
1 /*
2  * Copyright (c) 2017 Pantheon Technologies s.r.o. and others.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.mdsal.binding.javav2.dom.adapter.extractor;
10
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;
15
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;
20
21 public class DirectGetterRouteContextExtractorTest {
22
23     private static final InstanceIdentifier INSTANCE_IDENTIFIER = InstanceIdentifier.create(TreeNode.class);
24     private static final String EXCEPTION_TEXT = "testException";
25
26     @Test
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)));
32
33         try {
34             referenceExtractor.extract(null);
35             fail("Expected exception");
36         } catch (NullPointerException e) {
37             assertTrue(e.getMessage().equals(EXCEPTION_TEXT));
38         }
39     }
40
41     private static InstanceIdentifier testMethod(TreeNode data) {
42         if (data == null) {
43             throw new NullPointerException(EXCEPTION_TEXT);
44         }
45         return INSTANCE_IDENTIFIER;
46     }
47 }