<groupId>org.opendaylight.yangtools</groupId>
<artifactId>yang-repo-api</artifactId>
</dependency>
+
+ <dependency>
+ <groupId>org.opendaylight.yangtools</groupId>
+ <artifactId>mockito-configuration</artifactId>
+ </dependency>
</dependencies>
</project>
*/
package org.opendaylight.yangtools.yang.model.repo.spi;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
import com.google.common.base.MoreObjects.ToStringHelper;
-import java.io.Reader;
import java.io.StringReader;
import java.util.Optional;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
+import org.mockito.junit.jupiter.MockitoExtension;
import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
import org.opendaylight.yangtools.yang.model.repo.api.YangSchemaSourceRepresentation;
import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
@Deprecated
-@RunWith(MockitoJUnitRunner.StrictStubs.class)
-public class GuavaSchemaSourceCacheTest {
- public static final Class<YangSchemaSourceRepresentation> REPRESENTATION = YangSchemaSourceRepresentation.class;
- public static final long LIFETIME = 1000L;
- public static final TimeUnit UNITS = TimeUnit.MILLISECONDS;
+@ExtendWith(MockitoExtension.class)
+class GuavaSchemaSourceCacheTest {
+ private static final Class<YangSchemaSourceRepresentation> REPRESENTATION = YangSchemaSourceRepresentation.class;
+ private static final long LIFETIME = 1000L;
+ private static final TimeUnit UNITS = TimeUnit.MILLISECONDS;
@Mock
public SchemaSourceRegistry registry;
@Mock
public SchemaSourceRegistration<?> registration;
- @Before
- public void setUp() {
- doNothing().when(registration).close();
- doReturn(registration).when(registry).registerSchemaSource(any(SchemaSourceProvider.class),
- any(PotentialSchemaSource.class));
- }
-
@Test
- public void inMemorySchemaSourceCacheTest1() {
+ void inMemorySchemaSourceCacheTest1() {
try (var cache = GuavaSchemaSourceCache.createSoftCache(registry, REPRESENTATION)) {
assertNotNull(cache);
}
}
@Test
- public void inMemorySchemaSourceCacheTest2() {
+ void inMemorySchemaSourceCacheTest2() {
try (var cache = GuavaSchemaSourceCache.createSoftCache(registry, REPRESENTATION, LIFETIME, UNITS)) {
assertNotNull(cache);
}
}
@Test
- public void inMemorySchemaSourceCacheOfferAndGetSourcestest() throws Exception {
+ void inMemorySchemaSourceCacheOfferAndGetSourcestest() throws Exception {
+ doNothing().when(registration).close();
+ doReturn(registration).when(registry).registerSchemaSource(any(), any());
+
try (var cache = GuavaSchemaSourceCache.createSoftCache(registry, REPRESENTATION)) {
- final String content = "content";
- final YangTextSchemaSource source = new TestingYangSource("test", "2012-12-12", content);
+ final var content = "content";
+ final var source = new TestingYangSource("test", "2012-12-12", content);
cache.offer(source);
final var sourceIdentifier = new SourceIdentifier("test", "2012-12-12");
final var checkedSource = cache .getSource(sourceIdentifier);
}
@Test
- public void inMemorySchemaSourceCacheNullGetSourcestest() throws Exception {
+ void inMemorySchemaSourceCacheNullGetSourcestest() throws Exception {
try (var cache = GuavaSchemaSourceCache.createSoftCache(registry, REPRESENTATION)) {
final var sourceIdentifier = new SourceIdentifier("test", "2012-12-12");
final var checkedSource = cache.getSource(sourceIdentifier);
assertNotNull(checkedSource);
- assertThrows(ExecutionException.class, () -> checkedSource.get());
+ assertThrows(ExecutionException.class, checkedSource::get);
}
}
@Test
- public void inMemorySchemaSourceCache3test() throws InterruptedException, ExecutionException {
+ void inMemorySchemaSourceCache3test() throws InterruptedException, ExecutionException {
+ doNothing().when(registration).close();
+ doReturn(registration).when(registry).registerSchemaSource(any(), any());
+
try (var cache1 = GuavaSchemaSourceCache.createSoftCache(registry, REPRESENTATION)) {
try (var cache2 = GuavaSchemaSourceCache.createSoftCache(registry, REPRESENTATION, LIFETIME, UNITS)) {
- final String content = "content";
- final YangTextSchemaSource source = new TestingYangSource("test", "2012-12-12", content);
+ final var content = "content";
+ final var source = new TestingYangSource("test", "2012-12-12", content);
cache1.offer(source);
cache2.offer(source);
}
@Override
- public Reader openStream() {
+ public StringReader openStream() {
return new StringReader(content);
}
*/
package org.opendaylight.yangtools.yang.model.repo.spi;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertThrows;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertThrows;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.junit.MockitoJUnitRunner;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.junit.jupiter.MockitoExtension;
import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
import org.opendaylight.yangtools.yang.model.repo.api.YangSchemaSourceRepresentation;
-@RunWith(MockitoJUnitRunner.StrictStubs.class)
-public class PotentialSchemaSourceTest {
+@ExtendWith(MockitoExtension.class)
+class PotentialSchemaSourceTest {
private interface TestSchemaSourceRepresentation extends YangSchemaSourceRepresentation {
@Override
default Class<TestSchemaSourceRepresentation> getType() {
@SuppressWarnings("exports")
public PotentialSchemaSource<TestSchemaSourceRepresentation> same;
- @Before
- public void before() {
+ @BeforeEach
+ void before() {
source = PotentialSchemaSource.create(sourceIdentifier, TestSchemaSourceRepresentation.class,
PotentialSchemaSource.Costs.LOCAL_IO.getValue());
same = PotentialSchemaSource.create(source.getSourceIdentifier(), source.getRepresentation(),
}
@Test
- public void testNegativeCost() {
+ void testNegativeCost() {
assertThrows(IllegalArgumentException.class,
() -> PotentialSchemaSource.create(sourceIdentifier, TestSchemaSourceRepresentation.class, -1));
}
@Test
- public void testMethods() {
+ void testMethods() {
assertEquals(PotentialSchemaSource.Costs.LOCAL_IO.getValue(), source.getCost());
assertSame(sourceIdentifier, source.getSourceIdentifier());
assertSame(TestSchemaSourceRepresentation.class, source.getRepresentation());
assertEquals(same.hashCode(), source.hashCode());
- assertFalse(source.equals(null));
- assertTrue(source.equals(source));
- assertTrue(source.equals(same));
+ assertNotEquals(null, source);
+ assertEquals(source, source);
+ assertEquals(source, same);
}
@Test
- public void testIntern() {
+ void testIntern() {
assertSame(source, source.cachedReference());
assertSame(source, same.cachedReference());
}
*/
package org.opendaylight.yangtools.yang.model.repo.spi;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.doNothing;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
+import org.mockito.junit.jupiter.MockitoExtension;
-@RunWith(MockitoJUnitRunner.class)
-public class RefcountedRegistrationTest {
+@ExtendWith(MockitoExtension.class)
+class RefcountedRegistrationTest {
@Mock
- public SchemaSourceRegistration<?> reg;
-
- @Before
- public void before() {
- doNothing().when(reg).close();
- }
+ private SchemaSourceRegistration<?> reg;
@Test
- public void refcountDecTrue() {
- final RefcountedRegistration ref = new RefcountedRegistration(reg);
+ void refcountDecTrue() {
+ final var ref = new RefcountedRegistration(reg);
+ doNothing().when(reg).close();
assertTrue(ref.decRef());
- verify(reg, times(1)).close();
}
@Test
- public void refcountIncDecFalse() {
- final RefcountedRegistration ref = new RefcountedRegistration(reg);
+ void refcountIncDecFalse() {
+ final var ref = new RefcountedRegistration(reg);
ref.incRef();
assertFalse(ref.decRef());
- verify(reg, times(0)).close();
}
@Test
- public void refcountIncDecTrue() {
- final RefcountedRegistration ref = new RefcountedRegistration(reg);
+ void refcountIncDecTrue() {
+ final var ref = new RefcountedRegistration(reg);
ref.incRef();
assertFalse(ref.decRef());
+ doNothing().when(reg).close();
assertTrue(ref.decRef());
- verify(reg, times(1)).close();
}
}
*/
package org.opendaylight.yangtools.yang.model.repo.spi;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.mock;
import com.google.common.util.concurrent.AsyncFunction;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.SettableFuture;
import java.util.Arrays;
-import java.util.concurrent.Future;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
+import org.mockito.junit.jupiter.MockitoExtension;
import org.opendaylight.yangtools.yang.model.repo.api.EffectiveModelContextFactory;
import org.opendaylight.yangtools.yang.model.repo.api.SchemaContextFactoryConfiguration;
import org.opendaylight.yangtools.yang.model.repo.api.SchemaRepository;
import org.opendaylight.yangtools.yang.model.repo.api.YinXmlSchemaSource;
import org.opendaylight.yangtools.yang.model.repo.spi.PotentialSchemaSource.Costs;
-@RunWith(MockitoJUnitRunner.class)
-public class SchemaSourceTransformerTest {
+@ExtendWith(MockitoExtension.class)
+class SchemaSourceTransformerTest {
public static final Class<YangSchemaSourceRepresentation> SRC_CLASS = YangSchemaSourceRepresentation.class;
public static final Class<YinXmlSchemaSource> DST_CLASS = YinXmlSchemaSource.class;
public SchemaSourceTransformer<YangSchemaSourceRepresentation, YinXmlSchemaSource> schema;
@Test
- public void schemaSourceTransformerTest() {
+ void schemaSourceTransformerTest() {
schema = new SchemaSourceTransformer<>(
provider, SchemaSourceTransformerTest.SRC_CLASS, consumer,
SchemaSourceTransformerTest.DST_CLASS, function);
}
@Test
- public void schemaSourceTransformerGetSourceTest() {
- final Provider p = new Provider();
- final Registrator reg = new Registrator(p, SchemaSourceTransformerTest.SRC_CLASS,
+ void schemaSourceTransformerGetSourceTest() {
+ final var p = new Provider();
+ final var reg = new Registrator(p, SchemaSourceTransformerTest.SRC_CLASS,
PotentialSchemaSource.Costs.IMMEDIATE);
- final SourceIdentifier sourceIdentifier = new SourceIdentifier("source");
+ final var sourceIdentifier = new SourceIdentifier("source");
reg.register(sourceIdentifier);
schema = new SchemaSourceTransformer<>(p,
SchemaSourceTransformerTest.SRC_CLASS, consumer, SchemaSourceTransformerTest.DST_CLASS,
function);
- final SchemaSourceProvider<YinXmlSchemaSource> prov = schema;
- final Future<? extends YinXmlSchemaSource> source = prov.getSource(sourceIdentifier);
+ final var prov = schema;
+ final var source = prov.getSource(sourceIdentifier);
assertNotNull(source);
source.cancel(true);
assertTrue(source.isDone());
}
@Test
- public void schemaSourceRegAndUnregSchemaSourceTest() {
- final SourceIdentifier sourceIdentifier = new SourceIdentifier("source");
- final Foo<YangSchemaSourceRepresentation> foo = new Foo<>(sourceIdentifier,
+ void schemaSourceRegAndUnregSchemaSourceTest() {
+ final var sourceIdentifier = new SourceIdentifier("source");
+ final var foo = new Foo<>(sourceIdentifier,
SchemaSourceTransformerTest.SRC_CLASS,
PotentialSchemaSource.Costs.COMPUTATION);
- final Provider p = new Provider();
+ final var p = new Provider();
- final Registrator reg = new Registrator(p, SchemaSourceTransformerTest.SRC_CLASS,
+ final var reg = new Registrator(p, SchemaSourceTransformerTest.SRC_CLASS,
PotentialSchemaSource.Costs.IMMEDIATE);
reg.register(sourceIdentifier);
- final Consumer c = new Consumer();
+ final var c = new Consumer();
schema = new SchemaSourceTransformer<>(p, SchemaSourceTransformerTest.SRC_CLASS, c,
SchemaSourceTransformerTest.DST_CLASS, function);
- final SchemaSourceListener listener = schema;
+ final var listener = schema;
p.registerSchemaSourceListener(listener);
- final PotentialSchemaSource<?>[] potList = { foo.getPotentialSchemSource() };
- final Iterable<PotentialSchemaSource<?>> sources = Arrays.asList(potList);
+ final var potList = new PotentialSchemaSource<?>[]{ foo.getPotentialSchemSource() };
+ final var sources = Arrays.asList(potList);
listener.schemaSourceRegistered(sources);
- final ListenableFuture<YinXmlSchemaSource> source = schema.getSource(sourceIdentifier);
+ final var source = schema.getSource(sourceIdentifier);
assertNotNull(source);
listener.schemaSourceUnregistered(foo.getPotentialSchemSource());
- final ListenableFuture<YinXmlSchemaSource> source2 = schema.getSource(sourceIdentifier);
+ final var source2 = schema.getSource(sourceIdentifier);
assertNotNull(source2);
}
*/
package org.opendaylight.yangtools.yang.model.repo.spi;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
import com.google.common.base.MoreObjects.ToStringHelper;
-import java.io.Reader;
import java.io.StringReader;
import java.util.Optional;
import java.util.concurrent.ExecutionException;
-import java.util.concurrent.TimeUnit;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
+import org.mockito.junit.jupiter.MockitoExtension;
import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
import org.opendaylight.yangtools.yang.model.repo.api.YangSchemaSourceRepresentation;
import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
-@RunWith(MockitoJUnitRunner.StrictStubs.class)
-public class SoftSchemaSourceCacheTest {
- public static final Class<YangSchemaSourceRepresentation> REPRESENTATION = YangSchemaSourceRepresentation.class;
- public static final long LIFETIME = 1000L;
- public static final TimeUnit UNITS = TimeUnit.MILLISECONDS;
+@ExtendWith(MockitoExtension.class)
+class SoftSchemaSourceCacheTest {
+ private static final Class<YangSchemaSourceRepresentation> REPRESENTATION = YangSchemaSourceRepresentation.class;
@Mock
- public SchemaSourceRegistry registry;
+ private SchemaSourceRegistry registry;
@Mock
- public SchemaSourceRegistration<?> registration;
-
- @Before
- public void setUp() {
- doNothing().when(registration).close();
- doReturn(registration).when(registry).registerSchemaSource(any(SchemaSourceProvider.class),
- any(PotentialSchemaSource.class));
- }
+ private SchemaSourceRegistration<?> registration;
@Test
- public void inMemorySchemaSourceCacheTest() {
+ void inMemorySchemaSourceCacheTest() {
try (var cache = new SoftSchemaSourceCache<>(registry, REPRESENTATION)) {
assertNotNull(cache);
}
}
@Test
- public void inMemorySchemaSourceCacheOfferAndGetSourcestest() throws Exception {
+ void inMemorySchemaSourceCacheOfferAndGetSourcestest() throws Exception {
+ doNothing().when(registration).close();
+ doReturn(registration).when(registry).registerSchemaSource(any(), any());
+
try (var cache = new SoftSchemaSourceCache<>(registry, REPRESENTATION)) {
- final String content = "content";
- final YangTextSchemaSource source = new TestingYangSource("test", "2012-12-12", content);
+ final var content = "content";
+ final var source = new TestingYangSource("test", "2012-12-12", content);
cache.offer(source);
final var sourceIdentifier = new SourceIdentifier("test", "2012-12-12");
final var checkedSource = cache .getSource(sourceIdentifier);
}
@Test
- public void inMemorySchemaSourceCacheNullGetSourcestest() throws Exception {
+ void inMemorySchemaSourceCacheNullGetSourcestest() throws Exception {
try (var cache = new SoftSchemaSourceCache<>(registry, REPRESENTATION)) {
final var sourceIdentifier = new SourceIdentifier("test", "2012-12-12");
final var checkedSource = cache.getSource(sourceIdentifier);
assertNotNull(checkedSource);
- assertThrows(ExecutionException.class, () -> checkedSource.get());
+ assertThrows(ExecutionException.class, checkedSource::get);
}
}
@Test
- public void inMemorySchemaSourceCache3test() throws InterruptedException, ExecutionException {
+ void inMemorySchemaSourceCache3test() throws InterruptedException, ExecutionException {
+ doNothing().when(registration).close();
+ doReturn(registration).when(registry).registerSchemaSource(any(), any());
+
try (var cache1 = new SoftSchemaSourceCache<>(registry, REPRESENTATION)) {
try (var cache2 = new SoftSchemaSourceCache<>(registry, REPRESENTATION)) {
- final String content = "content";
- final YangTextSchemaSource source = new TestingYangSource("test", "2012-12-12", content);
+ final var content = "content";
+ final var source = new TestingYangSource("test", "2012-12-12", content);
cache1.offer(source);
cache2.offer(source);
}
@Override
- public Reader openStream() {
+ public StringReader openStream() {
return new StringReader(content);
}