StatementSupport is not a StatementDefinition
[yangtools.git] / parser / yang-parser-spi / src / test / java / org / opendaylight / yangtools / yang / parser / spi / source / QNameToStatementDefinitionMapTest.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 package org.opendaylight.yangtools.yang.parser.spi.source;
9
10 import static org.junit.Assert.assertSame;
11 import static org.junit.Assert.assertThrows;
12 import static org.mockito.Mockito.doReturn;
13 import static org.mockito.Mockito.mock;
14
15 import org.junit.Before;
16 import org.junit.Test;
17 import org.opendaylight.yangtools.yang.common.QName;
18 import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
19 import org.opendaylight.yangtools.yang.parser.spi.meta.StatementSupport;
20
21 public class QNameToStatementDefinitionMapTest {
22     private static final QName QNAME = QName.create("", "a");
23
24     private final QNameToStatementDefinitionMap map = new QNameToStatementDefinitionMap();
25     private final StatementSupport<?, ?, ?> support = mock(StatementSupport.class);
26     private final StatementDefinition definition = mock(StatementDefinition.class);
27
28     @Before
29     public void before() {
30         doReturn(definition).when(support).definition();
31     }
32
33     @Test
34     public void testPutNullNull() {
35         assertThrows(NullPointerException.class, () -> map.put(null, null));
36     }
37
38     @Test
39     public void testPutNullSome() {
40         assertThrows(NullPointerException.class, () -> map.put(null, support));
41     }
42
43     @Test
44     public void testPutSomeNull() {
45         assertThrows(NullPointerException.class, () -> map.put(QName.create("", "a"), null));
46     }
47
48     @Test
49     public void testPut() {
50         map.put(QNAME, support);
51         assertSame(definition, map.get(QNAME));
52         assertSame(support, map.getSupport(QNAME));
53     }
54 }