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.assertTrue;
12 import static org.junit.Assert.fail;
13 import static org.mockito.Mockito.mock;
15 import java.lang.reflect.Method;
16 import org.junit.Test;
17 import org.opendaylight.yangtools.yang.binding.DataObject;
18 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
20 public class DirectGetterRouteContextExtractorTest {
22 private static final InstanceIdentifier INSTANCE_IDENTIFIER = InstanceIdentifier.create(DataObject.class);
23 private static final String EXCEPTION_TEXT = "testException";
26 public void basicTest() throws Exception {
27 final Method testMthd = this.getClass().getDeclaredMethod("testMethod", DataObject.class);
28 testMthd.setAccessible(true);
29 final ContextReferenceExtractor referenceExtractor = DirectGetterRouteContextExtractor.create(testMthd);
30 assertEquals(testMethod(mock(DataObject.class)), referenceExtractor.extract(mock(DataObject.class)));
33 referenceExtractor.extract(null);
34 fail("Expected exception");
35 } catch (NullPointerException e) {
36 assertTrue(e.getMessage().equals(EXCEPTION_TEXT));
40 private static InstanceIdentifier testMethod(DataObject data) {
42 throw new NullPointerException(EXCEPTION_TEXT);
44 return INSTANCE_IDENTIFIER;