Enforce InstanceIdentifier creation
[mdsal.git] / binding / mdsal-binding-dom-adapter / src / test / java / org / opendaylight / mdsal / binding / dom / adapter / DirectGetterRouteContextExtractorTest.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. 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 package org.opendaylight.mdsal.binding.dom.adapter;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertThrows;
12 import static org.mockito.Mockito.mock;
13
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;
17
18 public class DirectGetterRouteContextExtractorTest {
19     private static final InstanceIdentifier<?> INSTANCE_IDENTIFIER = InstanceIdentifier.create(BooleanContainer.class);
20     private static final String EXCEPTION_TEXT = "testException";
21
22     @Test
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)));
27
28         assertEquals(EXCEPTION_TEXT,
29             assertThrows(NullPointerException.class, () -> referenceExtractor.extract(null)).getMessage());
30     }
31
32     public static InstanceIdentifier<?> testMethod(final BooleanContainer data) {
33         if (data == null) {
34             throw new NullPointerException(EXCEPTION_TEXT);
35         }
36         return INSTANCE_IDENTIFIER;
37     }
38 }