Merge branch 'master' of ../controller
[yangtools.git] / yang / yang-model-api / 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.assertTrue;
14
15 import org.junit.Before;
16 import org.junit.Test;
17 import org.junit.runner.RunWith;
18 import org.mockito.Mock;
19 import org.mockito.junit.MockitoJUnitRunner;
20 import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceRepresentation;
21 import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
22
23 @RunWith(MockitoJUnitRunner.StrictStubs.class)
24 public class PotentialSchemaSourceTest {
25     private interface TestSchemaSourceRepresentation extends SchemaSourceRepresentation {
26
27     }
28
29     @Mock
30     private SourceIdentifier sourceIdentifier;
31     private PotentialSchemaSource<TestSchemaSourceRepresentation> source;
32     private PotentialSchemaSource<TestSchemaSourceRepresentation> same;
33
34     @Before
35     public void before() {
36         source = PotentialSchemaSource.create(sourceIdentifier, TestSchemaSourceRepresentation.class,
37             PotentialSchemaSource.Costs.LOCAL_IO.getValue());
38         same = PotentialSchemaSource.create(source.getSourceIdentifier(), source.getRepresentation(),
39             source.getCost());
40     }
41
42     @Test(expected = IllegalArgumentException.class)
43     public void testNegativeCost() {
44         PotentialSchemaSource.create(sourceIdentifier, TestSchemaSourceRepresentation.class, -1);
45     }
46
47     @Test
48     public void testMethods() {
49         assertEquals(PotentialSchemaSource.Costs.LOCAL_IO.getValue(), source.getCost());
50         assertSame(sourceIdentifier, source.getSourceIdentifier());
51         assertSame(TestSchemaSourceRepresentation.class, source.getRepresentation());
52         assertEquals(same.hashCode(), source.hashCode());
53         assertFalse(source.equals(null));
54         assertTrue(source.equals(source));
55         assertTrue(source.equals(same));
56     }
57
58     @Test
59     public void testIntern() {
60         assertSame(source, source.cachedReference());
61         assertSame(source, same.cachedReference());
62     }
63 }