951a8842ac5fcfcae61d5ad43e1916c65971b140
[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.Mock;
20 import org.mockito.junit.MockitoJUnitRunner;
21 import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceRepresentation;
22 import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
23
24 @RunWith(MockitoJUnitRunner.StrictStubs.class)
25 public class PotentialSchemaSourceTest {
26     private interface TestSchemaSourceRepresentation extends SchemaSourceRepresentation {
27
28     }
29
30     @Mock
31     public SourceIdentifier sourceIdentifier;
32     @SuppressWarnings("exports")
33     public PotentialSchemaSource<TestSchemaSourceRepresentation> source;
34     @SuppressWarnings("exports")
35     public PotentialSchemaSource<TestSchemaSourceRepresentation> same;
36
37     @Before
38     public 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     public void testNegativeCost() {
47         assertThrows(IllegalArgumentException.class,
48             () -> PotentialSchemaSource.create(sourceIdentifier, TestSchemaSourceRepresentation.class, -1));
49     }
50
51     @Test
52     public 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         assertFalse(source.equals(null));
58         assertTrue(source.equals(source));
59         assertTrue(source.equals(same));
60     }
61
62     @Test
63     public void testIntern() {
64         assertSame(source, source.cachedReference());
65         assertSame(source, same.cachedReference());
66     }
67 }