Migrate yang-repo-spi to JUnit5
[yangtools.git] / yang / yang-repo-spi / src / test / java / org / opendaylight / yangtools / yang / model / repo / spi / PotentialSchemaSourceTest.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.repo.spi;
9
10 import static org.junit.jupiter.api.Assertions.assertEquals;
11 import static org.junit.jupiter.api.Assertions.assertNotEquals;
12 import static org.junit.jupiter.api.Assertions.assertSame;
13 import static org.junit.jupiter.api.Assertions.assertThrows;
14
15 import org.junit.jupiter.api.BeforeEach;
16 import org.junit.jupiter.api.Test;
17 import org.junit.jupiter.api.extension.ExtendWith;
18 import org.mockito.junit.jupiter.MockitoExtension;
19 import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
20 import org.opendaylight.yangtools.yang.model.repo.api.YangSchemaSourceRepresentation;
21
22 @ExtendWith(MockitoExtension.class)
23 class PotentialSchemaSourceTest {
24     private interface TestSchemaSourceRepresentation extends YangSchemaSourceRepresentation {
25         @Override
26         default Class<TestSchemaSourceRepresentation> getType() {
27             return TestSchemaSourceRepresentation.class;
28         }
29     }
30
31     public final SourceIdentifier sourceIdentifier = new SourceIdentifier("foo");
32     @SuppressWarnings("exports")
33     public PotentialSchemaSource<TestSchemaSourceRepresentation> source;
34     @SuppressWarnings("exports")
35     public PotentialSchemaSource<TestSchemaSourceRepresentation> same;
36
37     @BeforeEach
38     void before() {
39         source = PotentialSchemaSource.create(sourceIdentifier, TestSchemaSourceRepresentation.class,
40             PotentialSchemaSource.Costs.LOCAL_IO.getValue());
41         same = PotentialSchemaSource.create(source.getSourceIdentifier(), source.getRepresentation(),
42             source.getCost());
43     }
44
45     @Test
46     void testNegativeCost() {
47         assertThrows(IllegalArgumentException.class,
48             () -> PotentialSchemaSource.create(sourceIdentifier, TestSchemaSourceRepresentation.class, -1));
49     }
50
51     @Test
52     void testMethods() {
53         assertEquals(PotentialSchemaSource.Costs.LOCAL_IO.getValue(), source.getCost());
54         assertSame(sourceIdentifier, source.getSourceIdentifier());
55         assertSame(TestSchemaSourceRepresentation.class, source.getRepresentation());
56         assertEquals(same.hashCode(), source.hashCode());
57         assertNotEquals(null, source);
58         assertEquals(source, source);
59         assertEquals(source, same);
60     }
61
62     @Test
63     void testIntern() {
64         assertSame(source, source.cachedReference());
65         assertSame(source, same.cachedReference());
66     }
67 }