Populate data/ hierarchy
[yangtools.git] / yang / yang-model-api / src / test / java / org / opendaylight / yangtools / yang / model / api / meta / EffectiveStatementTest.java
1 /*
2  * Copyright (c) 2018 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.model.api.meta;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.mockito.ArgumentMatchers.any;
12 import static org.mockito.Mockito.doCallRealMethod;
13 import static org.mockito.Mockito.doReturn;
14
15 import com.google.common.collect.ImmutableList;
16 import java.util.Map;
17 import java.util.Optional;
18 import java.util.stream.Collectors;
19 import org.junit.Before;
20 import org.junit.Test;
21 import org.junit.runner.RunWith;
22 import org.mockito.Mock;
23 import org.mockito.junit.MockitoJUnitRunner;
24
25 @RunWith(MockitoJUnitRunner.StrictStubs.class)
26 public class EffectiveStatementTest {
27     @Mock
28     public EffectiveStatement1 stmt;
29     @Mock
30     public EffectiveStatement1 stmt1;
31     @Mock
32     public Effectivestatement2 stmt2;
33     @Mock
34     public Map<?, ?> mockNamespace;
35
36     @Before
37     public void before() {
38         doReturn("one").when(stmt1).argument();
39         doReturn("two").when(stmt2).argument();
40         doReturn(ImmutableList.of(stmt1, stmt2)).when(stmt).effectiveSubstatements();
41         doCallRealMethod().when(stmt).findFirstEffectiveSubstatement(any());
42         doCallRealMethod().when(stmt).findFirstEffectiveSubstatementArgument(any());
43         doCallRealMethod().when(stmt).streamEffectiveSubstatements(any());
44     }
45
46     @Test
47     public void testFindFirstDeclaredSubstatement() {
48         assertEquals(Optional.of(stmt1), stmt.findFirstEffectiveSubstatement(EffectiveStatement1.class));
49         assertEquals(Optional.of(stmt2), stmt.findFirstEffectiveSubstatement(Effectivestatement2.class));
50     }
51
52     @Test
53     public void testFindFirstDeclaredSubstatementArgument() {
54         assertEquals(Optional.of("one"), stmt.findFirstEffectiveSubstatementArgument(EffectiveStatement1.class));
55         assertEquals(Optional.of("two"), stmt.findFirstEffectiveSubstatementArgument(Effectivestatement2.class));
56     }
57
58     @Test
59     public void testStreamEffectiveSubstatements() {
60         assertEquals(ImmutableList.of(stmt1), stmt.streamEffectiveSubstatements(EffectiveStatement1.class)
61             .collect(Collectors.toList()));
62         assertEquals(ImmutableList.of(stmt2), stmt.streamEffectiveSubstatements(Effectivestatement2.class)
63             .collect(Collectors.toList()));
64     }
65 }