Migrate away from JUnit4/Hamcrest.
Change-Id: I90a48c4924015abc989bad91d339471771c358e7
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
*/
package org.opendaylight.yangtools.binding.codegen;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.File;
import java.net.URL;
import java.net.URLClassLoader;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-public class AugmentToUsesInAugmentCompilationTest extends BaseCompilationTest {
+class AugmentToUsesInAugmentCompilationTest extends BaseCompilationTest {
@Test
- public void testAugmentToUsesInAugment() throws Exception {
+ void testAugmentToUsesInAugment() throws Exception {
final File sourcesOutputDir = CompilationTestUtils.generatorOutput("augment-uses-to-augment");
final File compiledOutputDir = CompilationTestUtils.compilerOutput("augment-uses-to-augment");
generateTestSources("/compilation/augment-uses-to-augment", sourcesOutputDir);
CompilationTestUtils.cleanUp(sourcesOutputDir, compiledOutputDir);
}
-
}
package org.opendaylight.yangtools.binding.codegen;
import static java.nio.file.Files.newOutputStream;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import com.google.common.collect.Table;
import com.google.common.collect.Table.Cell;
import java.io.OutputStream;
import java.net.URISyntaxException;
import java.nio.charset.StandardCharsets;
+import java.util.Comparator;
import java.util.List;
import java.util.Optional;
-import org.junit.BeforeClass;
+import org.junit.jupiter.api.BeforeAll;
import org.opendaylight.yangtools.binding.contract.Naming;
import org.opendaylight.yangtools.binding.generator.impl.DefaultBindingGenerator;
import org.opendaylight.yangtools.binding.model.api.GeneratedType;
import org.opendaylight.yangtools.plugin.generator.api.GeneratedFilePath;
import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
-public abstract class BaseCompilationTest {
-
- @BeforeClass
- public static void createTestDirs() {
+abstract class BaseCompilationTest {
+ @BeforeAll
+ static final void createTestDirs() {
if (CompilationTestUtils.TEST_DIR.exists()) {
CompilationTestUtils.deleteTestDir(CompilationTestUtils.TEST_DIR);
}
assertTrue(CompilationTestUtils.COMPILER_OUTPUT_DIR.mkdirs());
}
- protected static final void generateTestSources(final List<GeneratedType> types, final File sourcesOutputDir)
+ static final void generateTestSources(final List<GeneratedType> types, final File sourcesOutputDir)
throws IOException {
- types.sort((o1, o2) -> o2.getName().compareTo(o1.getName()));
+ types.sort(Comparator.comparing(GeneratedType::getName).reversed());
final Table<?, GeneratedFilePath, GeneratedFile> generatedFiles = JavaFileGenerator.generateFiles(types, true);
for (Cell<?, GeneratedFilePath, GeneratedFile> cell : generatedFiles.cellSet()) {
}
}
- protected static final List<GeneratedType> generateTestSources(final String resourceDirPath,
- final File sourcesOutputDir) {
+ static final List<GeneratedType> generateTestSources(final String resourceDirPath, final File sourcesOutputDir) {
final List<File> sourceFiles;
try {
sourceFiles = CompilationTestUtils.getSourceFiles(resourceDirPath);
import java.lang.reflect.Constructor;
import java.net.URL;
import java.net.URLClassLoader;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Test for BG-1276. Previous construction of union constructor
* <p><code>this._value = arg1.getValue()</code> or
* <code>this._value = _arg1.getValue().toString().toCharArray()</code>
*/
-public class Bug1276Test extends BaseCompilationTest {
-
+class Bug1276Test extends BaseCompilationTest {
@Test
- public void test() throws Exception {
+ void test() throws Exception {
final File sourcesOutputDir = CompilationTestUtils.generatorOutput("bug1276");
final File compiledOutputDir = CompilationTestUtils.compilerOutput("bug1276");
generateTestSources("/compilation/bug1276", sourcesOutputDir);
*/
package org.opendaylight.yangtools.binding.codegen;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assume.assumeFalse;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assumptions.assumeFalse;
import static org.opendaylight.yangtools.binding.codegen.CompilationTestUtils.BASE_SVC_PATH;
import static org.opendaylight.yangtools.binding.codegen.CompilationTestUtils.FS;
import java.io.File;
import java.util.Map;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Bug5151 involves adding <code>{@literal @}return</code> annotations to accessor methods.
*/
-public class Bug5151Test extends BaseCompilationTest {
-
+class Bug5151Test extends BaseCompilationTest {
private static final String BUG_ID = "bug5151";
private static final String SVC_PATH = BASE_SVC_PATH + FS + "urn" + FS + "test" + FS + "foo" + FS + "rev160706";
@Test
- public void test() throws Exception {
+ void test() throws Exception {
// Xtend code generation uses the "line.separator" system property to generate proper line endings
// in templates, leading to test failures running on Windows-type OS.
assumeFalse(System.getProperty("os.name").toLowerCase().startsWith("win"));
*/
package org.opendaylight.yangtools.binding.codegen;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.opendaylight.yangtools.binding.codegen.CompilationTestUtils.BASE_PKG;
import static org.opendaylight.yangtools.binding.codegen.CompilationTestUtils.cleanUp;
import static org.opendaylight.yangtools.binding.codegen.CompilationTestUtils.testCompilation;
-import com.google.common.collect.Lists;
import java.io.File;
import java.lang.reflect.Constructor;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.List;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
/**
* Test correct functionality of copy constructor of generated builder classes.
*/
-public class Bug532Test extends BaseCompilationTest {
-
+class Bug532Test extends BaseCompilationTest {
@Test
- public void test() throws Exception {
+ void test() throws Exception {
final File sourcesOutputDir = CompilationTestUtils.generatorOutput("bug532");
final File compiledOutputDir = CompilationTestUtils.compilerOutput("bug532");
generateTestSources("/compilation/list-gen-test", sourcesOutputDir);
Object expectedLevel = Mockito.mock(levelClass);
Integer expectedLinksId = 11;
Object expectedNode = Mockito.mock(nodeClass);
- List<?> expectedNodeList = Lists.newArrayList(Mockito.mock(nodeListClass), Mockito.mock(nodeListClass));
+ List<?> expectedNodeList = List.of(Mockito.mock(nodeListClass), Mockito.mock(nodeListClass));
Constructor<?> keyConstructor = linksKeyClass.getDeclaredConstructor(Byte.class, String.class, Integer.class);
Object expectedKey = keyConstructor.newInstance(expectedId, expectedName, expectedSize);
*/
package org.opendaylight.yangtools.binding.codegen;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.doCallRealMethod;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import java.util.List;
import java.util.stream.Collectors;
import org.eclipse.xtend2.lib.StringConcatenation;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.binding.generator.impl.DefaultBindingGenerator;
import org.opendaylight.yangtools.binding.model.api.GeneratedType;
import org.opendaylight.yangtools.binding.model.api.JavaTypeName;
private static final JavaTypeName TYPE_NAME = JavaTypeName.create(TEST, TEST);
@Test
- public void basicTest() {
+ void basicTest() {
assertEquals("", new BuilderGenerator().generate(mock(Type.class)));
}
@Test
- public void builderTemplateGenerateHashcodeWithPropertyTest() {
+ void builderTemplateGenerateHashcodeWithPropertyTest() {
final GeneratedType genType = mockGenType("get" + TEST);
assertXtendEquals("""
}
@Test
- public void builderTemplateGenerateHashCodeWithoutAnyPropertyTest() {
+ void builderTemplateGenerateHashCodeWithoutAnyPropertyTest() {
assertEquals("", genHashCode(mockGenType(TEST)).toString());
}
@Test
- public void builderTemplateGenerateHashCodeWithMorePropertiesTest() {
+ void builderTemplateGenerateHashCodeWithMorePropertiesTest() {
assertXtendEquals("""
/**
* Default implementation of {@link Object#hashCode()} contract for this interface.
}
@Test
- public void builderTemplateGenerateHashCodeWithoutPropertyWithAugmentTest() {
+ void builderTemplateGenerateHashCodeWithoutPropertyWithAugmentTest() {
assertXtendEquals("""
/**
* Default implementation of {@link Object#hashCode()} contract for this interface.
}
@Test
- public void builderTemplateGenerateHashCodeWithPropertyWithAugmentTest() {
+ void builderTemplateGenerateHashCodeWithPropertyWithAugmentTest() {
assertXtendEquals("""
/**
* Default implementation of {@link Object#hashCode()} contract for this interface.
}
@Test
- public void builderTemplateGenerateHashCodeWithMorePropertiesWithAugmentTest() {
+ void builderTemplateGenerateHashCodeWithMorePropertiesWithAugmentTest() {
assertXtendEquals("""
/**
* Default implementation of {@link Object#hashCode()} contract for this interface.
}
@Test
- public void builderTemplateGenerateToStringWithPropertyTest() {
- final GeneratedType genType = mockGenType("get" + TEST);
+ void builderTemplateGenerateToStringWithPropertyTest() {
+ final var genType = mockGenType("get" + TEST);
assertXtendEquals("""
/**
}
@Test
- public void builderTemplateGenerateToStringWithoutAnyPropertyTest() {
+ void builderTemplateGenerateToStringWithoutAnyPropertyTest() {
assertXtendEquals("""
/**
* Default implementation of {@link Object#toString()} contract for this interface.
}
@Test
- public void builderTemplateGenerateToStringWithMorePropertiesTest() {
+ void builderTemplateGenerateToStringWithMorePropertiesTest() {
assertXtendEquals("""
/**
* Default implementation of {@link Object#toString()} contract for this interface.
}
@Test
- public void builderTemplateGenerateToStringWithoutPropertyWithAugmentTest() {
+ void builderTemplateGenerateToStringWithoutPropertyWithAugmentTest() {
assertXtendEquals("""
/**
* Default implementation of {@link Object#toString()} contract for this interface.
}
@Test
- public void builderTemplateGenerateToStringWithPropertyWithAugmentTest() {
+ void builderTemplateGenerateToStringWithPropertyWithAugmentTest() {
assertXtendEquals("""
/**
* Default implementation of {@link Object#toString()} contract for this interface.
}
@Test
- public void builderTemplateGenerateToStringWithMorePropertiesWithAugmentTest() {
+ void builderTemplateGenerateToStringWithMorePropertiesWithAugmentTest() {
assertXtendEquals("""
/**
* Default implementation of {@link Object#toString()} contract for this interface.
}
@Test
- public void builderTemplateGenerateToEqualsComparingOrderTest() {
+ void builderTemplateGenerateToEqualsComparingOrderTest() {
final var context = YangParserTestUtils.parseYangResource("/test-types.yang");
final var types = new DefaultBindingGenerator().generateTypes(context);
assertEquals(27, types.size());
*/
package org.opendaylight.yangtools.binding.codegen;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertTrue;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-public class ByteRangeGeneratorTest {
+class ByteRangeGeneratorTest {
@Test
@Deprecated
- public void convertTest() {
+ void convertTest() {
assertTrue(new ByteRangeGenerator().convert(1L).equals(Long.valueOf(1).byteValue()));
}
}
*/
package org.opendaylight.yangtools.binding.codegen;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.opendaylight.yangtools.binding.codegen.CompilationTestUtils.BASE_PKG;
import static org.opendaylight.yangtools.binding.codegen.CompilationTestUtils.NS_BAR;
import static org.opendaylight.yangtools.binding.codegen.CompilationTestUtils.NS_BAZ;
import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLClassLoader;
-import org.junit.Test;
-
-public class CascadeUsesCompilationTest extends BaseCompilationTest {
+import org.junit.jupiter.api.Test;
+class CascadeUsesCompilationTest extends BaseCompilationTest {
@Test
- public void testCascadeUsesCompilation() throws Exception {
+ void testCascadeUsesCompilation() throws Exception {
final File sourcesOutputDir = CompilationTestUtils.generatorOutput("cascade-uses");
final File compiledOutputDir = CompilationTestUtils.compilerOutput("cascade-uses");
generateTestSources("/compilation/cascade-uses", sourcesOutputDir);
cleanUp(sourcesOutputDir, compiledOutputDir);
}
-
}
*/
package org.opendaylight.yangtools.binding.codegen;
-import static org.hamcrest.CoreMatchers.containsString;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
import java.util.List;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.binding.generator.impl.DefaultBindingGenerator;
import org.opendaylight.yangtools.binding.model.api.GeneratedProperty;
import org.opendaylight.yangtools.binding.model.api.GeneratedTransferObject;
-import org.opendaylight.yangtools.binding.model.api.GeneratedType;
import org.opendaylight.yangtools.binding.model.api.JavaTypeName;
import org.opendaylight.yangtools.binding.model.api.type.builder.GeneratedPropertyBuilder;
-import org.opendaylight.yangtools.binding.model.api.type.builder.GeneratedTOBuilder;
import org.opendaylight.yangtools.binding.model.ri.Types;
import org.opendaylight.yangtools.binding.model.ri.generated.type.builder.CodegenGeneratedTOBuilder;
import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
-public class ClassCodeGeneratorTest {
+class ClassCodeGeneratorTest {
@Test
- public void compositeKeyClassTest() {
- final List<GeneratedType> genTypes = new DefaultBindingGenerator().generateTypes(
+ void compositeKeyClassTest() {
+ final var genTypes = new DefaultBindingGenerator().generateTypes(
YangParserTestUtils.parseYangResource("/list-composite-key.yang"));
assertNotNull(genTypes);
int genTypesCount = 0;
int genTOsCount = 0;
- for (final GeneratedType type : genTypes) {
- if (type instanceof final GeneratedTransferObject genTO) {
+ for (var type : genTypes) {
+ if (type instanceof GeneratedTransferObject genTO) {
if (genTO.getName().equals("CompositeKeyListKey")) {
final List<GeneratedProperty> properties = genTO
.getProperties();
final String outputStr = clsGen.generate(genTO);
assertNotNull(outputStr);
- assertThat(outputStr, containsString(
- "public CompositeKeyListKey(@NonNull Byte _key1, @NonNull String _key2)"));
+ assertThat(outputStr)
+ .contains("public CompositeKeyListKey(@NonNull Byte _key1, @NonNull String _key2)");
assertEquals(2, propertyCount);
genTOsCount++;
* constructor.
*/
@Test
- public void defaultConstructorNotPresentInValueTypeTest() {
- final GeneratedTOBuilder toBuilder = new CodegenGeneratedTOBuilder(JavaTypeName.create("simple.pack",
- "DefCtor"));
+ void defaultConstructorNotPresentInValueTypeTest() {
+ final var toBuilder = new CodegenGeneratedTOBuilder(JavaTypeName.create("simple.pack", "DefCtor"));
GeneratedPropertyBuilder propBuilder = toBuilder.addProperty("foo");
propBuilder.setReturnType(Types.typeForClass(String.class));
}
@Test
- public void toStringTest() {
- final GeneratedTOBuilder toBuilder = new CodegenGeneratedTOBuilder(JavaTypeName.create("simple.pack",
- "DefCtor"));
+ void toStringTest() {
+ final var toBuilder = new CodegenGeneratedTOBuilder(JavaTypeName.create("simple.pack", "DefCtor"));
GeneratedPropertyBuilder propBuilder = toBuilder.addProperty("foo");
propBuilder.setReturnType(Types.typeForClass(String.class));
*/
package org.opendaylight.yangtools.binding.codegen;
-import static org.hamcrest.CoreMatchers.startsWith;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertThrows;
-import static org.junit.Assert.assertTrue;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import com.google.common.collect.Collections2;
-import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Range;
import java.io.File;
import java.util.HexFormat;
import java.util.List;
import java.util.stream.Collectors;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.binding.ChildOf;
import org.opendaylight.yangtools.binding.annotations.RoutingContext;
import org.opendaylight.yangtools.binding.model.ri.TypeConstants;
* Test correct code generation.
*
*/
-public class CompilationTest extends BaseCompilationTest {
-
+class CompilationTest extends BaseCompilationTest {
/*
* Java 8 allows JaCoCo to hook onto interfaces, as well as
* generating a default implementation. We only want to check
}
@Test
- public void testListGeneration() throws Exception {
+ void testListGeneration() throws Exception {
final File sourcesOutputDir = CompilationTestUtils.generatorOutput("list-gen");
final File compiledOutputDir = CompilationTestUtils.compilerOutput("list-gen");
generateTestSources("/compilation/list-gen", sourcesOutputDir);
* @throws Exception when any exception occurs during the test
*/
@Test
- public void testContainerGettersGeneration() throws Exception {
+ void testContainerGettersGeneration() throws Exception {
final File sourcesOutputDir = CompilationTestUtils.generatorOutput("containers-gen");
final File compiledOutputDir = CompilationTestUtils.compilerOutput("containers-gen");
generateTestSources("/compilation/containers-gen", sourcesOutputDir);
}
@Test
- public void testAugmentUnderUsesGeneration() {
+ void testAugmentUnderUsesGeneration() {
final File sourcesOutputDir = CompilationTestUtils.generatorOutput("augment-under-uses");
final File compiledOutputDir = CompilationTestUtils.compilerOutput("augment-under-uses");
generateTestSources("/compilation/augment-under-uses", sourcesOutputDir);
}
@Test
- public void testAugmentOfAugmentGeneration() {
+ void testAugmentOfAugmentGeneration() {
final File sourcesOutputDir = CompilationTestUtils.generatorOutput("aug-of-aug");
final File compiledOutputDir = CompilationTestUtils.compilerOutput("aug-of-aug");
generateTestSources("/compilation/augment-of-augment", sourcesOutputDir);
}
@Test
- public void testLeafReturnTypes() throws Exception {
+ void testLeafReturnTypes() throws Exception {
final File sourcesOutputDir = CompilationTestUtils.generatorOutput("leaf-return-types");
final File compiledOutputDir = CompilationTestUtils.compilerOutput("leaf-return-types");
generateTestSources("/compilation/leaf-return-types", sourcesOutputDir);
}
@Test
- public void testGenerationContextReferenceExtension() throws Exception {
+ void testGenerationContextReferenceExtension() throws Exception {
final File sourcesOutputDir = CompilationTestUtils.generatorOutput("context-reference");
final File compiledOutputDir = CompilationTestUtils.compilerOutput("context-reference");
generateTestSources("/compilation/context-reference", sourcesOutputDir);
// test identity
final Class<?> baseIdentity = Class.forName("org.opendaylight.yangtools.binding.BaseIdentity", true,
loader);
- assertEquals(ImmutableList.of(baseIdentity), Arrays.asList(identityClass.getInterfaces()));
+ assertEquals(List.of(baseIdentity), Arrays.asList(identityClass.getInterfaces()));
// Test annotation
final Method getId;
}
@Test
- public void compilationTest() {
+ void compilationTest() {
final File sourcesOutputDir = CompilationTestUtils.generatorOutput("yang");
final File compiledOutputDir = CompilationTestUtils.compilerOutput("yang");
generateTestSources("/yang", sourcesOutputDir);
}
@Test
- public void testBug586() {
+ void testBug586() {
final File sourcesOutputDir = CompilationTestUtils.generatorOutput("bug586");
final File compiledOutputDir = CompilationTestUtils.compilerOutput("bug586");
generateTestSources("/compilation/bug586", sourcesOutputDir);
}
@Test
- public void testBug4760() {
+ void testBug4760() {
final File sourcesOutputDir = CompilationTestUtils.generatorOutput("bug4760");
final File compiledOutputDir = CompilationTestUtils.compilerOutput("bug4760");
generateTestSources("/compilation/bug4760", sourcesOutputDir);
* Test handling nested uses-augmentations.
*/
@Test
- public void testBug1172() {
+ void testBug1172() {
final File sourcesOutputDir = CompilationTestUtils.generatorOutput("bug1172");
final File compiledOutputDir = CompilationTestUtils.compilerOutput("bug1172");
generateTestSources("/compilation/bug1172", sourcesOutputDir);
}
@Test
- public void testBug5461() {
+ void testBug5461() {
final File sourcesOutputDir = CompilationTestUtils.generatorOutput("bug5461");
final File compiledOutputDir = CompilationTestUtils.compilerOutput("bug5461");
generateTestSources("/compilation/bug5461", sourcesOutputDir);
}
@Test
- public void testBug5882() throws Exception {
+ void testBug5882() throws Exception {
final File sourcesOutputDir = CompilationTestUtils.generatorOutput("bug5882");
final File compiledOutputDir = CompilationTestUtils.compilerOutput("bug5882");
generateTestSources("/compilation/bug5882", sourcesOutputDir);
assertTrue(new File(parent, "TypedefCurrent.java").exists());
assertTrue(new File(parent, "TypedefDeprecated.java").exists());
- try (URLClassLoader loader = new URLClassLoader(new URL[] { compiledOutputDir.toURI().toURL() })) {
+ try (var loader = new URLClassLoader(new URL[] { compiledOutputDir.toURI().toURL() })) {
final String pkg = CompilationTestUtils.BASE_PKG + ".urn.yang.foo.rev160102";
final Class<?> cls = loader.loadClass(pkg + ".FooData");
final Class<?> clsContainer = loader.loadClass(pkg + ".ContainerMain");
final Class<?> clsTypeDef2 = loader.loadClass(pkg + ".Typedef2");
final Class<?> clsTypeDef3 = loader.loadClass(pkg + ".Typedef3");
assertEquals(1, clsTypedefDepr.getAnnotations().length);
- assertThat(clsTypedefDepr.getAnnotations()[0].toString(), startsWith("@java.lang.Deprecated"));
+ assertThat(clsTypedefDepr.getAnnotations()[0].toString()).startsWith("@java.lang.Deprecated");
assertEquals(0, clsTypedefCur.getAnnotations().length);
assertEquals(1, clsGroupingDepr.getAnnotations().length);
- assertThat(clsGroupingDepr.getAnnotations()[0].toString(), startsWith("@java.lang.Deprecated"));
+ assertThat(clsGroupingDepr.getAnnotations()[0].toString()).startsWith("@java.lang.Deprecated");
assertEquals(0, clsGroupingCur.getAnnotations().length);
assertEquals(0, clsTypeDef1.getAnnotations().length);
assertEquals(1, clsTypeDef2.getAnnotations().length);
- assertThat(clsTypeDef2.getAnnotations()[0].toString(), startsWith("@java.lang.Deprecated"));
+ assertThat(clsTypeDef2.getAnnotations()[0].toString()).startsWith("@java.lang.Deprecated");
assertEquals(0, clsTypeDef3.getAnnotations().length);
/*methods inside container*/
* Test if class generated for node from grouping implements ChildOf.
*/
@Test
- public void testBug1377() throws Exception {
+ void testBug1377() throws Exception {
final File sourcesOutputDir = CompilationTestUtils.generatorOutput("bug1377");
final File compiledOutputDir = CompilationTestUtils.compilerOutput("bug1377");
}
@Test
- public void testMdsal327() {
+ void testMdsal327() {
final File sourcesOutputDir = CompilationTestUtils.generatorOutput("mdsal327");
final File compiledOutputDir = CompilationTestUtils.compilerOutput("mdsal327");
generateTestSources("/compilation/mdsal327", sourcesOutputDir);
}
@Test
- public void testMdsal365() {
+ void testMdsal365() {
final File sourcesOutputDir = CompilationTestUtils.generatorOutput("mdsal365");
final File compiledOutputDir = CompilationTestUtils.compilerOutput("mdsal365");
generateTestSources("/compilation/mdsal365", sourcesOutputDir);
}
@Test
- public void testMdsal395() {
+ void testMdsal395() {
final File sourcesOutputDir = CompilationTestUtils.generatorOutput("mdsal395");
final File compiledOutputDir = CompilationTestUtils.compilerOutput("mdsal395");
generateTestSources("/compilation/mdsal395", sourcesOutputDir);
}
@Test
- public void classNamesColisionTest() {
+ void classNamesColisionTest() {
final File sourcesOutputDir = CompilationTestUtils.generatorOutput("class-name-collision");
final File compiledOutputDir = CompilationTestUtils.compilerOutput("class-name-collision");
generateTestSources("/compilation/class-name-collision", sourcesOutputDir);
}
@Test
- public void innerEnumerationNameCollisionTest() {
+ void innerEnumerationNameCollisionTest() {
final File sourcesOutputDir = CompilationTestUtils.generatorOutput("mdsal321");
final File compiledOutputDir = CompilationTestUtils.compilerOutput("mdsal321");
generateTestSources("/compilation/mdsal321", sourcesOutputDir);
}
@Test
- public void twoNestedUnionsTest() {
+ void twoNestedUnionsTest() {
final File sourcesOutputDir = CompilationTestUtils.generatorOutput("mdsal320");
final File compiledOutputDir = CompilationTestUtils.compilerOutput("mdsal320");
generateTestSources("/compilation/mdsal320", sourcesOutputDir);
}
@Test
- public void testMdsal425() {
+ void testMdsal425() {
final File sourcesOutputDir = CompilationTestUtils.generatorOutput("mdsal425");
final File compiledOutputDir = CompilationTestUtils.compilerOutput("mdsal425");
generateTestSources("/compilation/mdsal425", sourcesOutputDir);
}
@Test
- public void testMdsal426() {
+ void testMdsal426() {
final File sourcesOutputDir = CompilationTestUtils.generatorOutput("mdsal426");
final File compiledOutputDir = CompilationTestUtils.compilerOutput("mdsal426");
generateTestSources("/compilation/mdsal426", sourcesOutputDir);
}
@Test
- public void testMdsal529() {
+ void testMdsal529() {
final File sourcesOutputDir = CompilationTestUtils.generatorOutput("mdsal529");
final File compiledOutputDir = CompilationTestUtils.compilerOutput("mdsal529");
generateTestSources("/compilation/mdsal529", sourcesOutputDir);
}
@Test
- public void testMdsal589() {
+ void testMdsal589() {
final File sourcesOutputDir = CompilationTestUtils.generatorOutput("mdsal589");
final File compiledOutputDir = CompilationTestUtils.compilerOutput("mdsal589");
generateTestSources("/compilation/mdsal589", sourcesOutputDir);
}
@Test
- public void testMdsal533() {
+ void testMdsal533() {
final File sourcesOutputDir = CompilationTestUtils.generatorOutput("mdsal533");
final File compiledOutputDir = CompilationTestUtils.compilerOutput("mdsal533");
generateTestSources("/compilation/mdsal533", sourcesOutputDir);
}
@Test
- public void testMdsal664() {
+ void testMdsal664() {
final File sourcesOutputDir = CompilationTestUtils.generatorOutput("mdsal664");
final File compiledOutputDir = CompilationTestUtils.compilerOutput("mdsal664");
generateTestSources("/compilation/mdsal664", sourcesOutputDir);
}
@Test
- public void testUnionStringPatterns() throws Exception {
+ void testUnionStringPatterns() throws Exception {
final File sourcesOutputDir = CompilationTestUtils.generatorOutput("union-string-pattern");
final File compiledOutputDir = CompilationTestUtils.compilerOutput("union-string-pattern");
generateTestSources("/compilation/union-string-pattern", sourcesOutputDir);
}
@Test
- public void yangDataCompilation() {
+ void yangDataCompilation() {
final File sourcesOutputDir = CompilationTestUtils.generatorOutput("yang-data-gen");
final File compiledOutputDir = CompilationTestUtils.compilerOutput("yang-data-gen");
final String className = CompilationTestUtils.BASE_PKG + ".urn.test.yang.data.demo.rev220222." + name;
// ensure class source is generated
final String srcPath = className.replace('.', File.separatorChar) + ".java";
- assertTrue(srcPath + " exists", new File(sourcesOutputDir, srcPath).exists());
+ assertTrue(new File(sourcesOutputDir, srcPath).exists(), srcPath + " exists");
}
CompilationTestUtils.cleanUp(sourcesOutputDir, compiledOutputDir);
package org.opendaylight.yangtools.binding.codegen;
import static com.google.common.base.Preconditions.checkState;
-import static org.hamcrest.CoreMatchers.instanceOf;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertThrows;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
import java.io.File;
import java.io.FileNotFoundException;
static void assertContainsRestrictionCheck(final Constructor<?> constructor, final String errorMsg,
final Object... args) {
final var cause = assertThrows(InvocationTargetException.class, () -> constructor.newInstance(args)).getCause();
- assertThat(cause, instanceOf(IllegalArgumentException.class));
+ assertInstanceOf(IllegalArgumentException.class, cause);
assertEquals(errorMsg, cause.getMessage());
}
static void assertContainsRestrictionCheck(final Object obj, final Method method, final String errorMsg,
final Object... args) {
final var cause = assertThrows(InvocationTargetException.class, () -> method.invoke(obj, args)).getCause();
- assertThat(cause, instanceOf(IllegalArgumentException.class));
+ assertInstanceOf(IllegalArgumentException.class, cause);
assertEquals(errorMsg, cause.getMessage());
}
* @param ifc expected interface
*/
static void assertImplementsIfc(final Class<?> clazz, final Class<?> ifc) {
- List<Class<?>> ifcsList = Arrays.asList(clazz.getInterfaces());
+ final var ifcsList = Arrays.asList(clazz.getInterfaces());
if (!ifcsList.contains(ifc)) {
throw new AssertionError(clazz + " should implement " + ifc);
}
Type[] typeArg = ifcType.getActualTypeArguments();
assertEquals(1, typeArg.length);
Type typeArgument = typeArg[0];
- assertThat(typeArgument, instanceOf(Class.class));
+ assertInstanceOf(Class.class, typeArgument);
Class<?> argClass = (Class<?>) typeArgument;
assertEquals(genericTypeName, argClass.getName());
assertTrue(argClass.isInterface());
throw new AssertionError("File " + dir + " doesn't exists or it's not a directory");
}
- assertEquals("Unexpected count of generated files", count, dirContent.length);
+ assertEquals(count, dirContent.length, "Unexpected count of generated files");
}
/**
*/
package org.opendaylight.yangtools.binding.codegen;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import java.math.BigInteger;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.Decimal64;
-public class Decimal64RangeGeneratorTest {
+class Decimal64RangeGeneratorTest {
@Test
@Deprecated
- public void convertTest() {
+ void convertTest() {
Decimal64RangeGenerator generator = new Decimal64RangeGenerator();
Decimal64 one = Decimal64.valueOf(1, 1);
assertEquals(one, generator.convert(1L));
import static org.opendaylight.yangtools.binding.codegen.CompilationTestUtils.testCompilation;
import java.io.File;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Test if generated classes from yang file is compilable, generated javadoc comments contains
* symbols as javadoc comment tag, which caused of compilation problem.
*/
-public class EncodingInJavaDocTest extends BaseCompilationTest {
+class EncodingInJavaDocTest extends BaseCompilationTest {
@Test
- public void testAugmentToUsesInAugment() {
+ void testAugmentToUsesInAugment() {
final File sourcesOutputDir = CompilationTestUtils.generatorOutput("encoding-javadoc");
final File compiledOutputDir = CompilationTestUtils.compilerOutput("encoding-javadoc");
generateTestSources("/compilation/encoding-javadoc", sourcesOutputDir);
*/
package org.opendaylight.yangtools.binding.codegen;
-import static org.hamcrest.CoreMatchers.containsString;
-import static org.hamcrest.MatcherAssert.assertThat;
+import static org.assertj.core.api.Assertions.assertThat;
import java.io.File;
import java.io.IOException;
}
static void assertFileContains(final String fileContent, final String searchText) {
- assertThat(fileContent, containsString(searchText));
+ assertThat(fileContent).contains(searchText);
}
static void assertFileContainsConsecutiveLines(final File file, final String fileContent, final String ... lines) {
- for (final String line : lines) {
+ for (var line : lines) {
assertFileContains(fileContent, line);
}
assertFileContains(fileContent, String.join(LS, lines));
}
static Map<String, File> getFiles(final File path) {
- final Map<String, File> ret = new HashMap<>();
+ final var ret = new HashMap<String, File>();
getFiles(path, ret);
return ret;
}
private static void getFiles(final File path, final Map<String, File> files) {
- final File [] dirFiles = path.listFiles();
- for (File file : dirFiles) {
+ for (var file : path.listFiles()) {
if (file.isDirectory()) {
getFiles(file, files);
}
*/
package org.opendaylight.yangtools.binding.codegen;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import org.eclipse.jdt.annotation.NonNullByDefault;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.binding.model.api.GeneratedType;
import org.opendaylight.yangtools.binding.model.api.JavaTypeName;
import org.opendaylight.yangtools.binding.model.api.type.builder.GeneratedTypeBuilder;
import org.opendaylight.yangtools.binding.model.ri.BindingTypes;
import org.opendaylight.yangtools.binding.model.ri.generated.type.builder.CodegenGeneratedTypeBuilder;
-public class GeneratorJavaFileTest extends BaseCompilationTest {
+class GeneratorJavaFileTest extends BaseCompilationTest {
private static final String FS = File.separator;
private static final String PATH = "target/test/test-dir";
@Test
- public void test() throws IOException {
+ void test() throws IOException {
final GeneratedTypeBuilder gtb = new CodegenGeneratedTypeBuilder(JavaTypeName.create(
"org.opendaylight.controller.gen", "Type4"));
gtb.addImplementsType(BindingTypes.augmentable(gtb));
*/
package org.opendaylight.yangtools.binding.codegen;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-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.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.doReturn;
import static org.opendaylight.yangtools.binding.codegen.GeneratorUtil.createImports;
import static org.opendaylight.yangtools.binding.model.ri.TypeConstants.PATTERN_CONSTANT_NAME;
-import com.google.common.collect.ImmutableList;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import java.util.List;
+import org.junit.jupiter.api.BeforeEach;
+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.mockito.junit.jupiter.MockitoSettings;
+import org.mockito.quality.Strictness;
import org.opendaylight.yangtools.binding.model.api.AnnotationType;
import org.opendaylight.yangtools.binding.model.api.Constant;
import org.opendaylight.yangtools.binding.model.api.GeneratedProperty;
import org.opendaylight.yangtools.binding.model.api.ParameterizedType;
import org.opendaylight.yangtools.binding.model.api.Type;
-@RunWith(MockitoJUnitRunner.StrictStubs.class)
-public class GeneratorUtilTest {
+@MockitoSettings(strictness = Strictness.LENIENT)
+@ExtendWith(MockitoExtension.class)
+class GeneratorUtilTest {
private static final JavaTypeName ANNOTATION = JavaTypeName.create("tst.package", "tstAnnotationName");
private static final JavaTypeName PARAMETERIZED_TYPE = JavaTypeName.create("tst.package", "tstParametrizedType");
private static final JavaTypeName TYPE = JavaTypeName.create("tst.package", "tstName");
@Mock
private GeneratedTransferObject superType;
- @Before
- public void before() {
+ @BeforeEach
+ void before() {
doReturn("tst.package").when(parameterizedType).getPackageName();
doReturn("tstParametrizedType").when(parameterizedType).getName();
doReturn(PARAMETERIZED_TYPE).when(parameterizedType).getIdentifier();
doReturn(TYPE).when(type).getIdentifier();
doReturn(parameterizedType).when(property).getReturnType();
doReturn(new Type[] { type }).when(parameterizedType).getActualTypeArguments();
- doReturn(ImmutableList.of(property)).when(enclosedType).getProperties();
+ doReturn(List.of(property)).when(enclosedType).getProperties();
doReturn(Boolean.TRUE).when(property).isReadOnly();
doReturn("tst.package").when(enclosedType).getPackageName();
doReturn("tstName").when(enclosedType).getName();
- doReturn(ImmutableList.of(parameter)).when(methodSignature).getParameters();
+ doReturn(List.of(parameter)).when(methodSignature).getParameters();
doReturn("tst.package").when(annotationType).getPackageName();
doReturn("tstAnnotationName").when(annotationType).getName();
doReturn(type).when(parameter).getType();
doReturn(type).when(methodSignature).getReturnType();
- doReturn(ImmutableList.of(annotationType)).when(methodSignature).getAnnotations();
- doReturn(ImmutableList.of(methodSignature)).when(enclosedType).getMethodDefinitions();
+ doReturn(List.of(annotationType)).when(methodSignature).getAnnotations();
+ doReturn(List.of(methodSignature)).when(enclosedType).getMethodDefinitions();
doReturn(PATTERN_CONSTANT_NAME).when(constant).getName();
- doReturn(ImmutableList.of(constant)).when(enclosedType).getConstantDefinitions();
+ doReturn(List.of(constant)).when(enclosedType).getConstantDefinitions();
- doReturn(ImmutableList.of()).when(enclosedType).getEnclosedTypes();
- doReturn(ImmutableList.of(enclosedType)).when(generatedType).getEnclosedTypes();
+ doReturn(List.of()).when(enclosedType).getEnclosedTypes();
+ doReturn(List.of(enclosedType)).when(generatedType).getEnclosedTypes();
}
@Test
- public void createChildImportsTest() {
+ void createChildImportsTest() {
doReturn("tst.package").when(enclosedType).getPackageName();
doReturn("tstName").when(enclosedType).getName();
- doReturn(ImmutableList.of()).when(enclosedType).getEnclosedTypes();
- doReturn(ImmutableList.of(enclosedType)).when(generatedType).getEnclosedTypes();
+ doReturn(List.of()).when(enclosedType).getEnclosedTypes();
+ doReturn(List.of(enclosedType)).when(generatedType).getEnclosedTypes();
final var generated = GeneratorUtil.createChildImports(generatedType);
assertNotNull(generated);
assertTrue(generated.get("tstName").equals("tst.package"));
}
@Test
- public void createImportsWithExceptionTest() {
+ void createImportsWithExceptionTest() {
final var iae = assertThrows(IllegalArgumentException.class, () -> GeneratorUtil.createImports(null));
assertEquals("Generated Type cannot be NULL!", iae.getMessage());
}
@Test
- public void createImportsTest() {
+ void createImportsTest() {
final var generated = createImports(generatedType);
assertNotNull(generated);
assertEquals(JavaTypeName.create("tst.package", "tstAnnotationName"), generated.get("tstAnnotationName"));
}
@Test
- public void isConstantToExceptionTest() {
+ void isConstantToExceptionTest() {
final var iae = assertThrows(IllegalArgumentException.class, () -> GeneratorUtil.isConstantInTO(null, null));
assertNull(iae.getMessage());
}
@Test
- public void isConstantToTest() {
+ void isConstantToTest() {
doReturn("tst2").when(constant).getName();
- doReturn(ImmutableList.of(constant)).when(enclosedType).getConstantDefinitions();
+ doReturn(List.of(constant)).when(enclosedType).getConstantDefinitions();
assertFalse(GeneratorUtil.isConstantInTO("tst", enclosedType));
}
@Test
- public void getPropertiesOfAllParentsTest() {
+ void getPropertiesOfAllParentsTest() {
doReturn(enclosedType).when(superType).getSuperType();
assertTrue(GeneratorUtil.getPropertiesOfAllParents(superType).contains(property));
}
@Test
- public void getExplicitTypeTest() {
+ void getExplicitTypeTest() {
assertEquals(annotationType.getName(), GeneratorUtil.getExplicitType(
generatedType, annotationType, createImports(generatedType)));
*/
package org.opendaylight.yangtools.binding.codegen;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertTrue;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-public class IntegerRangeGeneratorTest {
+class IntegerRangeGeneratorTest {
@Test
@Deprecated
- public void convertTest() {
+ void convertTest() {
assertTrue(new IntegerRangeGenerator().convert(1L).equals(Long.valueOf(1).intValue()));
}
}
*/
package org.opendaylight.yangtools.binding.codegen;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
-import com.google.common.collect.ImmutableList;
import java.util.ArrayList;
import java.util.List;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.binding.model.api.AnnotationType;
import org.opendaylight.yangtools.binding.model.api.GeneratedType;
import org.opendaylight.yangtools.binding.model.api.JavaTypeName;
import org.opendaylight.yangtools.binding.model.api.Type;
import org.opendaylight.yangtools.binding.model.ri.Types;
-public class InterfaceGeneratorTest {
+class InterfaceGeneratorTest {
private static final String TEST = "test";
private static final JavaTypeName TYPE_NAME = JavaTypeName.create(TEST, TEST);
@Test
- public void basicTest() {
+ void basicTest() {
assertEquals("", new InterfaceGenerator().generate(mock(Type.class)));
}
@Test
- public void builderTemplateListenerMethodTest() {
+ void builderTemplateListenerMethodTest() {
final MethodSignature methSign = mockMethSign("on" + TEST);
final GeneratedType genType = mockGenType(methSign);
}
@Test
- public void builderTemplateDeprecatedListenerMethodTest() {
+ void builderTemplateDeprecatedListenerMethodTest() {
final MethodSignature methSign = mockMethSign("on" + TEST);
addMethodStatus(methSign, JavaTypeName.create(Deprecated.class));
final GeneratedType genType = mockGenType(methSign);
}
@Test
- public void builderTemplateGenerateObsoleteListenerMethodTest() {
+ void builderTemplateGenerateObsoleteListenerMethodTest() {
final MethodSignature methSign = mockMethSign("on" + TEST);
addMethodStatus(methSign, JavaTypeName.create(Deprecated.class));
doReturn(true).when(methSign).isDefault();
private static void addMethodStatus(final MethodSignature methSign, final JavaTypeName annotationJavaType) {
final AnnotationType annotationType = mock(AnnotationType.class);
doReturn(annotationJavaType).when(annotationType).getIdentifier();
- doReturn(ImmutableList.of(annotationType)).when(methSign).getAnnotations();
+ doReturn(List.of(annotationType)).when(methSign).getAnnotations();
}
}
*/
package org.opendaylight.yangtools.binding.codegen;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertTrue;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-public class LongRangeGeneratorTest {
+class LongRangeGeneratorTest {
@Test
@Deprecated
- public void convertTest() {
+ void convertTest() {
assertTrue(new LongRangeGenerator().convert(1).equals(Integer.valueOf(1).longValue()));
}
}
*/
package org.opendaylight.yangtools.binding.codegen;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
import java.io.File;
import java.nio.file.Files;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
-public class Mdsal732Test extends BaseCompilationTest {
+class Mdsal732Test extends BaseCompilationTest {
private File sourcesOutputDir;
private File compiledOutputDir;
- @Before
- public void before() {
+ @BeforeEach
+ void before() {
sourcesOutputDir = CompilationTestUtils.generatorOutput("mdsal732");
compiledOutputDir = CompilationTestUtils.compilerOutput("mdsal732");
}
- @After
- public void after() {
+ @AfterEach
+ void after() {
CompilationTestUtils.cleanUp(sourcesOutputDir, compiledOutputDir);
}
@Test
- public void testIdentityrefLeafrefSpecialization() throws Exception {
+ void testIdentityrefLeafrefSpecialization() throws Exception {
generateTestSources("/compilation/mdsal732", sourcesOutputDir);
final var xyzzyBuilder = FileSearchUtil.getFiles(sourcesOutputDir).get("XyzzyBuilder.java");
assertNotNull(xyzzyBuilder);
*/
package org.opendaylight.yangtools.binding.codegen;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
import java.io.File;
import java.nio.file.Files;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
public class Mdsal738Test extends BaseCompilationTest {
private File sourcesOutputDir;
private File compiledOutputDir;
- @Before
- public void before() {
+ @BeforeEach
+ void before() {
sourcesOutputDir = CompilationTestUtils.generatorOutput("mdsal738");
compiledOutputDir = CompilationTestUtils.compilerOutput("mdsal738");
}
- @After
- public void after() {
+ @AfterEach
+ void after() {
CompilationTestUtils.cleanUp(sourcesOutputDir, compiledOutputDir);
}
@Test
- public void testUnionOfDecimal64() throws Exception {
+ void testUnionOfDecimal64() throws Exception {
generateTestSources("/compilation/mdsal738", sourcesOutputDir);
final var pmDataType = FileSearchUtil.getFiles(sourcesOutputDir).get("PmDataType.java");
assertNotNull(pmDataType);
*/
package org.opendaylight.yangtools.binding.codegen;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
import java.io.File;
import java.nio.file.Files;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
-public class Mdsal807Test extends BaseCompilationTest {
+class Mdsal807Test extends BaseCompilationTest {
private File sourcesOutputDir;
private File compiledOutputDir;
- @Before
- public void before() {
+ @BeforeEach
+ void before() {
sourcesOutputDir = CompilationTestUtils.generatorOutput("mdsal807");
compiledOutputDir = CompilationTestUtils.compilerOutput("mdsal807");
}
- @After
- public void after() {
+ @AfterEach
+ void after() {
CompilationTestUtils.cleanUp(sourcesOutputDir, compiledOutputDir);
}
@Test
- public void testBitsTypedef() throws Exception {
+ void testBitsTypedef() throws Exception {
generateTestSources("/compilation/mdsal807", sourcesOutputDir);
final var pmDataType = FileSearchUtil.getFiles(sourcesOutputDir).get("TableConfig.java");
assertNotNull(pmDataType);
*/
package org.opendaylight.yangtools.binding.codegen;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.opendaylight.yangtools.binding.codegen.CompilationTestUtils.BASE_PKG;
import static org.opendaylight.yangtools.binding.codegen.CompilationTestUtils.NS_SVC_TEST;
import static org.opendaylight.yangtools.binding.codegen.CompilationTestUtils.NS_TEST;
import java.io.File;
import java.net.URL;
import java.net.URLClassLoader;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Test correct code generation.
*
*/
-public class NestedGroupingCompilationTest extends BaseCompilationTest {
-
+class NestedGroupingCompilationTest extends BaseCompilationTest {
@Test
- public void testListGeneration() throws Exception {
+ void testListGeneration() throws Exception {
final File sourcesOutputDir = CompilationTestUtils.generatorOutput("nested-grouping");
final File compiledOutputDir = CompilationTestUtils.compilerOutput("nested-grouping");
generateTestSources("/compilation/nested-grouping", sourcesOutputDir);
*/
package org.opendaylight.yangtools.binding.codegen;
-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.doReturn;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.BeforeAll;
+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.binding.model.api.GeneratedType;
import org.opendaylight.yangtools.binding.model.api.YangSourceDefinition;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
-@RunWith(MockitoJUnitRunner.StrictStubs.class)
-public class PresenceContainerTest {
+@ExtendWith(MockitoExtension.class)
+class PresenceContainerTest {
private static final QName DIRECTORY_QNAME = QName.create("urn:opendaylight:presence-container",
"2022-03-17", "directory");
private static final QName USER_QNAME = QName.create("urn:opendaylight:presence-container",
@Mock
GeneratedType type;
- @BeforeClass
- public static void beforeClass() {
+ @BeforeAll
+ static void beforeClass() {
final var context = YangParserTestUtils.parseYangResource("/presence-container.yang");
module = context.findModule(XMLNamespace.of("urn:opendaylight:presence-container"), Revision.of("2022-03-17"))
.orElseThrow();
* Test that type which is NOT container is NOT recognized as non-presence container.
*/
@Test
- public void nonContainerIsNonPresenceContainerTest() {
+ void nonContainerIsNonPresenceContainerTest() {
final var userList = module.findDataTreeChild(DIRECTORY_QNAME, USER_QNAME).orElseThrow();
final var definition = YangSourceDefinition.of(module, userList);
doReturn(definition).when(type).getYangSourceDefinition();
* Test that presence container is NOT recognized as non-presence container.
*/
@Test
- public void presenceContainerIsNonPresenceContainerTest() {
+ void presenceContainerIsNonPresenceContainerTest() {
final var scpContainer = module.findDataTreeChild(DIRECTORY_QNAME, SCP_QNAME).orElseThrow();
final var definition = YangSourceDefinition.of(module, scpContainer);
doReturn(definition).when(type).getYangSourceDefinition();
* Test that non-presence container IS recognized as non-presence container.
*/
@Test
- public void nonPresenceContainerIsNonPresenceContainerTest() {
+ void nonPresenceContainerIsNonPresenceContainerTest() {
final var dataContainer = module.findDataTreeChild(DIRECTORY_QNAME, DATA_QNAME).orElseThrow();
final var definition = YangSourceDefinition.of(module, dataContainer);
doReturn(definition).when(type).getYangSourceDefinition();
*/
package org.opendaylight.yangtools.binding.codegen;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertTrue;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-public class ShortRangeGeneratorTest {
+class ShortRangeGeneratorTest {
@Test
@Deprecated
- public void convertTest() {
+ void convertTest() {
assertTrue(new ShortRangeGenerator().convert(1L).equals(Long.valueOf(1).shortValue()));
}
}
*/
package org.opendaylight.yangtools.binding.codegen;
-import static org.hamcrest.CoreMatchers.containsString;
-import static org.hamcrest.CoreMatchers.not;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.opendaylight.yangtools.binding.codegen.FileSearchUtil.DOUBLE_TAB;
import static org.opendaylight.yangtools.binding.codegen.FileSearchUtil.TAB;
import static org.opendaylight.yangtools.binding.codegen.FileSearchUtil.TRIPLE_TAB;
import java.nio.file.Path;
import java.util.List;
import java.util.Map;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.binding.contract.Naming;
import org.opendaylight.yangtools.binding.model.api.GeneratedType;
import org.opendaylight.yangtools.binding.model.api.ParameterizedType;
import org.opendaylight.yangtools.binding.model.api.Type;
import org.opendaylight.yangtools.binding.model.ri.Types;
-public class SpecializingLeafrefTest extends BaseCompilationTest {
+class SpecializingLeafrefTest extends BaseCompilationTest {
private static final ParameterizedType SET_STRING_TYPE = Types.setTypeFor(Types.STRING);
public static final String BAR_CONT = "BarCont";
private List<GeneratedType> types;
private Map<String, File> files;
- @Before
- public void before() {
+ @BeforeEach
+ void before() {
sourcesOutputDir = CompilationTestUtils.generatorOutput("mdsal426");
compiledOutputDir = CompilationTestUtils.compilerOutput("mdsal426");
types = generateTestSources("/compilation/mdsal426", sourcesOutputDir);
files = getFiles(sourcesOutputDir);
}
- @After
- public void after() {
+ @AfterEach
+ void after() {
CompilationTestUtils.cleanUp(sourcesOutputDir, compiledOutputDir);
}
@Test
- public void testGroupingWithUnresolvedLeafRefs() throws Exception {
+ void testGroupingWithUnresolvedLeafRefs() throws Exception {
verifyReturnType(FOO_GRP, GET_LEAF1_NAME, Types.objectType());
verifyReturnType(FOO_GRP, GET_LEAFLIST1_NAME, Types.setTypeWildcard());
final String content = getFileContent(FOO_GRP);
- assertThat(content, containsString(GET_LEAF1_TYPE_OBJECT));
- assertThat(content, containsString(GET_LEAFLIST1_WILDCARD));
+ assertThat(content).contains(GET_LEAF1_TYPE_OBJECT);
+ assertThat(content).contains(GET_LEAFLIST1_WILDCARD);
}
@Test
- public void testLeafLeafrefPointsLeaf() throws Exception {
+ void testLeafLeafrefPointsLeaf() throws Exception {
verifyReturnType(RESOLVED_LEAF_GRP, GET_LEAF1_NAME, Types.STRING);
final String content = getFileContent(RESOLVED_LEAF_GRP);
- assertThat(content, containsString(GET_LEAF1_TYPE_STRING));
+ assertThat(content).contains(GET_LEAF1_TYPE_STRING);
}
@Test
- public void testLeafLeafrefPointsLeafList() throws Exception {
+ void testLeafLeafrefPointsLeafList() throws Exception {
verifyReturnType(RESOLVED_LEAFLIST_GRP, GET_LEAF1_NAME, Types.STRING);
final String content = getFileContent(RESOLVED_LEAF_GRP);
- assertThat(content, containsString(GET_LEAF1_TYPE_STRING));
+ assertThat(content).contains(GET_LEAF1_TYPE_STRING);
}
@Test
- public void testLeafListLeafrefPointsLeaf() throws Exception {
+ void testLeafListLeafrefPointsLeaf() throws Exception {
verifyReturnType(RESOLVED_LEAF_GRP, GET_LEAFLIST1_NAME, SET_STRING_TYPE);
final String content = getFileContent(RESOLVED_LEAF_GRP);
}
@Test
- public void testLeafListLeafrefPointsLeafList() throws Exception {
+ void testLeafListLeafrefPointsLeafList() throws Exception {
verifyReturnType(RESOLVED_LEAFLIST_GRP, GET_LEAFLIST1_NAME, SET_STRING_TYPE);
final String content = getFileContent(RESOLVED_LEAFLIST_GRP);
}
@Test
- public void testGroupingWhichInheritUnresolvedLeafrefAndDoesNotDefineIt() throws Exception {
+ void testGroupingWhichInheritUnresolvedLeafrefAndDoesNotDefineIt() throws Exception {
verifyMethodAbsence(TRANSITIVE_GROUP, GET_LEAF1_NAME);
verifyMethodAbsence(TRANSITIVE_GROUP, GET_LEAFLIST1_NAME);
final String content = getFileContent(TRANSITIVE_GROUP);
- assertThat(content, not(containsString(GET_LEAF1_DECLARATION)));
- assertThat(content, not(containsString(GET_LEAFLIST1_DECLARATION)));
+ assertThat(content).doesNotContain(GET_LEAF1_DECLARATION);
+ assertThat(content).doesNotContain(GET_LEAFLIST1_DECLARATION);
}
@Test
- public void testLeafrefWhichPointsBoolean() throws Exception {
+ void testLeafrefWhichPointsBoolean() throws Exception {
verifyReturnType(UNRESOLVED_GROUPING, GET_LEAF1_NAME, Types.objectType());
verifyReturnType(BOOLEAN_CONT, GET_LEAF1_NAME, Types.BOOLEAN);
final String booleanCont = getFileContent(BOOLEAN_CONT);
assertNotOverriddenGetter(unresolvedGrouping, GET_LEAF1_TYPE_OBJECT);
- assertThat(booleanCont, containsString(GET_LEAF1_DECLARATION));
+ assertThat(booleanCont).contains(GET_LEAF1_DECLARATION);
}
@Test
- public void testGroupingsUsageWhereLeafrefAlreadyResolved() throws Exception {
+ void testGroupingsUsageWhereLeafrefAlreadyResolved() throws Exception {
leafList1AndLeaf1Absence(BAR_CONT);
leafList1AndLeaf1Absence(BAR_LST);
leafList1AndLeaf1Absence(BAZ_GRP);
final String content = getFileContent(typeName);
- assertThat(content, not(containsString(GET_LEAF1_DECLARATION)));
- assertThat(content, not(containsString(GET_LEAFLIST1_DECLARATION)));
+ assertThat(content).doesNotContain(GET_LEAF1_DECLARATION);
+ assertThat(content).doesNotContain(GET_LEAFLIST1_DECLARATION);
}
private static void assertNotOverriddenGetter(final String fileContent, final String getterString) {
- assertThat(fileContent, not(containsString("@Override" + System.lineSeparator() + getterString)));
- assertThat(fileContent, containsString(getterString));
+ assertThat(fileContent).doesNotContain("@Override" + System.lineSeparator() + getterString);
+ assertThat(fileContent).contains(getterString);
}
private static void assertOverriddenGetter(final String fileContent, final String getterString) {
- assertThat(fileContent, containsString("@Override" + System.lineSeparator() + getterString));
+ assertThat(fileContent).contains("@Override" + System.lineSeparator() + getterString);
}
@Test
- public void barContBuilderDataObjectTest() throws Exception {
+ void barContBuilderDataObjectTest() throws Exception {
final File file = files.get(getJavaBuilderFileName(BAR_CONT));
final String content = Files.readString(file.toPath());
}
@Test
- public void booleanContBuilderDataObjectTest() throws Exception {
+ void booleanContBuilderDataObjectTest() throws Exception {
final File file = files.get(getJavaBuilderFileName(BOOLEAN_CONT));
final String content = Files.readString(file.toPath());
*/
package org.opendaylight.yangtools.binding.codegen;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import java.util.List;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.binding.model.api.ConcreteType;
import org.opendaylight.yangtools.binding.model.api.GeneratedProperty;
import org.opendaylight.yangtools.binding.model.api.GeneratedTransferObject;
import org.opendaylight.yangtools.binding.model.api.Type;
-public class TypeUtilsTest {
+class TypeUtilsTest {
@Test
- public void getBaseYangTypeTest() {
+ void getBaseYangTypeTest() {
final GeneratedTransferObject rootType = mock(GeneratedTransferObject.class);
final GeneratedTransferObject innerType = mock(GeneratedTransferObject.class);
final GeneratedProperty property = mock(GeneratedProperty.class);
}
@Test
- public void getBaseYangTypeWithExceptionTest() {
+ void getBaseYangTypeWithExceptionTest() {
final GeneratedTransferObject rootType = mock(GeneratedTransferObject.class);
final GeneratedTransferObject innerType = mock(GeneratedTransferObject.class);
final GeneratedProperty property = mock(GeneratedProperty.class);
*/
package org.opendaylight.yangtools.binding.codegen;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import com.google.common.collect.Range;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.Decimal64;
import org.opendaylight.yangtools.yang.common.Empty;
/**
* Test correct code generation.
*/
-public class TypedefCompilationTest extends BaseCompilationTest {
+class TypedefCompilationTest extends BaseCompilationTest {
private static final String VAL = "_value";
private static final String GET_VAL = "getValue";
private static final String UNITS = "_UNITS";
@Test
- public void test() throws Exception {
+ void test() throws Exception {
final File sourcesOutputDir = CompilationTestUtils.generatorOutput("typedef");
final File compiledOutputDir = CompilationTestUtils.compilerOutput("typedef");
generateTestSources("/compilation/typedef", sourcesOutputDir);
*/
package org.opendaylight.yangtools.binding.codegen;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.opendaylight.yangtools.binding.codegen.CompilationTestUtils.cleanUp;
import static org.opendaylight.yangtools.binding.codegen.CompilationTestUtils.testCompilation;
import java.io.File;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-public class UnionTypedefUnusedImportTest extends BaseCompilationTest {
+class UnionTypedefUnusedImportTest extends BaseCompilationTest {
@Test
- public void testUnionTypedefUnusedImport() {
+ void testUnionTypedefUnusedImport() {
final File sourcesOutputDir = CompilationTestUtils.generatorOutput("union-typedef");
final var types = generateTestSources("/compilation/union-typedef", sourcesOutputDir);
assertEquals(2, types.size());
*/
package org.opendaylight.yangtools.binding.codegen;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
import java.io.File;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLClassLoader;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.binding.contract.Naming;
/**
* Union constructor with indentityref. Previously identityref was ignored so that there is no constructor for
* identityref.
*/
-public class UnionWithIdentityrefTest extends BaseCompilationTest {
-
+class UnionWithIdentityrefTest extends BaseCompilationTest {
@Test
- public void test() throws Exception {
+ void test() throws Exception {
final File sourcesOutputDir = CompilationTestUtils.generatorOutput("union-with-identityref");
final File compiledOutputDir = CompilationTestUtils.compilerOutput("union-with-identityref");
generateTestSources("/compilation/union-with-identityref", sourcesOutputDir);
*/
package org.opendaylight.yangtools.binding.codegen;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import java.io.File;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLClassLoader;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.binding.contract.Naming;
-public class UnionWithMultipleIdentityrefsTest extends BaseCompilationTest {
+class UnionWithMultipleIdentityrefsTest extends BaseCompilationTest {
@Test
- public void test() throws Exception {
+ void test() throws Exception {
final File sourcesOutputDir = CompilationTestUtils.generatorOutput("union-with-multiple-identityrefs");
final File compiledOutputDir = CompilationTestUtils.compilerOutput("union-with-multiple-identityrefs");
generateTestSources("/compilation/union-with-multiple-identityrefs", sourcesOutputDir);
*/
package org.opendaylight.yangtools.binding.codegen;
-import static org.hamcrest.CoreMatchers.startsWith;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Table;
import java.io.File;
import java.io.FileNotFoundException;
-import java.io.OutputStream;
import java.lang.reflect.Method;
import java.net.URI;
import java.net.URL;
import java.net.URLClassLoader;
import java.nio.file.Files;
-import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
-import java.util.Map.Entry;
import java.util.Optional;
import java.util.Set;
import javax.tools.Diagnostic;
import javax.tools.JavaFileObject;
import javax.tools.StandardJavaFileManager;
import javax.tools.ToolProvider;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.binding.meta.YangModuleInfo;
import org.opendaylight.yangtools.plugin.generator.api.GeneratedFile;
import org.opendaylight.yangtools.plugin.generator.api.GeneratedFilePath;
*/
// TODO: most of private static methods are copied from
// binding-java-api-generator project - reorganize compilation tests
-public class YangModuleInfoCompilationTest {
+class YangModuleInfoCompilationTest {
public static final String FS = File.separator;
private static final String BASE_PKG = "org.opendaylight.yang.svc.v1";
private static final String COMPILER_OUTPUT_PATH = TEST_PATH + FS + "bin";
private static final File COMPILER_OUTPUT_DIR = new File(COMPILER_OUTPUT_PATH);
- @BeforeClass
- public static void createTestDirs() {
+ @BeforeAll
+ static void createTestDirs() {
if (TEST_DIR.exists()) {
deleteTestDir(TEST_DIR);
}
}
@Test
- public void compilationTest() throws Exception {
+ void compilationTest() throws Exception {
final File sourcesOutputDir = new File(GENERATOR_OUTPUT_PATH + FS + "yang");
- assertTrue("Failed to create test file '" + sourcesOutputDir + "'", sourcesOutputDir.mkdirs());
+ assertTrue(sourcesOutputDir.mkdirs(), "Failed to create test file '" + sourcesOutputDir + "'");
final File compiledOutputDir = new File(COMPILER_OUTPUT_PATH + FS + "yang");
- assertTrue("Failed to create test file '" + compiledOutputDir + "'", compiledOutputDir.mkdirs());
+ assertTrue(compiledOutputDir.mkdirs(), "Failed to create test file '" + compiledOutputDir + "'");
generateTestSources("/yang-module-info", sourcesOutputDir);
}
}
assertNotNull(infoImport);
- assertThat(infoImport.getYangTextCharSource().readFirstLine(), startsWith("module import-module"));
+ assertThat(infoImport.getYangTextCharSource().readFirstLine()).startsWith("module import-module");
assertNotNull(infoSub1);
- assertThat(infoSub1.getYangTextCharSource().readFirstLine(), startsWith("submodule submodule1"));
+ assertThat(infoSub1.getYangTextCharSource().readFirstLine()).startsWith("submodule submodule1");
assertNotNull(infoSub2);
- assertThat(infoSub2.getYangTextCharSource().readFirstLine(), startsWith("submodule submodule2"));
+ assertThat(infoSub2.getYangTextCharSource().readFirstLine()).startsWith("submodule submodule2");
assertNotNull(infoSub3);
- assertThat(infoSub3.getYangTextCharSource().readFirstLine(), startsWith("submodule submodule3"));
+ assertThat(infoSub3.getYangTextCharSource().readFirstLine()).startsWith("submodule submodule3");
cleanUp(sourcesOutputDir, compiledOutputDir);
}
private static void generateTestSources(final String resourceDirPath, final File sourcesOutputDir)
throws Exception {
- final List<File> sourceFiles = getSourceFiles(resourceDirPath);
- final EffectiveModelContext context = YangParserTestUtils.parseYangFiles(sourceFiles);
- final Table<GeneratedFileType, GeneratedFilePath, GeneratedFile> codegen = new JavaFileGenerator(Map.of())
- .generateFiles(context, Set.copyOf(context.getModules()),
+ final var sourceFiles = getSourceFiles(resourceDirPath);
+ final var context = YangParserTestUtils.parseYangFiles(sourceFiles);
+ final var codegen = new JavaFileGenerator(Map.of()).generateFiles(context, Set.copyOf(context.getModules()),
(module, representation) -> Optional.of(resourceDirPath + File.separator + module.getName()
+ YangConstants.RFC6020_YANG_FILE_EXTENSION));
assertEquals(14, codegen.row(GeneratedFileType.SOURCE).size());
assertEquals(1, codegen.row(GeneratedFileType.RESOURCE).size());
- for (Entry<GeneratedFilePath, GeneratedFile> entry : codegen.row(GeneratedFileType.SOURCE).entrySet()) {
- final Path path = new File(sourcesOutputDir,
+ for (var entry : codegen.row(GeneratedFileType.SOURCE).entrySet()) {
+ final var path = new File(sourcesOutputDir,
entry.getKey().getPath().replace(GeneratedFilePath.SEPARATOR, File.separatorChar)).toPath();
Files.createDirectories(path.getParent());
- try (OutputStream out = Files.newOutputStream(path)) {
+ try (var out = Files.newOutputStream(path)) {
entry.getValue().writeBody(out);
}
}
}
@Test
- public void generateTestSourcesWithAdditionalConfig() throws Exception {
+ void generateTestSourcesWithAdditionalConfig() throws Exception {
final List<File> sourceFiles = getSourceFiles("/yang-module-info");
final EffectiveModelContext context = YangParserTestUtils.parseYangFiles(sourceFiles);
JavaFileGenerator codegen = new JavaFileGenerator(Map.of("test", "test"));
}
}
}
-
}