diff options
author | Bjørn Christian Seime <bjorncs@yahooinc.com> | 2022-07-29 14:54:15 +0200 |
---|---|---|
committer | Bjørn Christian Seime <bjorncs@yahooinc.com> | 2022-07-29 14:54:15 +0200 |
commit | 4b53d0d135fcacc5964b2720678642f182fd15d1 (patch) | |
tree | 020d6fa01180c42bde940787cffd9ae4892cf33b /configgen | |
parent | 9e02699ef6451d6e5f8a329fdc0001a1624d0787 (diff) |
Convert configgen to junit5
Diffstat (limited to 'configgen')
8 files changed, 208 insertions, 196 deletions
diff --git a/configgen/pom.xml b/configgen/pom.xml index 11d6a195bc6..3c7032d684b 100644 --- a/configgen/pom.xml +++ b/configgen/pom.xml @@ -15,8 +15,13 @@ <description>Config java code generation from config definition files for Java Vespa components.</description> <dependencies> <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> + <groupId>org.junit.jupiter</groupId> + <artifactId>junit-jupiter-api</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.junit.jupiter</groupId> + <artifactId>junit-jupiter-engine</artifactId> <scope>test</scope> </dependency> </dependencies> diff --git a/configgen/src/test/java/com/yahoo/config/codegen/DefLineParsingTest.java b/configgen/src/test/java/com/yahoo/config/codegen/DefLineParsingTest.java index 9cf363376cc..53d02689fed 100644 --- a/configgen/src/test/java/com/yahoo/config/codegen/DefLineParsingTest.java +++ b/configgen/src/test/java/com/yahoo/config/codegen/DefLineParsingTest.java @@ -1,12 +1,9 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.config.codegen; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.*; /** * Tests parsing of a single line of a .def file @@ -16,13 +13,15 @@ import static org.junit.Assert.assertTrue; */ public class DefLineParsingTest { - @Test(expected = IllegalArgumentException.class) - public void require_that_null_default_is_not_allowed() { - new DefLine("s string default=null"); + @Test + void require_that_null_default_is_not_allowed() { + assertThrows(IllegalArgumentException.class, () -> { + new DefLine("s string default=null"); + }); } @Test - public void testParseIntArray() { + void testParseIntArray() { DefLine l = new DefLine("foo[] int"); assertEquals("foo[]", l.getName()); @@ -31,7 +30,7 @@ public class DefLineParsingTest { } @Test - public void testParseIntMap() { + void testParseIntMap() { DefLine l = new DefLine("foo{} int"); assertEquals("foo{}", l.getName()); @@ -40,7 +39,7 @@ public class DefLineParsingTest { } @Test - public void testParseInnerMap() { + void testParseInnerMap() { DefLine l = new DefLine("foo{}.i int"); assertEquals("foo{}.i", l.getName()); @@ -49,7 +48,7 @@ public class DefLineParsingTest { } @Test - public void testParseEnum() { + void testParseEnum() { DefLine l = new DefLine("idtype enum { us_east, US_WEST, EMEA } default=EMEA"); assertEquals("idtype", l.getName()); @@ -62,7 +61,7 @@ public class DefLineParsingTest { } @Test - public void testParseDefaultReference() { + void testParseDefaultReference() { DefLine l = new DefLine("foo.bar reference default=\"value\""); assertEquals("foo.bar", l.getName()); @@ -72,7 +71,7 @@ public class DefLineParsingTest { } @Test - public void testParseNoDefaultReference() { + void testParseNoDefaultReference() { DefLine l = new DefLine("foo.bar reference"); assertEquals("foo.bar", l.getName()); @@ -85,7 +84,7 @@ public class DefLineParsingTest { * the future, so the test is included to verify that value and name can be retrieved. */ @Test - public void testParseDefaultFile() { + void testParseDefaultFile() { DefLine l = new DefLine("fileWithDef file default=\"value\""); assertEquals("fileWithDef", l.getName()); @@ -95,7 +94,7 @@ public class DefLineParsingTest { } @Test - public void testParseNoDefaultFile() { + void testParseNoDefaultFile() { DefLine l = new DefLine("fileVal file"); assertEquals("fileVal", l.getName()); @@ -104,7 +103,7 @@ public class DefLineParsingTest { } @Test - public void testParseUrls() { + void testParseUrls() { DefLine l = new DefLine("urlVal url"); assertEquals("urlVal", l.getName()); @@ -113,7 +112,7 @@ public class DefLineParsingTest { } @Test - public void testParseDefaultUrls() { + void testParseDefaultUrls() { DefLine l = new DefLine("urlVal url default=\"http://docs.vespa.ai\""); assertEquals("urlVal", l.getName()); @@ -124,7 +123,7 @@ public class DefLineParsingTest { @Test - public void testParseDefaultInt() { + void testParseDefaultInt() { DefLine l = new DefLine("foo int default=1000"); assertEquals("foo", l.getName()); @@ -134,7 +133,7 @@ public class DefLineParsingTest { } @Test - public void testParseDefaultLong() { + void testParseDefaultLong() { DefLine l = new DefLine("foo long default=9223372036854775807"); assertEquals("foo", l.getName()); @@ -144,7 +143,7 @@ public class DefLineParsingTest { } @Test - public void testParseDefaultDouble() { + void testParseDefaultDouble() { DefLine l = new DefLine("foo double default=5.37"); assertEquals("foo", l.getName()); @@ -154,7 +153,7 @@ public class DefLineParsingTest { } @Test - public void testParseDefaultFalseBoolean() { + void testParseDefaultFalseBoolean() { DefLine l = new DefLine("foo bool default=false"); assertEquals("foo", l.getName()); @@ -164,7 +163,7 @@ public class DefLineParsingTest { } @Test - public void testParseDefaultTrueBoolean() { + void testParseDefaultTrueBoolean() { DefLine l = new DefLine("foo bool default=true"); assertEquals("foo", l.getName()); @@ -174,7 +173,7 @@ public class DefLineParsingTest { } @Test - public void testParseNoDefaultString() { + void testParseNoDefaultString() { DefLine l = new DefLine("foo.bar string"); assertEquals("foo.bar", l.getName()); @@ -183,7 +182,7 @@ public class DefLineParsingTest { } @Test - public void testParseDefaultString() { + void testParseDefaultString() { DefLine l = new DefLine("foo.bar string default=\"value\""); assertEquals("foo.bar", l.getName()); @@ -193,7 +192,7 @@ public class DefLineParsingTest { } @Test - public void testParseDefaultEmptyString() { + void testParseDefaultEmptyString() { DefLine l = new DefLine("foo.bar string default=\"\""); assertEquals("foo.bar", l.getName()); @@ -203,7 +202,7 @@ public class DefLineParsingTest { } @Test - public void testParseDefaultStringUnquoted() { + void testParseDefaultStringUnquoted() { DefLine l = new DefLine("foo.bar string default=value"); assertEquals("foo.bar", l.getName()); @@ -213,7 +212,7 @@ public class DefLineParsingTest { } @Test - public void testParseStringnullDefaultString() { + void testParseStringnullDefaultString() { DefLine l = new DefLine("foo.bar string default=\"null\""); assertEquals("foo.bar", l.getName()); @@ -223,7 +222,7 @@ public class DefLineParsingTest { } @Test - public void testRanges() { + void testRanges() { DefLine i = new DefLine("i int range=[0, 100]"); DefLine l = new DefLine("l long range=[-1e10, 0]"); DefLine d = new DefLine("d double range=[0, 1.0]"); @@ -233,7 +232,7 @@ public class DefLineParsingTest { } @Test - public void testRestartSpecification() { + void testRestartSpecification() { DefLine r0 = new DefLine("i int"); DefLine r1 = new DefLine("i int restart"); assertFalse(r0.getRestart()); diff --git a/configgen/src/test/java/com/yahoo/config/codegen/DefParserNamespaceTest.java b/configgen/src/test/java/com/yahoo/config/codegen/DefParserNamespaceTest.java index 2eb86546e51..c57114a9ba8 100644 --- a/configgen/src/test/java/com/yahoo/config/codegen/DefParserNamespaceTest.java +++ b/configgen/src/test/java/com/yahoo/config/codegen/DefParserNamespaceTest.java @@ -1,15 +1,14 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.config.codegen; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.io.IOException; import static com.yahoo.config.codegen.DefParserTest.assertLineFails; import static com.yahoo.config.codegen.DefParserTest.createDefTemplate; import static com.yahoo.config.codegen.DefParserTest.createParser; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; +import static org.junit.jupiter.api.Assertions.*; /** * @author gjoranv @@ -18,49 +17,53 @@ import static org.junit.Assert.assertNotEquals; public class DefParserNamespaceTest { @Test - public void namespace_is_set_on_root_node() { + void namespace_is_set_on_root_node() { DefParser parser = createParser("namespace=myproject.config\n"); CNode root = parser.getTree(); assertEquals("myproject.config", root.getNamespace()); } @Test - public void package_is_used_as_namespace_when_no_namespace_is_given() { + void package_is_used_as_namespace_when_no_namespace_is_given() { String PACKAGE = "com.github.myproject"; DefParser parser = createParser("package=" + PACKAGE + "\n"); CNode root = parser.getTree(); assertEquals(PACKAGE, root.getNamespace()); } - @Test(expected = CodegenRuntimeException.class) - public void uppercase_chars_are_not_allowed() { - createParser("namespace=Foo\n").getTree(); + @Test + void uppercase_chars_are_not_allowed() { + assertThrows(CodegenRuntimeException.class, () -> { + createParser("namespace=Foo\n").getTree(); + }); } - @Test(expected = CodegenRuntimeException.class) - public void explicit_com_yahoo_prefix_is_not_allowed() { - createParser("namespace=com.yahoo.myproject.config\n").getTree(); + @Test + void explicit_com_yahoo_prefix_is_not_allowed() { + assertThrows(CodegenRuntimeException.class, () -> { + createParser("namespace=com.yahoo.myproject.config\n").getTree(); + }); } @Test - public void spaces_are_allowed_around_equals_sign() { + void spaces_are_allowed_around_equals_sign() { DefParser parser = createParser("namespace = myproject.config\n"); CNode root = parser.getTree(); assertEquals("myproject.config", root.getNamespace()); } @Test - public void empty_namespace_is_not_allowed() { + void empty_namespace_is_not_allowed() { assertLineFails("namespace"); } @Test - public void consecutive_dots_are_not_allowed() { + void consecutive_dots_are_not_allowed() { assertLineFails("namespace=a..b"); } @Test - public void namespace_alters_def_md5() { + void namespace_alters_def_md5() { DefParser parser = createParser(""); CNode root = parser.getTree(); @@ -72,7 +75,7 @@ public class DefParserNamespaceTest { @Test - public void number_is_allowed_as_non_leading_char_in_namespace() throws IOException, DefParser.DefParserException { + void number_is_allowed_as_non_leading_char_in_namespace() throws IOException, DefParser.DefParserException { StringBuilder sb = createDefTemplate(); String line = "namespace=a.b.c2\n"; sb.append(line); @@ -80,17 +83,17 @@ public class DefParserNamespaceTest { } @Test - public void number_is_not_allowed_as_namespace_start_char() { + void number_is_not_allowed_as_namespace_start_char() { assertLineFails("namespace=2.a.b"); } @Test - public void number_is_not_allowed_as_leading_char_in_namespace_token() { + void number_is_not_allowed_as_leading_char_in_namespace_token() { assertLineFails("namespace=a.b.2c"); } @Test - public void underscore_in_namespace_is_allowed() throws IOException, DefParser.DefParserException { + void underscore_in_namespace_is_allowed() throws IOException, DefParser.DefParserException { StringBuilder sb = createDefTemplate(); String line = "namespace=a_b.c\n"; sb.append(line); diff --git a/configgen/src/test/java/com/yahoo/config/codegen/DefParserPackageTest.java b/configgen/src/test/java/com/yahoo/config/codegen/DefParserPackageTest.java index cd7ca1a89b9..4aa40ae902c 100644 --- a/configgen/src/test/java/com/yahoo/config/codegen/DefParserPackageTest.java +++ b/configgen/src/test/java/com/yahoo/config/codegen/DefParserPackageTest.java @@ -1,16 +1,14 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.config.codegen; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.io.IOException; import static com.yahoo.config.codegen.DefParserTest.assertLineFails; import static com.yahoo.config.codegen.DefParserTest.createDefTemplate; import static com.yahoo.config.codegen.DefParserTest.createParser; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.*; /** * Tests setting explicit java package in the def file. @@ -21,17 +19,17 @@ public class DefParserPackageTest { String PACKAGE = "com.github.myproject"; @Test - public void package_is_set_on_root_node() { + void package_is_set_on_root_node() { DefParser parser = createParser("package=" + PACKAGE + "\n"); CNode root = parser.getTree(); assertEquals(PACKAGE, root.getPackage()); } @Test - public void package_and_namespace_can_coexist() { + void package_and_namespace_can_coexist() { String namespace = "test.namespace"; DefParser parser = createParser("package=" + PACKAGE + - "\nnamespace=" + namespace +"\n"); + "\nnamespace=" + namespace + "\n"); CNode root = parser.getTree(); assertEquals(PACKAGE, root.getPackage()); assertEquals(namespace, root.getNamespace()); @@ -39,37 +37,39 @@ public class DefParserPackageTest { // Required by JavaClassBuilder ctor. @Test - public void package_is_null_when_not_explicitly_given() { + void package_is_null_when_not_explicitly_given() { String namespace = "test.namespace"; DefParser parser = createParser("namespace=" + namespace + "\n"); CNode root = parser.getTree(); assertNull(root.getPackage()); } - @Test(expected = CodegenRuntimeException.class) - public void uppercase_chars_are_not_allowed() { - createParser("package=Foo.bar\n").getTree(); + @Test + void uppercase_chars_are_not_allowed() { + assertThrows(CodegenRuntimeException.class, () -> { + createParser("package=Foo.bar\n").getTree(); + }); } @Test - public void spaces_are_allowed_around_equals_sign() { + void spaces_are_allowed_around_equals_sign() { DefParser parser = createParser("package = " + PACKAGE + "\n"); CNode root = parser.getTree(); assertEquals(PACKAGE, root.getPackage()); } @Test - public void empty_package_is_not_allowed() { - assertLineFails("package"); + void empty_package_is_not_allowed() { + assertLineFails("package"); } @Test - public void consecutive_dots_are_not_allowed() { + void consecutive_dots_are_not_allowed() { assertLineFails("package=a..b"); } @Test - public void package_alters_def_md5() { + void package_alters_def_md5() { DefParser parser = createParser("a string\n"); CNode root = parser.getTree(); @@ -81,7 +81,7 @@ public class DefParserPackageTest { @Test - public void number_is_allowed_as_non_leading_char() throws IOException, DefParser.DefParserException { + void number_is_allowed_as_non_leading_char() throws IOException, DefParser.DefParserException { StringBuilder sb = createDefTemplate(); String line = "package=a.b.c2\n"; sb.append(line); @@ -89,17 +89,17 @@ public class DefParserPackageTest { } @Test - public void number_is_not_allowed_as_package_start_char() { + void number_is_not_allowed_as_package_start_char() { assertLineFails("package=2.a.b"); } @Test - public void number_is_not_allowed_as_leading_char_in_package_token() { + void number_is_not_allowed_as_leading_char_in_package_token() { assertLineFails("package=a.b.2c"); } @Test - public void underscore_in_package_is_allowed() throws IOException, DefParser.DefParserException { + void underscore_in_package_is_allowed() throws IOException, DefParser.DefParserException { StringBuilder sb = createDefTemplate(); String line = "package=a_b.c\n"; sb.append(line); diff --git a/configgen/src/test/java/com/yahoo/config/codegen/DefParserTest.java b/configgen/src/test/java/com/yahoo/config/codegen/DefParserTest.java index 915edce1440..4fbf01892cc 100644 --- a/configgen/src/test/java/com/yahoo/config/codegen/DefParserTest.java +++ b/configgen/src/test/java/com/yahoo/config/codegen/DefParserTest.java @@ -1,17 +1,15 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.config.codegen; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; + import java.io.File; import java.io.FileReader; import java.io.IOException; import java.io.StringReader; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.*; /** * Unit tests for DefParser. @@ -25,7 +23,7 @@ public class DefParserTest { private static final String DEF_NAME = TEST_DIR + "configgen.allfeatures.def"; @Test - public void testTraverseTree() throws IOException { + void testTraverseTree() throws IOException { File defFile = new File(DEF_NAME); CNode root = new DefParser("test", new FileReader(defFile)).getTree(); assertNotNull(root); @@ -62,21 +60,21 @@ public class DefParserTest { } @Test - public void testFileWithNamespaceInFilename() throws IOException { + void testFileWithNamespaceInFilename() throws IOException { File defFile = new File(TEST_DIR + "baz.bar.foo.def"); CNode root = new DefParser("test", new FileReader(defFile)).getTree(); assertEquals("31a0f9bda0e5ff929762a29569575a7e", root.defMd5); } @Test - public void testMd5Sum() throws IOException { + void testMd5Sum() throws IOException { File defFile = new File(DEF_NAME); CNode root = new DefParser("test", new FileReader(defFile)).getTree(); assertEquals("f901bdc5c96e7005130399c63f247823", root.defMd5); } @Test - public void testMd5Sum2() { + void testMd5Sum2() { String def = "a string\n"; CNode root = new DefParser("testMd5Sum2", new StringReader(def)).getTree(); assertEquals("a5e5fdbb2b27e56ba7d5e60e335c598b", root.defMd5); @@ -84,7 +82,7 @@ public class DefParserTest { // TODO: Version is not used anymore, remove test in Vespa 9 @Test - public void testValidVersions() { + void testValidVersions() { try { parse("version=8"); parse("version=8-1"); @@ -103,7 +101,7 @@ public class DefParserTest { } @Test - public void testInvalidType() { + void testInvalidType() { String line = "a sting"; assertLineFails(line, "Could not create sting a"); } @@ -113,20 +111,23 @@ public class DefParserTest { } @Test - public void verify_fail_on_default_for_file() { + void verify_fail_on_default_for_file() { assertLineFails("f file default=\"file1.txt\"", - "Invalid default value"); + "Invalid default value"); } - @Test(expected = CodegenRuntimeException.class) - @Ignore("Not implemented yet") - public void testInvalidEnum() { - DefParser parser = createParser("anEnum enum {A, B, A}\n"); + @Test + @Disabled("Not implemented yet") + void testInvalidEnum() { + assertThrows(CodegenRuntimeException.class, () -> { + DefParser parser = createParser("anEnum enum {A, B, A}\n"); + //parser.validateDef(def); + }); //parser.validateDef(def); } @Test - public void testEnum() { + void testEnum() { StringBuilder sb = createDefTemplate(); sb.append("enum1 enum {A,B} default=A\n"); sb.append("enum2 enum {A, B} default=A\n"); @@ -148,20 +149,22 @@ public class DefParserTest { assertEquals("A", node.getDefaultValue().getStringRepresentation()); } - @Test(expected = DefParser.DefParserException.class) - public void testInvalidCommaInEnum() throws DefParser.DefParserException, IOException { - String invalidEnum = "anEnum enum {A, B, } default=A\n"; - String validEnum = "anotherEnum enum {A, B} default=A\n"; - StringBuilder sb = createDefTemplate(); - sb.append(invalidEnum); - sb.append(validEnum); - DefParser parser = createParser(sb.toString()); - parser.parse(); + @Test + void testInvalidCommaInEnum() throws DefParser.DefParserException, IOException { + assertThrows(DefParser.DefParserException.class, () -> { + String invalidEnum = "anEnum enum {A, B, } default=A\n"; + String validEnum = "anotherEnum enum {A, B} default=A\n"; + StringBuilder sb = createDefTemplate(); + sb.append(invalidEnum); + sb.append(validEnum); + DefParser parser = createParser(sb.toString()); + parser.parse(); + }); } - @Ignore //TODO: finish this! The numeric leaf nodes must contain their range. + @Disabled //TODO: finish this! The numeric leaf nodes must contain their range. @Test - public void testRanges() { + void testRanges() { StringBuilder sb = new StringBuilder(); sb.append("i int range=[0,10]"); sb.append("l long range=[-1e20,0]"); @@ -173,7 +176,7 @@ public class DefParserTest { } @Test - public void duplicate_parameter_is_illegal() { + void duplicate_parameter_is_illegal() { Class<?> exceptionClass = DefParser.DefParserException.class; StringBuilder sb = createDefTemplate(); String duplicateLine = "b int\n"; @@ -189,76 +192,76 @@ public class DefParserTest { } @Test - public void testIllegalCharacterInName() { - assertLineFails("a-b int", - "a-b contains unexpected character"); + void testIllegalCharacterInName() { + assertLineFails("a-b int", + "a-b contains unexpected character"); } @Test - public void parameter_name_starting_with_digit_is_illegal() { + void parameter_name_starting_with_digit_is_illegal() { assertLineFails("1a int", - "1a must start with a non-digit character"); + "1a must start with a non-digit character"); } @Test - public void parameter_name_starting_with_uppercase_is_illegal() { + void parameter_name_starting_with_uppercase_is_illegal() { assertLineFails("SomeInt int", - "'SomeInt' cannot start with an uppercase letter"); + "'SomeInt' cannot start with an uppercase letter"); } @Test - public void parameter_name_starting_with_the_internal_prefix_is_illegal() { + void parameter_name_starting_with_the_internal_prefix_is_illegal() { String internalPrefix = ReservedWords.INTERNAL_PREFIX; assertLineFails(internalPrefix + "i int", - "'" + internalPrefix + "i' cannot start with '" + internalPrefix + "'"); + "'" + internalPrefix + "i' cannot start with '" + internalPrefix + "'"); } @Test - public void testIllegalArray() { + void testIllegalArray() { assertLineFails("intArr[ int", - "intArr[ Expected ] to terminate array definition"); + "intArr[ Expected ] to terminate array definition"); } @Test - public void testIllegalDefault() { + void testIllegalDefault() { assertLineFails("a int deflt 10", - " deflt 10"); + " deflt 10"); } @Test - public void testReservedWordInC() { + void testReservedWordInC() { assertLineFails("auto int", - "auto is a reserved word in C"); + "auto is a reserved word in C"); } @Test - public void testReservedWordInCForArray() { + void testReservedWordInCForArray() { assertLineFails("auto[] int", - "auto is a reserved word in C"); + "auto is a reserved word in C"); } @Test - public void testReservedWordInJava() { + void testReservedWordInJava() { assertLineFails("abstract int", - "abstract is a reserved word in Java"); + "abstract is a reserved word in Java"); } @Test - public void testReservedWordInJavaForMap() { + void testReservedWordInJavaForMap() { assertLineFails("abstract{} int", - "abstract is a reserved word in Java"); + "abstract is a reserved word in Java"); } @Test - public void testReservedWordInCAndJava() { + void testReservedWordInCAndJava() { assertLineFails("continue int", - "continue is a reserved word in C and Java"); + "continue is a reserved word in C and Java"); } @Test - public void testReservedWordInCAndJavaForArray() { + void testReservedWordInCAndJavaForArray() { assertLineFails("continue[] int", - "continue is a reserved word in C and Java"); + "continue is a reserved word in C and Java"); } static StringBuilder createDefTemplate() { diff --git a/configgen/src/test/java/com/yahoo/config/codegen/JavaClassBuilderTest.java b/configgen/src/test/java/com/yahoo/config/codegen/JavaClassBuilderTest.java index e6e86b2c2a3..69a690b0e82 100644 --- a/configgen/src/test/java/com/yahoo/config/codegen/JavaClassBuilderTest.java +++ b/configgen/src/test/java/com/yahoo/config/codegen/JavaClassBuilderTest.java @@ -1,8 +1,8 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.config.codegen; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import java.io.IOException; import java.io.StringReader; @@ -12,9 +12,7 @@ import java.util.List; import static com.yahoo.config.codegen.ConfiggenUtil.createClassName; import static com.yahoo.config.codegen.JavaClassBuilder.createUniqueSymbol; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.*; /** * @author gjoranv @@ -26,44 +24,44 @@ public class JavaClassBuilderTest { private static final String DEF_NAME = TEST_DIR + "configgen.allfeatures.def"; private static final String REFERENCE_NAME = TEST_DIR + "allfeatures.reference"; - @Ignore + @Disabled @Test - public void visual_inspection_of_generated_class() { + void visual_inspection_of_generated_class() { final String testDefinition = "namespace=test\n" + // - "p path\n" + // - "pathArr[] path\n" + // - "u url\n" + // - "urlArr[] url\n" + // - "f file\n" + // - "fileArr[] file\n" + // - "i int default=0\n" + // - "# A long value\n" + // - "l long default=0\n" + // - "s string default=\"\"\n" + // - "b bool\n" + // - "# An enum value\n" + // - "e enum {A, B, C}\n" + // - "intArr[] int\n" + // - "boolArr[] bool\n" + // - "enumArr[] enum {FOO, BAR}\n" + // - "intMap{} int\n" + // - "# A struct\n" + // - "# with multi-line\n" + // - "# comment and \"quotes\".\n" + // - "myStruct.i int\n" + // - "myStruct.s string\n" + // - "# An inner array\n" + // - "myArr[].i int\n" + // - "myArr[].newStruct.s string\n" + // - "myArr[].newStruct.b bool\n" + // - "myArr[].intArr[] int\n" + // - "# An inner map\n" + // - "myMap{}.i int\n" + // - "myMap{}.newStruct.s string\n" + // - "myMap{}.newStruct.b bool\n" + // - "myMap{}.intArr[] int\n" + // - "intMap{} int\n"; + "p path\n" + // + "pathArr[] path\n" + // + "u url\n" + // + "urlArr[] url\n" + // + "f file\n" + // + "fileArr[] file\n" + // + "i int default=0\n" + // + "# A long value\n" + // + "l long default=0\n" + // + "s string default=\"\"\n" + // + "b bool\n" + // + "# An enum value\n" + // + "e enum {A, B, C}\n" + // + "intArr[] int\n" + // + "boolArr[] bool\n" + // + "enumArr[] enum {FOO, BAR}\n" + // + "intMap{} int\n" + // + "# A struct\n" + // + "# with multi-line\n" + // + "# comment and \"quotes\".\n" + // + "myStruct.i int\n" + // + "myStruct.s string\n" + // + "# An inner array\n" + // + "myArr[].i int\n" + // + "myArr[].newStruct.s string\n" + // + "myArr[].newStruct.b bool\n" + // + "myArr[].intArr[] int\n" + // + "# An inner map\n" + // + "myMap{}.i int\n" + // + "myMap{}.newStruct.s string\n" + // + "myMap{}.newStruct.b bool\n" + // + "myMap{}.intArr[] int\n" + // + "intMap{} int\n"; DefParser parser = new DefParser("test", new StringReader(testDefinition)); InnerCNode root = parser.getTree(); @@ -73,11 +71,11 @@ public class JavaClassBuilderTest { } @Test - public void testCreateUniqueSymbol() { + void testCreateUniqueSymbol() { final String testDefinition = "namespace=test\n" + // - "m int\n" + // - "n int\n"; + "m int\n" + // + "n int\n"; InnerCNode root = new DefParser("test", new StringReader(testDefinition)).getTree(); assertEquals("f", createUniqueSymbol(root, "foo")); @@ -90,7 +88,7 @@ public class JavaClassBuilderTest { } @Test - public void testCreateClassName() { + void testCreateClassName() { assertEquals("SimpleConfig", createClassName("simple")); assertEquals("AConfig", createClassName("a")); assertEquals("ABCConfig", createClassName("a-b-c")); @@ -99,13 +97,15 @@ public class JavaClassBuilderTest { assertEquals("MyAppConfig", createClassName("MyApp")); } - @Test(expected = CodegenRuntimeException.class) - public void testIllegalClassName() { - createClassName("+illegal"); + @Test + void testIllegalClassName() { + assertThrows(CodegenRuntimeException.class, () -> { + createClassName("+illegal"); + }); } @Test - public void verify_generated_class_against_reference() throws IOException { + void verify_generated_class_against_reference() throws IOException { String testDefinition = String.join("\n", Files.readAllLines(FileSystems.getDefault().getPath(DEF_NAME))); List<String> referenceClassLines = Files.readAllLines(FileSystems.getDefault().getPath(REFERENCE_NAME)); @@ -114,11 +114,13 @@ public class JavaClassBuilderTest { JavaClassBuilder builder = new JavaClassBuilder(root, parser.getNormalizedDefinition(), null, null); String[] configClassLines = builder.getConfigClass("AllfeaturesConfig").split("\n"); - for (var line : configClassLines) { System.out.println(line); } + for (var line : configClassLines) { + System.out.println(line); + } for (int i = 0; i < referenceClassLines.size(); i++) { if (configClassLines.length <= i) fail("Missing lines i generated config class. First missing line:\n" + referenceClassLines.get(i)); - assertEquals("Line " + i, referenceClassLines.get(i), configClassLines[i]); + assertEquals(referenceClassLines.get(i), configClassLines[i], "Line " + i); } } diff --git a/configgen/src/test/java/com/yahoo/config/codegen/MakeConfigTest.java b/configgen/src/test/java/com/yahoo/config/codegen/MakeConfigTest.java index 9b3e9c31363..d967e16ba0b 100644 --- a/configgen/src/test/java/com/yahoo/config/codegen/MakeConfigTest.java +++ b/configgen/src/test/java/com/yahoo/config/codegen/MakeConfigTest.java @@ -1,26 +1,26 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.config.codegen; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import java.io.File; import java.io.IOException; -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 MakeConfigTest { private File dest; - @Before + @BeforeEach public void setUp() { dest = new File("/tmp/"+System.currentTimeMillis()+File.separator); dest.mkdir(); } - @After + @AfterEach public void tearDown() { recursiveDeleteDir(dest); } @@ -40,9 +40,9 @@ public class MakeConfigTest { // The directory is now empty so delete it return dir.delete(); } - + @Test - public void testProps() throws PropertyException { + void testProps() throws PropertyException { System.setProperty("config.dumpTree", "true"); System.setProperty("config.useFramework", "true"); System.setProperty("config.dest", dest.getAbsolutePath()); @@ -53,7 +53,7 @@ public class MakeConfigTest { assertTrue(p.generateFrameworkCode); assertEquals(p.specFiles.size(), 1); assertEquals(p.specFiles.get(0).getAbsolutePath(), new File("src/test/resources/configgen.allfeatures.def").getAbsolutePath()); - + System.setProperty("config.dumpTree", "false"); System.setProperty("config.useFramework", "false"); System.setProperty("config.dest", dest.getAbsolutePath()); @@ -66,7 +66,7 @@ public class MakeConfigTest { } @Test - public void testMake() throws IOException { + void testMake() throws IOException { System.setProperty("config.dumpTree", "true"); System.setProperty("config.useFramework", "true"); System.setProperty("config.dest", dest.getAbsolutePath()); diff --git a/configgen/src/test/java/com/yahoo/config/codegen/NormalizedDefinitionTest.java b/configgen/src/test/java/com/yahoo/config/codegen/NormalizedDefinitionTest.java index d57210dd9ed..61b5eb5a759 100644 --- a/configgen/src/test/java/com/yahoo/config/codegen/NormalizedDefinitionTest.java +++ b/configgen/src/test/java/com/yahoo/config/codegen/NormalizedDefinitionTest.java @@ -9,10 +9,10 @@ import java.io.IOException; import java.io.StringReader; import java.util.List; -import org.junit.Test; +import org.junit.jupiter.api.Test; -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; /** @@ -21,13 +21,13 @@ import static org.junit.Assert.assertNotNull; public class NormalizedDefinitionTest { @Test - public void testNormalizingFromReader() { + void testNormalizingFromReader() { String def = "aString string \n" + - "anInt int #comment \n" + - "aStringCommentCharacterAfter string default=\"ab\" #foo\n" + - "aStringWithCommentCharacter string default=\"a#b\"\n" + - "aStringWithEscapedQuote string default=\"a\"b\"\n"; + "anInt int #comment \n" + + "aStringCommentCharacterAfter string default=\"ab\" #foo\n" + + "aStringWithCommentCharacter string default=\"a#b\"\n" + + "aStringWithEscapedQuote string default=\"a\"b\"\n"; StringReader reader = new StringReader(def); @@ -52,7 +52,7 @@ public class NormalizedDefinitionTest { } @Test - public void testNormalizingFromFile() throws IOException { + void testNormalizingFromFile() throws IOException { FileReader fileReader = null; try { fileReader = new FileReader("src/test/resources/configgen.allfeatures.def"); |