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