2 * Copyright (c) 2018 Pantheon Technologies, s.r.o. and others. All rights reserved.
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
8 package org.opendaylight.yangtools.yang.model.repo.spi;
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;
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;
22 @ExtendWith(MockitoExtension.class)
23 class PotentialSchemaSourceTest {
24 private interface TestSchemaSourceRepresentation extends YangSchemaSourceRepresentation {
26 default Class<TestSchemaSourceRepresentation> getType() {
27 return TestSchemaSourceRepresentation.class;
31 public final SourceIdentifier sourceIdentifier = new SourceIdentifier("foo");
32 @SuppressWarnings("exports")
33 public PotentialSchemaSource<TestSchemaSourceRepresentation> source;
34 @SuppressWarnings("exports")
35 public PotentialSchemaSource<TestSchemaSourceRepresentation> same;
39 source = PotentialSchemaSource.create(sourceIdentifier, TestSchemaSourceRepresentation.class,
40 PotentialSchemaSource.Costs.LOCAL_IO.getValue());
41 same = PotentialSchemaSource.create(source.getSourceIdentifier(), source.getRepresentation(),
46 void testNegativeCost() {
47 assertThrows(IllegalArgumentException.class,
48 () -> PotentialSchemaSource.create(sourceIdentifier, TestSchemaSourceRepresentation.class, -1));
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);
64 assertSame(source, source.cachedReference());
65 assertSame(source, same.cachedReference());