From 0ab2b31942ef5b11cb700124e729483a1b5ce6e2 Mon Sep 17 00:00:00 2001 From: Sylwester Lachiewicz Date: Sun, 14 Apr 2024 22:39:38 +0200 Subject: [PATCH] Convert tests to JUnit 5 --- pom.xml | 16 +- .../AbstractJavadocExtractorTest.java | 14 +- .../XsdGeneratorHelperTest.java | 200 +++++++++-------- ...ractSourceCodeAwareNodeProcessingTest.java | 16 +- .../postprocessing/javadoc/DomHelperTest.java | 20 +- .../javadoc/FieldLocationTest.java | 23 +- .../javadoc/JavaDocExtractorTest.java | 174 +++++++-------- ...AnnotationProcessorSemiDocumentedTest.java | 11 +- .../javadoc/XsdAnnotationProcessorTest.java | 11 +- ...XsdEnumerationAnnotationProcessorTest.java | 11 +- .../XsdAnnotationProcessorAndEnumsTest.java | 13 +- .../ChangeFilenameProcessorTest.java | 15 +- .../ChangeNamespacePrefixProcessorTest.java | 23 +- .../SimpleNamespaceResolverTest.java | 79 +++---- .../TransformSchemaTest.java | 36 +-- .../jaxb2/shared/FileSystemUtilitiesTest.java | 209 +++++++++--------- .../mojo/jaxb2/shared/ValidateTest.java | 32 +-- .../shared/arguments/ArgumentBuilderTest.java | 94 ++++---- .../ThreadContextClassLoaderBuilderTest.java | 59 ++--- .../environment/locale/LocaleFacetTest.java | 37 ++-- ...ystemPropertySaveEnvironmentFacetTest.java | 23 +- .../jaxb2/shared/filters/FiltersTest.java | 60 ++--- .../filters/PackageFilterInclusionTest.java | 37 ++-- .../shared/filters/T_AbstractFilterTest.java | 45 ++-- .../pattern/AbstractPatternFilterTest.java | 11 +- .../pattern/PatternFileFilterTest.java | 32 +-- .../filters/pattern/PatternURLFilterTest.java | 33 +-- .../pattern/T_AbstractPatternFilterTest.java | 55 ++--- .../version/DependencyFileParserTest.java | 95 ++++---- 29 files changed, 783 insertions(+), 701 deletions(-) diff --git a/pom.xml b/pom.xml index f0deb04e..0068ef25 100644 --- a/pom.xml +++ b/pom.xml @@ -239,12 +239,6 @@ plexus-build-api ${plexus-build-api.version} - - - junit - junit - test - org.xmlunit xmlunit-matchers @@ -274,6 +268,16 @@ 1.5.4 test + + org.junit.jupiter + junit-jupiter + test + + + org.junit.jupiter + junit-jupiter-api + test + com.sun.istack istack-commons-runtime diff --git a/src/test/java/org/codehaus/mojo/jaxb2/schemageneration/postprocessing/AbstractJavadocExtractorTest.java b/src/test/java/org/codehaus/mojo/jaxb2/schemageneration/postprocessing/AbstractJavadocExtractorTest.java index 14a84f93..c32e9f4f 100644 --- a/src/test/java/org/codehaus/mojo/jaxb2/schemageneration/postprocessing/AbstractJavadocExtractorTest.java +++ b/src/test/java/org/codehaus/mojo/jaxb2/schemageneration/postprocessing/AbstractJavadocExtractorTest.java @@ -15,11 +15,13 @@ import org.codehaus.mojo.jaxb2.shared.Validate; import org.codehaus.mojo.jaxb2.shared.filters.Filter; import org.codehaus.mojo.jaxb2.shared.filters.pattern.PatternFileFilter; -import org.junit.Assert; -import org.junit.Before; +import org.junit.jupiter.api.BeforeEach; import org.w3c.dom.Document; import se.jguru.shared.algorithms.api.resources.PropertyResources; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + /** * @author Lennart Jörelid, jGuru Europe AB */ @@ -31,7 +33,7 @@ public abstract class AbstractJavadocExtractorTest { protected JavaDocExtractor extractor; protected List> javaSourceExcludeFilter; - @Before + @BeforeEach public void setupSharedState() { sourceRootDirectories = new ArrayList(); @@ -54,14 +56,14 @@ protected void addSourceRootDirectory(final String resourcePath) { final String effectiveResourcePath = resourcePath.charAt(0) == '/' ? resourcePath : "/" + resourcePath; final URL resource = Thread.currentThread().getContextClassLoader().getResource(effectiveResourcePath); - Assert.assertNotNull("Effective resourcePath [" + resourcePath + "] could not be found.", resource); + assertNotNull(resource, "Effective resourcePath [" + resourcePath + "] could not be found."); final File toAdd = new File(resource.getPath()); final boolean exists = toAdd.exists(); final boolean isDirectory = toAdd.isDirectory(); - Assert.assertTrue("Resource [" + toAdd.getAbsolutePath() + "] was nonexistent.", exists); - Assert.assertTrue("Resource [" + toAdd.getAbsolutePath() + "] was not a directory.", isDirectory); + assertTrue(exists, "Resource [" + toAdd.getAbsolutePath() + "] was nonexistent."); + assertTrue(isDirectory, "Resource [" + toAdd.getAbsolutePath() + "] was not a directory."); sourceRootDirectories.add(toAdd); } diff --git a/src/test/java/org/codehaus/mojo/jaxb2/schemageneration/postprocessing/XsdGeneratorHelperTest.java b/src/test/java/org/codehaus/mojo/jaxb2/schemageneration/postprocessing/XsdGeneratorHelperTest.java index ebf33d6a..bcea1510 100644 --- a/src/test/java/org/codehaus/mojo/jaxb2/schemageneration/postprocessing/XsdGeneratorHelperTest.java +++ b/src/test/java/org/codehaus/mojo/jaxb2/schemageneration/postprocessing/XsdGeneratorHelperTest.java @@ -35,21 +35,27 @@ import org.custommonkey.xmlunit.ElementNameAndAttributeQualifier; import org.custommonkey.xmlunit.XMLAssert; import org.custommonkey.xmlunit.XMLUnit; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.w3c.dom.Document; import se.jguru.shared.algorithms.api.resources.PropertyResources; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; + /** * @author Lennart Jörelid */ -public class XsdGeneratorHelperTest { +class XsdGeneratorHelperTest { private static TransformerFactory factory; - @BeforeClass - public static void setupSharedState() { + @BeforeAll + static void setupSharedState() { // Configure XMLUnit. XMLUnit.setIgnoreWhitespace(true); @@ -72,40 +78,44 @@ public static void setupSharedState() { } } - @Test(expected = MojoExecutionException.class) - public void validateExceptionThrownOnDuplicateURIs() throws MojoExecutionException { + @Test + void validateExceptionThrownOnDuplicateURIs() throws MojoExecutionException { + assertThrows(MojoExecutionException.class, () -> { - // Assemble - final TransformSchema transformSchema1 = new TransformSchema("foo", "foo", "foo"); - final TransformSchema transformSchema2 = new TransformSchema("foo", "bar", "bar"); + // Assemble + final TransformSchema transformSchema1 = new TransformSchema("foo", "foo", "foo"); + final TransformSchema transformSchema2 = new TransformSchema("foo", "bar", "bar"); - final List transformSchemas = new ArrayList(); - transformSchemas.add(transformSchema1); - transformSchemas.add(transformSchema2); + final List transformSchemas = new ArrayList(); + transformSchemas.add(transformSchema1); + transformSchemas.add(transformSchema2); - // Act & Assert - XsdGeneratorHelper.validateSchemasInPluginConfiguration(transformSchemas); - Assert.fail("Two schemas with same URIs should yield a MojoExecutionException."); + // Act & Assert + XsdGeneratorHelper.validateSchemasInPluginConfiguration(transformSchemas); + fail("Two schemas with same URIs should yield a MojoExecutionException."); + }); } - @Test(expected = MojoExecutionException.class) - public void validateExceptionThrownOnDuplicatePrefixes() throws MojoExecutionException { + @Test + void validateExceptionThrownOnDuplicatePrefixes() throws MojoExecutionException { + assertThrows(MojoExecutionException.class, () -> { - // Assemble - final TransformSchema transformSchema1 = new TransformSchema("foo", "foo", "foo"); - final TransformSchema transformSchema2 = new TransformSchema("bar", "foo", "bar"); + // Assemble + final TransformSchema transformSchema1 = new TransformSchema("foo", "foo", "foo"); + final TransformSchema transformSchema2 = new TransformSchema("bar", "foo", "bar"); - final List transformSchemas = new ArrayList(); - transformSchemas.add(transformSchema1); - transformSchemas.add(transformSchema2); + final List transformSchemas = new ArrayList(); + transformSchemas.add(transformSchema1); + transformSchemas.add(transformSchema2); - // Act & Assert - XsdGeneratorHelper.validateSchemasInPluginConfiguration(transformSchemas); - Assert.fail("Two schemas with same Prefixes should yield a MojoExecutionException."); + // Act & Assert + XsdGeneratorHelper.validateSchemasInPluginConfiguration(transformSchemas); + fail("Two schemas with same Prefixes should yield a MojoExecutionException."); + }); } @Test - public void validateNoExceptionThrownOnDuplicateNullPrefixes() { + void validateNoExceptionThrownOnDuplicateNullPrefixes() { // Assemble final TransformSchema transformSchema1 = new TransformSchema("foo", null, "foo"); final TransformSchema transformSchema2 = new TransformSchema("bar", null, "bar"); @@ -115,15 +125,13 @@ public void validateNoExceptionThrownOnDuplicateNullPrefixes() { transformSchemas.add(transformSchema2); // Act & Assert - try { - XsdGeneratorHelper.validateSchemasInPluginConfiguration(transformSchemas); - } catch (MojoExecutionException e) { - Assert.fail("Two schemas with null Prefix should not yield a MojoExecutionException."); - } + Assertions.assertDoesNotThrow( + () -> XsdGeneratorHelper.validateSchemasInPluginConfiguration(transformSchemas), + "Two schemas with null Prefix should not yield a MojoExecutionException."); } @Test - public void validateExceptionThrownOnDuplicateFiles() { + void validateExceptionThrownOnDuplicateFiles() { // Assemble final TransformSchema transformSchema1 = new TransformSchema("foo", "foo", "foo.xsd"); @@ -136,59 +144,65 @@ public void validateExceptionThrownOnDuplicateFiles() { // Act & Assert try { XsdGeneratorHelper.validateSchemasInPluginConfiguration(transformSchemas); - Assert.fail("Two schemas with same Files should yield a MojoExecutionException."); + fail("Two schemas with same Files should yield a MojoExecutionException."); } catch (MojoExecutionException e) { // Validate the error message. String expectedMessage = "Misconfiguration detected: Duplicate 'file' property with value [foo.xsd] " + "found in plugin configuration. Correct schema elements index (0) and (1), " + "to ensure that all 'file' values are unique."; - Assert.assertEquals(expectedMessage, e.getLocalizedMessage()); + assertEquals(expectedMessage, e.getLocalizedMessage()); } } - @Test(expected = MojoExecutionException.class) - public void validateExceptionThrownOnOnlyUriGiven() throws MojoExecutionException { - // Assemble - final TransformSchema transformSchema1 = new TransformSchema("foo", null, ""); + @Test + void validateExceptionThrownOnOnlyUriGiven() throws MojoExecutionException { + assertThrows(MojoExecutionException.class, () -> { + // Assemble + final TransformSchema transformSchema1 = new TransformSchema("foo", null, ""); - final List transformSchemas = new ArrayList(); - transformSchemas.add(transformSchema1); + final List transformSchemas = new ArrayList(); + transformSchemas.add(transformSchema1); - // Act & Assert - XsdGeneratorHelper.validateSchemasInPluginConfiguration(transformSchemas); - Assert.fail("A schema definition with no prefix or file should yield a MojoExecutionException."); + // Act & Assert + XsdGeneratorHelper.validateSchemasInPluginConfiguration(transformSchemas); + fail("A schema definition with no prefix or file should yield a MojoExecutionException."); + }); } - @Test(expected = MojoExecutionException.class) - public void validateExceptionThrownOnNullUri() throws MojoExecutionException { + @Test + void validateExceptionThrownOnNullUri() throws MojoExecutionException { + assertThrows(MojoExecutionException.class, () -> { - // Assemble - final TransformSchema transformSchema1 = new TransformSchema(null, "foo", "bar"); + // Assemble + final TransformSchema transformSchema1 = new TransformSchema(null, "foo", "bar"); - final List transformSchemas = new ArrayList(); - transformSchemas.add(transformSchema1); + final List transformSchemas = new ArrayList(); + transformSchemas.add(transformSchema1); - // Act & Assert - XsdGeneratorHelper.validateSchemasInPluginConfiguration(transformSchemas); - Assert.fail("A schema definition with null URI should yield a MojoExecutionException."); + // Act & Assert + XsdGeneratorHelper.validateSchemasInPluginConfiguration(transformSchemas); + fail("A schema definition with null URI should yield a MojoExecutionException."); + }); } - @Test(expected = MojoExecutionException.class) - public void validateExceptionThrownOnEmptyUri() throws MojoExecutionException { + @Test + void validateExceptionThrownOnEmptyUri() throws MojoExecutionException { + assertThrows(MojoExecutionException.class, () -> { - // Assemble - final TransformSchema transformSchema1 = new TransformSchema("", "foo", "bar"); + // Assemble + final TransformSchema transformSchema1 = new TransformSchema("", "foo", "bar"); - final List transformSchemas = new ArrayList(); - transformSchemas.add(transformSchema1); + final List transformSchemas = new ArrayList(); + transformSchemas.add(transformSchema1); - // Act & Assert - XsdGeneratorHelper.validateSchemasInPluginConfiguration(transformSchemas); - Assert.fail("A schema definition with empty URI should yield a MojoExecutionException."); + // Act & Assert + XsdGeneratorHelper.validateSchemasInPluginConfiguration(transformSchemas); + fail("A schema definition with empty URI should yield a MojoExecutionException."); + }); } @Test - public void validateProcessingNodes() { + void validateProcessingNodes() { // Assemble final String newPrefix = "changedFoo"; @@ -210,7 +224,7 @@ public void validateProcessingNodes() { } @Test - public void validateProcessingXSDsWithEnumerations() throws Exception { + void validateProcessingXSDsWithEnumerations() throws Exception { // Assemble final BufferingLog log = new BufferingLog(); @@ -219,10 +233,10 @@ public void validateProcessingXSDsWithEnumerations() throws Exception { final String parentPath = "testdata/schemageneration/javadoc/enums/"; final URL parentPathURL = getClass().getClassLoader().getResource(parentPath); - Assert.assertNotNull(parentPathURL); + assertNotNull(parentPathURL); final File parentDir = new File(parentPathURL.getPath()); - Assert.assertTrue(parentDir.exists() && parentDir.isDirectory()); + assertTrue(parentDir.exists() && parentDir.isDirectory()); final List> excludeFilesMatching = new ArrayList>(); excludeFilesMatching.add(new PatternFileFilter(Collections.singletonList("\\.xsd"))); @@ -230,7 +244,7 @@ public void validateProcessingXSDsWithEnumerations() throws Exception { final List allSourceFiles = FileSystemUtilities.filterFiles( parentDir, null, parentDir.getAbsolutePath(), log, "allJavaFiles", excludeFilesMatching); - Assert.assertEquals(3, allSourceFiles.size()); + assertEquals(3, allSourceFiles.size()); final List urls = new ArrayList(); for (File current : allSourceFiles) { @@ -241,7 +255,7 @@ public void validateProcessingXSDsWithEnumerations() throws Exception { "Could not convert file [" + current.getAbsolutePath() + "] to a URL", e); } } - Assert.assertEquals(3, urls.size()); + assertEquals(3, urls.size()); extractor.addSourceURLs(urls); final SearchableDocumentation docs = extractor.process(); @@ -266,7 +280,7 @@ public void validateProcessingXSDsWithEnumerations() throws Exception { } @Test - public void validateXmlDocumentationForWrappers() throws Exception { + void validateXmlDocumentationForWrappers() throws Exception { // Assemble final BufferingLog log = new BufferingLog(); @@ -275,12 +289,12 @@ public void validateXmlDocumentationForWrappers() throws Exception { final String parentPath = "testdata/schemageneration/javadoc/xmlwrappers/"; final URL parentPathURL = getClass().getClassLoader().getResource(parentPath); - Assert.assertNotNull(parentPathURL); + assertNotNull(parentPathURL); final String schemaGenCreatedSchema = PropertyResources.readFully(parentPath + "expectedRawXmlWrappers.xsd"); final File parentDir = new File(parentPathURL.getPath()); - Assert.assertTrue(parentDir.exists() && parentDir.isDirectory()); + assertTrue(parentDir.exists() && parentDir.isDirectory()); final List> excludeFilesMatching = new ArrayList>(); excludeFilesMatching.add(new PatternFileFilter(Collections.singletonList("\\.xsd"))); @@ -288,7 +302,7 @@ public void validateXmlDocumentationForWrappers() throws Exception { final List allSourceFiles = FileSystemUtilities.filterFiles( parentDir, null, parentDir.getAbsolutePath(), log, "allJavaFiles", excludeFilesMatching); - Assert.assertEquals(2, allSourceFiles.size()); + assertEquals(2, allSourceFiles.size()); final List urls = new ArrayList(); for (File current : allSourceFiles) { @@ -299,7 +313,7 @@ public void validateXmlDocumentationForWrappers() throws Exception { "Could not convert file [" + current.getAbsolutePath() + "] to a URL", e); } } - Assert.assertEquals(2, urls.size()); + assertEquals(2, urls.size()); // Act extractor.addSourceURLs(urls); @@ -315,7 +329,7 @@ public void validateXmlDocumentationForWrappers() throws Exception { } @Test - public void validateAcquiringFilenameToResolverMap() throws MojoExecutionException { + void validateAcquiringFilenameToResolverMap() throws MojoExecutionException { // Assemble final String[] expectedFilenames = {"schema1.xsd", "schema2.xsd", "schema3.xsd"}; @@ -327,34 +341,34 @@ public void validateAcquiringFilenameToResolverMap() throws MojoExecutionExcepti XsdGeneratorHelper.getFileNameToResolverMap(directory); // Assert - Assert.assertEquals(3, fileNameToResolverMap.size()); + assertEquals(3, fileNameToResolverMap.size()); for (String current : expectedFilenames) { - Assert.assertTrue(fileNameToResolverMap.keySet().contains(current)); + assertTrue(fileNameToResolverMap.keySet().contains(current)); } SimpleNamespaceResolver schema1Resolver = fileNameToResolverMap.get("schema1.xsd"); - Assert.assertEquals("http://yet/another/namespace", schema1Resolver.getLocalNamespaceURI()); - Assert.assertEquals("schema1.xsd", schema1Resolver.getSourceFilename()); + assertEquals("http://yet/another/namespace", schema1Resolver.getLocalNamespaceURI()); + assertEquals("schema1.xsd", schema1Resolver.getSourceFilename()); final Map schema1NamespaceURI2PrefixMap = schema1Resolver.getNamespaceURI2PrefixMap(); - Assert.assertEquals(1, schema1NamespaceURI2PrefixMap.size()); - Assert.assertEquals("xs", schema1NamespaceURI2PrefixMap.get("http://www.w3.org/2001/XMLSchema")); + assertEquals(1, schema1NamespaceURI2PrefixMap.size()); + assertEquals("xs", schema1NamespaceURI2PrefixMap.get("http://www.w3.org/2001/XMLSchema")); SimpleNamespaceResolver schema2Resolver = fileNameToResolverMap.get("schema2.xsd"); - Assert.assertEquals("http://some/namespace", schema2Resolver.getLocalNamespaceURI()); - Assert.assertEquals("schema2.xsd", schema2Resolver.getSourceFilename()); + assertEquals("http://some/namespace", schema2Resolver.getLocalNamespaceURI()); + assertEquals("schema2.xsd", schema2Resolver.getSourceFilename()); final Map schema2NamespaceURI2PrefixMap = schema2Resolver.getNamespaceURI2PrefixMap(); - Assert.assertEquals(2, schema2NamespaceURI2PrefixMap.size()); - Assert.assertEquals("ns1", schema2NamespaceURI2PrefixMap.get("http://another/namespace")); - Assert.assertEquals("xs", schema2NamespaceURI2PrefixMap.get("http://www.w3.org/2001/XMLSchema")); + assertEquals(2, schema2NamespaceURI2PrefixMap.size()); + assertEquals("ns1", schema2NamespaceURI2PrefixMap.get("http://another/namespace")); + assertEquals("xs", schema2NamespaceURI2PrefixMap.get("http://www.w3.org/2001/XMLSchema")); SimpleNamespaceResolver schema3Resolver = fileNameToResolverMap.get("schema3.xsd"); - Assert.assertEquals("http://another/namespace", schema3Resolver.getLocalNamespaceURI()); - Assert.assertEquals("schema3.xsd", schema3Resolver.getSourceFilename()); + assertEquals("http://another/namespace", schema3Resolver.getLocalNamespaceURI()); + assertEquals("schema3.xsd", schema3Resolver.getSourceFilename()); final Map schema3NamespaceURI2PrefixMap = schema3Resolver.getNamespaceURI2PrefixMap(); - Assert.assertEquals(3, schema3NamespaceURI2PrefixMap.size()); - Assert.assertEquals("ns2", schema3NamespaceURI2PrefixMap.get("http://yet/another/namespace")); - Assert.assertEquals("ns1", schema3NamespaceURI2PrefixMap.get("http://some/namespace")); - Assert.assertEquals("xs", schema3NamespaceURI2PrefixMap.get("http://www.w3.org/2001/XMLSchema")); + assertEquals(3, schema3NamespaceURI2PrefixMap.size()); + assertEquals("ns2", schema3NamespaceURI2PrefixMap.get("http://yet/another/namespace")); + assertEquals("ns1", schema3NamespaceURI2PrefixMap.get("http://some/namespace")); + assertEquals("xs", schema3NamespaceURI2PrefixMap.get("http://www.w3.org/2001/XMLSchema")); } // diff --git a/src/test/java/org/codehaus/mojo/jaxb2/schemageneration/postprocessing/javadoc/AbstractSourceCodeAwareNodeProcessingTest.java b/src/test/java/org/codehaus/mojo/jaxb2/schemageneration/postprocessing/javadoc/AbstractSourceCodeAwareNodeProcessingTest.java index ad33a09e..efe43fb9 100644 --- a/src/test/java/org/codehaus/mojo/jaxb2/schemageneration/postprocessing/javadoc/AbstractSourceCodeAwareNodeProcessingTest.java +++ b/src/test/java/org/codehaus/mojo/jaxb2/schemageneration/postprocessing/javadoc/AbstractSourceCodeAwareNodeProcessingTest.java @@ -31,8 +31,7 @@ import org.codehaus.mojo.jaxb2.shared.Validate; import org.custommonkey.xmlunit.Diff; import org.custommonkey.xmlunit.XMLUnit; -import org.junit.Assert; -import org.junit.Before; +import org.junit.jupiter.api.BeforeEach; import org.w3c.dom.Document; import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; @@ -40,6 +39,9 @@ import org.xml.sax.InputSource; import org.xml.sax.SAXException; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + /** * @author Lennart Jörelid, jGuru Europe AB */ @@ -70,10 +72,10 @@ public AbstractSourceCodeAwareNodeProcessingTest() { // Setup the basic directories. basedir = getBasedir(); testJavaDir = new File(basedir, "src/test/java"); - Assert.assertTrue(testJavaDir.exists() && testJavaDir.isDirectory()); + assertTrue(testJavaDir.exists() && testJavaDir.isDirectory()); } - @Before + @BeforeEach public final void setupSharedState() throws Exception { log = new BufferingLog(BufferingLog.LogLevel.DEBUG); @@ -92,7 +94,7 @@ public final void setupSharedState() throws Exception { // Create the JAXBContext jaxbClasses = getJaxbAnnotatedClassesForJaxbContext(); - Assert.assertNotNull("getJaxbAnnotatedClassesForJaxbContext() should not return a null List.", jaxbClasses); + assertNotNull(jaxbClasses, "getJaxbAnnotatedClassesForJaxbContext() should not return a null List."); final Class[] classArray = jaxbClasses.toArray(new Class[jaxbClasses.size()]); jaxbContext = JAXBContext.newInstance(classArray); @@ -174,8 +176,8 @@ protected File getBasedir() { } final File toReturn = new File(basedirPath); - Assert.assertNotNull("Could not find 'basedir'. Please set the system property 'basedir'.", toReturn); - Assert.assertTrue("'basedir' must be an existing directory. ", toReturn.exists() && toReturn.isDirectory()); + assertNotNull(toReturn, "Could not find 'basedir'. Please set the system property 'basedir'."); + assertTrue(toReturn.exists() && toReturn.isDirectory(), "'basedir' must be an existing directory. "); // All done. return toReturn; diff --git a/src/test/java/org/codehaus/mojo/jaxb2/schemageneration/postprocessing/javadoc/DomHelperTest.java b/src/test/java/org/codehaus/mojo/jaxb2/schemageneration/postprocessing/javadoc/DomHelperTest.java index 120341e9..fda1ee2e 100644 --- a/src/test/java/org/codehaus/mojo/jaxb2/schemageneration/postprocessing/javadoc/DomHelperTest.java +++ b/src/test/java/org/codehaus/mojo/jaxb2/schemageneration/postprocessing/javadoc/DomHelperTest.java @@ -7,21 +7,23 @@ import java.util.TreeMap; import org.codehaus.mojo.jaxb2.schemageneration.XsdGeneratorHelper; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; import se.jguru.shared.algorithms.api.resources.PropertyResources; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + /** * @author Lennart Jörelid, jGuru Europe AB */ -public class DomHelperTest { +class DomHelperTest { @Test - public void validateDomHelperAccessors() throws Exception { + void validateDomHelperAccessors() throws Exception { // Assemble final String xsd = PropertyResources.readFully("testdata/schemageneration/javadoc/enums/rawEnumSchema.xsd"); @@ -50,15 +52,15 @@ public void validateDomHelperAccessors() throws Exception { } // Assert - Assert.assertNotNull(xpath2ValueMap); - Assert.assertEquals(3, xpath2ValueMap.size()); + assertNotNull(xpath2ValueMap); + assertEquals(3, xpath2ValueMap.size()); final String prefix = "#document/xs:schema/xs:simpleType[@name='foodPreference']/" + "xs:restriction/xs:enumeration[@value='"; - Assert.assertEquals("LACTO_VEGETARIAN", xpath2ValueMap.get(prefix + "LACTO_VEGETARIAN']")); - Assert.assertEquals("NONE", xpath2ValueMap.get(prefix + "NONE']")); - Assert.assertEquals("VEGAN", xpath2ValueMap.get(prefix + "VEGAN']")); + assertEquals("LACTO_VEGETARIAN", xpath2ValueMap.get(prefix + "LACTO_VEGETARIAN']")); + assertEquals("NONE", xpath2ValueMap.get(prefix + "NONE']")); + assertEquals("VEGAN", xpath2ValueMap.get(prefix + "VEGAN']")); } // diff --git a/src/test/java/org/codehaus/mojo/jaxb2/schemageneration/postprocessing/javadoc/FieldLocationTest.java b/src/test/java/org/codehaus/mojo/jaxb2/schemageneration/postprocessing/javadoc/FieldLocationTest.java index 082b6c7f..74c0b33d 100644 --- a/src/test/java/org/codehaus/mojo/jaxb2/schemageneration/postprocessing/javadoc/FieldLocationTest.java +++ b/src/test/java/org/codehaus/mojo/jaxb2/schemageneration/postprocessing/javadoc/FieldLocationTest.java @@ -9,20 +9,21 @@ import jakarta.xml.bind.annotation.XmlType; import org.codehaus.mojo.jaxb2.schemageneration.postprocessing.javadoc.location.FieldLocation; import org.codehaus.mojo.jaxb2.schemageneration.postprocessing.schemaenhancement.XmlNameAnnotatedClassWithFieldAccess; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; /** * @author Lennart Jörelid, jGuru Europe AB */ -public class FieldLocationTest { +class FieldLocationTest { private Class theClass; private Map fieldName2MethodMap; - @Before - public void setupSharedState() { + @BeforeEach + void setupSharedState() { fieldName2MethodMap = new TreeMap(); @@ -35,7 +36,7 @@ public void setupSharedState() { } @Test - public void validateFieldLocationWithXmlName() throws Exception { + void validateFieldLocationWithXmlName() throws Exception { // Assemble final String packageName = theClass.getPackage().getName(); @@ -64,9 +65,9 @@ public void validateFieldLocationWithXmlName() throws Exception { packageName, theClass.getSimpleName(), classXmlName, stringField.getName(), stringFieldXmlName); // Assert - Assert.assertEquals(expectedIntegerFieldPath, integerFieldLocation.getPath()); - Assert.assertEquals(expectedStringFieldPath, stringFieldLocation.getPath()); - Assert.assertEquals(expectedIntegerFieldToString, integerFieldLocation.toString()); - Assert.assertEquals(integerFieldXmlName, integerFieldLocation.getMemberName()); + assertEquals(expectedIntegerFieldPath, integerFieldLocation.getPath()); + assertEquals(expectedStringFieldPath, stringFieldLocation.getPath()); + assertEquals(expectedIntegerFieldToString, integerFieldLocation.toString()); + assertEquals(integerFieldXmlName, integerFieldLocation.getMemberName()); } } diff --git a/src/test/java/org/codehaus/mojo/jaxb2/schemageneration/postprocessing/javadoc/JavaDocExtractorTest.java b/src/test/java/org/codehaus/mojo/jaxb2/schemageneration/postprocessing/javadoc/JavaDocExtractorTest.java index 6c05b169..f22ee079 100644 --- a/src/test/java/org/codehaus/mojo/jaxb2/schemageneration/postprocessing/javadoc/JavaDocExtractorTest.java +++ b/src/test/java/org/codehaus/mojo/jaxb2/schemageneration/postprocessing/javadoc/JavaDocExtractorTest.java @@ -20,15 +20,16 @@ import org.codehaus.mojo.jaxb2.shared.filters.Filter; import org.codehaus.mojo.jaxb2.shared.filters.Filters; import org.codehaus.mojo.jaxb2.shared.filters.pattern.PatternFileFilter; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; /** * @author Lennart Jörelid, jGuru Europe AB */ -public class JavaDocExtractorTest { +class JavaDocExtractorTest { // Shared state private File javaDocBasicDir; @@ -37,33 +38,33 @@ public class JavaDocExtractorTest { private File javaDocXmlWrappersDir; private BufferingLog log; - @Before - public void setupSharedState() { + @BeforeEach + void setupSharedState() { log = new BufferingLog(BufferingLog.LogLevel.DEBUG); // Find the desired directory final URL dirURL = getClass().getClassLoader().getResource("testdata/schemageneration/javadoc/basic"); this.javaDocBasicDir = new File(dirURL.getPath()); - Assert.assertTrue(javaDocBasicDir.exists() && javaDocBasicDir.isDirectory()); + assertTrue(javaDocBasicDir.exists() && javaDocBasicDir.isDirectory()); final URL annotatedDirURL = getClass().getClassLoader().getResource("testdata/schemageneration/javadoc/annotated"); this.javaDocAnnotatedDir = new File(annotatedDirURL.getPath()); - Assert.assertTrue(javaDocAnnotatedDir.exists() && javaDocAnnotatedDir.isDirectory()); + assertTrue(javaDocAnnotatedDir.exists() && javaDocAnnotatedDir.isDirectory()); final URL enumsDirURL = getClass().getClassLoader().getResource("testdata/schemageneration/javadoc/enums"); this.javaDocEnumsDir = new File(enumsDirURL.getPath()); - Assert.assertTrue(javaDocEnumsDir.exists() && javaDocEnumsDir.isDirectory()); + assertTrue(javaDocEnumsDir.exists() && javaDocEnumsDir.isDirectory()); final URL wrappersDirURL = getClass().getClassLoader().getResource("testdata/schemageneration/javadoc/xmlwrappers"); this.javaDocXmlWrappersDir = new File(wrappersDirURL.getPath()); - Assert.assertTrue(javaDocXmlWrappersDir.exists() && javaDocXmlWrappersDir.isDirectory()); + assertTrue(javaDocXmlWrappersDir.exists() && javaDocXmlWrappersDir.isDirectory()); } @Test - public void validateLogStatementsDuringProcessing() { + void validateLogStatementsDuringProcessing() { // Assemble final JavaDocExtractor unitUnderTest = new JavaDocExtractor(log); @@ -86,21 +87,21 @@ public void validateLogStatementsDuringProcessing() { * 004: (DEBUG) Added method-level JavaDoc for [basic.NodeProcessor#accept(org.w3c.dom.Node)], * 005: (DEBUG) Added method-level JavaDoc for [basic.NodeProcessor#process(org.w3c.dom.Node)]] */ - Assert.assertEquals(6, keys.size()); - Assert.assertEquals("001: (INFO) Processing [1] java sources.", keys.get(1)); - Assert.assertEquals("002: (DEBUG) Added package-level JavaDoc for [basic]", keys.get(2)); - Assert.assertEquals("003: (DEBUG) Added class-level JavaDoc for [basic.NodeProcessor]", keys.get(3)); - Assert.assertEquals( + assertEquals(6, keys.size()); + assertEquals("001: (INFO) Processing [1] java sources.", keys.get(1)); + assertEquals("002: (DEBUG) Added package-level JavaDoc for [basic]", keys.get(2)); + assertEquals("003: (DEBUG) Added class-level JavaDoc for [basic.NodeProcessor]", keys.get(3)); + assertEquals( "004: (DEBUG) Added method-level JavaDoc for [basic.NodeProcessor#accept(org.w3c.dom.Node)]", keys.get(4)); - Assert.assertEquals( + assertEquals( "005: (DEBUG) Added method-level JavaDoc for [basic.NodeProcessor#process(org.w3c.dom.Node)]", keys.get(5)); } @Test - @Ignore - public void validateExtractingXmlAnnotatedName() throws Exception { + @Disabled + void validateExtractingXmlAnnotatedName() throws Exception { // Assemble final JavaDocExtractor unitUnderTest = new JavaDocExtractor(log); @@ -119,26 +120,26 @@ public void validateExtractingXmlAnnotatedName() throws Exception { final SortableLocation stringMethodLocation = result.getLocation(fieldAccessPrefix + "getStringField()"); final SortableLocation integerMethodLocation = result.getLocation(fieldAccessPrefix + "getIntegerField()"); - Assert.assertTrue(stringFieldLocation instanceof FieldLocation); - Assert.assertTrue(integerFieldLocation instanceof FieldLocation); - Assert.assertTrue(stringMethodLocation instanceof MethodLocation); - Assert.assertTrue(integerMethodLocation instanceof MethodLocation); + assertTrue(stringFieldLocation instanceof FieldLocation); + assertTrue(integerFieldLocation instanceof FieldLocation); + assertTrue(stringMethodLocation instanceof MethodLocation); + assertTrue(integerMethodLocation instanceof MethodLocation); - Assert.assertNull(stringMethodLocation.getAnnotationRenamedTo()); - Assert.assertNull(integerMethodLocation.getAnnotationRenamedTo()); - Assert.assertEquals("annotatedStringField", stringFieldLocation.getAnnotationRenamedTo()); - Assert.assertEquals("annotatedIntegerField", integerFieldLocation.getAnnotationRenamedTo()); + assertNull(stringMethodLocation.getAnnotationRenamedTo()); + assertNull(integerMethodLocation.getAnnotationRenamedTo()); + assertEquals("annotatedStringField", stringFieldLocation.getAnnotationRenamedTo()); + assertEquals("annotatedIntegerField", integerFieldLocation.getAnnotationRenamedTo()); - Assert.assertEquals( + assertEquals( JavaDocData.NO_COMMENT, result.getJavaDoc(stringMethodLocation.getPath()).getComment()); - Assert.assertEquals( + assertEquals( JavaDocData.NO_COMMENT, result.getJavaDoc(integerMethodLocation.getPath()).getComment()); - Assert.assertEquals( + assertEquals( "This is a string field.", result.getJavaDoc(stringFieldLocation.getPath()).getComment()); - Assert.assertEquals( + assertEquals( "This is an integer field.", result.getJavaDoc(integerFieldLocation.getPath()).getComment()); @@ -150,33 +151,33 @@ public void validateExtractingXmlAnnotatedName() throws Exception { final SortableLocation integerMethodLocation2 = result.getLocation(methodAccessPrefix + "annotatedIntegerMethod()"); - Assert.assertTrue(stringFieldLocation2 instanceof FieldLocation); - Assert.assertTrue(integerFieldLocation2 instanceof FieldLocation); - Assert.assertTrue(stringMethodLocation2 instanceof MethodLocation); - Assert.assertTrue(integerMethodLocation2 instanceof MethodLocation); + assertTrue(stringFieldLocation2 instanceof FieldLocation); + assertTrue(integerFieldLocation2 instanceof FieldLocation); + assertTrue(stringMethodLocation2 instanceof MethodLocation); + assertTrue(integerMethodLocation2 instanceof MethodLocation); - Assert.assertNull(stringFieldLocation2.getAnnotationRenamedTo()); - Assert.assertNull(integerFieldLocation2.getAnnotationRenamedTo()); - Assert.assertEquals("annotatedStringMethod", stringMethodLocation2.getAnnotationRenamedTo()); - Assert.assertEquals("annotatedIntegerMethod", integerMethodLocation2.getAnnotationRenamedTo()); + assertNull(stringFieldLocation2.getAnnotationRenamedTo()); + assertNull(integerFieldLocation2.getAnnotationRenamedTo()); + assertEquals("annotatedStringMethod", stringMethodLocation2.getAnnotationRenamedTo()); + assertEquals("annotatedIntegerMethod", integerMethodLocation2.getAnnotationRenamedTo()); - Assert.assertEquals( + assertEquals( "Getter for the stringField.", result.getJavaDoc(stringMethodLocation2.getPath()).getComment()); - Assert.assertEquals( + assertEquals( "Getter for the integerField.", result.getJavaDoc(integerMethodLocation2.getPath()).getComment()); - Assert.assertEquals( + assertEquals( JavaDocData.NO_COMMENT, result.getJavaDoc(stringFieldLocation2.getPath()).getComment()); - Assert.assertEquals( + assertEquals( JavaDocData.NO_COMMENT, result.getJavaDoc(integerFieldLocation2.getPath()).getComment()); } @Test - @Ignore - public void validateJavaDocsForXmlEnumsAreCorrectlyApplied() { + @Disabled + void validateJavaDocsForXmlEnumsAreCorrectlyApplied() { // Assemble final JavaDocExtractor unitUnderTest = new JavaDocExtractor(log); @@ -186,7 +187,7 @@ public void validateJavaDocsForXmlEnumsAreCorrectlyApplied() { final MapWrapper mapWrapper = new MapWrapper(result); // Assert - Assert.assertEquals(21, mapWrapper.sortableLocations2JavaDocDataMap.size()); + assertEquals(21, mapWrapper.sortableLocations2JavaDocDataMap.size()); final List paths = Arrays.asList( "enums", @@ -211,9 +212,9 @@ public void validateJavaDocsForXmlEnumsAreCorrectlyApplied() { "enums.FoodPreference#meatEater", "enums.FoodPreference#milkDrinker"); for (String current : paths) { - Assert.assertTrue( - "Required path [" + current + "] not found.", - mapWrapper.path2LocationMap.keySet().contains(current.trim())); + assertTrue( + mapWrapper.path2LocationMap.keySet().contains(current.trim()), + "Required path [" + current + "] not found."); } // Finally, validate that the injected XML document comments @@ -240,8 +241,8 @@ public void validateJavaDocsForXmlEnumsAreCorrectlyApplied() { } @Test - @Ignore - public void validateJavaDocsForXmlWrapperAnnotatedFieldsAndMethodsAreCorrectlyApplied() throws Exception { + @Disabled + void validateJavaDocsForXmlWrapperAnnotatedFieldsAndMethodsAreCorrectlyApplied() throws Exception { // Assemble final JavaDocExtractor unitUnderTest = new JavaDocExtractor(log); @@ -251,7 +252,7 @@ public void validateJavaDocsForXmlWrapperAnnotatedFieldsAndMethodsAreCorrectlyAp final MapWrapper mapWrapper = new MapWrapper(result); // Assert - Assert.assertEquals(11, mapWrapper.sortableLocations2JavaDocDataMap.size()); + assertEquals(11, mapWrapper.sortableLocations2JavaDocDataMap.size()); final String packagePrefix = "org.codehaus.mojo.jaxb2.schemageneration.postprocessing.javadoc.wrappers"; final List paths = new ArrayList(); @@ -271,9 +272,9 @@ public void validateJavaDocsForXmlWrapperAnnotatedFieldsAndMethodsAreCorrectlyAp } for (String current : paths) { - Assert.assertTrue( - "Required path [" + current + "] not found.", - mapWrapper.path2LocationMap.keySet().contains(current.trim())); + assertTrue( + mapWrapper.path2LocationMap.keySet().contains(current.trim()), + "Required path [" + current + "] not found."); } mapWrapper.validateJavaDocCommentText( @@ -291,7 +292,7 @@ public void validateJavaDocsForXmlWrapperAnnotatedFieldsAndMethodsAreCorrectlyAp } @Test - public void validatePathsFromProcessing() { + void validatePathsFromProcessing() { // Assemble final JavaDocExtractor unitUnderTest = new JavaDocExtractor(log); @@ -302,18 +303,18 @@ public void validatePathsFromProcessing() { // Assert final ArrayList sortableLocations = new ArrayList(result.getAll().keySet()); - Assert.assertEquals(4, sortableLocations.size()); + assertEquals(4, sortableLocations.size()); final List paths = new ArrayList(result.getPaths()); - Assert.assertEquals(4, paths.size()); - Assert.assertEquals("basic", paths.get(0)); - Assert.assertEquals("basic.NodeProcessor", paths.get(1)); - Assert.assertEquals("basic.NodeProcessor#accept(org.w3c.dom.Node)", paths.get(2)); - Assert.assertEquals("basic.NodeProcessor#process(org.w3c.dom.Node)", paths.get(3)); + assertEquals(4, paths.size()); + assertEquals("basic", paths.get(0)); + assertEquals("basic.NodeProcessor", paths.get(1)); + assertEquals("basic.NodeProcessor#accept(org.w3c.dom.Node)", paths.get(2)); + assertEquals("basic.NodeProcessor#process(org.w3c.dom.Node)", paths.get(3)); } @Test - public void validateJavaDocDataFromProcessing() { + void validateJavaDocDataFromProcessing() { // Assemble final String basicPackagePath = "basic"; @@ -338,12 +339,12 @@ public void validateJavaDocDataFromProcessing() { */ final SortableLocation packageLocation = result.getLocation(basicPackagePath); final JavaDocData basicPackageJavaDoc = result.getJavaDoc(basicPackagePath); - Assert.assertTrue(packageLocation instanceof PackageLocation); + assertTrue(packageLocation instanceof PackageLocation); final PackageLocation castPackageLocation = (PackageLocation) packageLocation; - Assert.assertEquals("basic", castPackageLocation.getPackageName()); - Assert.assertEquals(JavaDocData.NO_COMMENT, basicPackageJavaDoc.getComment()); - Assert.assertEquals(0, basicPackageJavaDoc.getTag2ValueMap().size()); + assertEquals("basic", castPackageLocation.getPackageName()); + assertEquals(JavaDocData.NO_COMMENT, basicPackageJavaDoc.getComment()); + assertEquals(0, basicPackageJavaDoc.getTag2ValueMap().size()); /* +================= @@ -355,18 +356,17 @@ public void validateJavaDocDataFromProcessing() { */ final SortableLocation classLocation = result.getLocation(nodeProcessorClassPath); final JavaDocData nodeProcessorClassJavaDoc = result.getJavaDoc(nodeProcessorClassPath); - Assert.assertTrue(classLocation instanceof ClassLocation); + assertTrue(classLocation instanceof ClassLocation); final ClassLocation castClassLocation = (ClassLocation) classLocation; - Assert.assertEquals("basic", castClassLocation.getPackageName()); - Assert.assertEquals("NodeProcessor", castClassLocation.getClassName()); - Assert.assertEquals( - "Processor/visitor pattern specification for DOM Nodes.", nodeProcessorClassJavaDoc.getComment()); + assertEquals("basic", castClassLocation.getPackageName()); + assertEquals("NodeProcessor", castClassLocation.getClassName()); + assertEquals("Processor/visitor pattern specification for DOM Nodes.", nodeProcessorClassJavaDoc.getComment()); final SortedMap classTag2ValueMap = nodeProcessorClassJavaDoc.getTag2ValueMap(); - Assert.assertEquals(2, classTag2ValueMap.size()); - Assert.assertEquals("org.w3c.dom.Node", classTag2ValueMap.get("see")); - Assert.assertEquals( + assertEquals(2, classTag2ValueMap.size()); + assertEquals("org.w3c.dom.Node", classTag2ValueMap.get("see")); + assertEquals( "Lennart Jörelid, Mr. Foo", classTag2ValueMap.get("author")); /* @@ -379,19 +379,19 @@ public void validateJavaDocDataFromProcessing() { */ final SortableLocation acceptMethodLocation = result.getLocation(acceptMethodPath); final JavaDocData acceptMethodClassJavaDoc = result.getJavaDoc(acceptMethodPath); - Assert.assertTrue(acceptMethodLocation instanceof MethodLocation); + assertTrue(acceptMethodLocation instanceof MethodLocation); final MethodLocation castMethodLocation = (MethodLocation) acceptMethodLocation; - Assert.assertEquals("basic", castMethodLocation.getPackageName()); - Assert.assertEquals("NodeProcessor", castMethodLocation.getClassName()); - Assert.assertEquals("(org.w3c.dom.Node)", castMethodLocation.getParametersAsString()); - Assert.assertEquals( + assertEquals("basic", castMethodLocation.getPackageName()); + assertEquals("NodeProcessor", castMethodLocation.getClassName()); + assertEquals("(org.w3c.dom.Node)", castMethodLocation.getParametersAsString()); + assertEquals( "Defines if this visitor should process the provided node.", acceptMethodClassJavaDoc.getComment()); final SortedMap methodTag2ValueMap = acceptMethodClassJavaDoc.getTag2ValueMap(); - Assert.assertEquals(2, methodTag2ValueMap.size()); - Assert.assertEquals("aNode The DOM node to process.", methodTag2ValueMap.get("param")); - Assert.assertEquals( + assertEquals(2, methodTag2ValueMap.size()); + assertEquals("aNode The DOM node to process.", methodTag2ValueMap.get("param")); + assertEquals( "true if the provided Node should be processed by this NodeProcessor.", methodTag2ValueMap.get("return")); } @@ -440,7 +440,7 @@ public void validateJavaDocCommentText(final String expected, final String path) final JavaDocData xmlWrapperJavaDocData = sortableLocations2JavaDocDataMap.get(sortableLocation); // All Done. - Assert.assertEquals(expected, xmlWrapperJavaDocData.getComment()); + assertEquals(expected, xmlWrapperJavaDocData.getComment()); } } @@ -450,7 +450,7 @@ private void validateJavaDocCommentText(final MapWrapper wrapper, final String e final JavaDocData xmlWrapperJavaDocData = wrapper.sortableLocations2JavaDocDataMap.get(sortableLocation); // All Done. - Assert.assertEquals(expected, xmlWrapperJavaDocData.getComment()); + assertEquals(expected, xmlWrapperJavaDocData.getComment()); } private SearchableDocumentation getSearchableDocumentationFor( @@ -472,7 +472,7 @@ private SearchableDocumentation getSearchableDocumentationFor( // Find all normal Files not being ".xsd" files below the supplied sourceDirs final List sourceFiles = FileSystemUtilities.resolveRecursively(sourceDirs, excludeFilesMatching, log); - Assert.assertEquals(expectedNumberOfFiles, sourceFiles.size()); + assertEquals(expectedNumberOfFiles, sourceFiles.size()); // Add the found files as source files unitUnderTest.addSourceFiles(sourceFiles); diff --git a/src/test/java/org/codehaus/mojo/jaxb2/schemageneration/postprocessing/javadoc/XsdAnnotationProcessorSemiDocumentedTest.java b/src/test/java/org/codehaus/mojo/jaxb2/schemageneration/postprocessing/javadoc/XsdAnnotationProcessorSemiDocumentedTest.java index b2984531..942e879b 100644 --- a/src/test/java/org/codehaus/mojo/jaxb2/schemageneration/postprocessing/javadoc/XsdAnnotationProcessorSemiDocumentedTest.java +++ b/src/test/java/org/codehaus/mojo/jaxb2/schemageneration/postprocessing/javadoc/XsdAnnotationProcessorSemiDocumentedTest.java @@ -3,21 +3,22 @@ import java.util.Arrays; import java.util.List; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.w3c.dom.Document; import org.w3c.dom.Node; +import static org.junit.jupiter.api.Assertions.assertTrue; + /** * @author Lennart Jörelid, jGuru Europe AB */ -public class XsdAnnotationProcessorSemiDocumentedTest extends AbstractSourceCodeAwareNodeProcessingTest { +class XsdAnnotationProcessorSemiDocumentedTest extends AbstractSourceCodeAwareNodeProcessingTest { // Shared state private JavaDocRenderer renderer = new DefaultJavaDocRenderer(); @Test - public void validateProcessingNodesInVanillaXSD() throws Exception { + void validateProcessingNodesInVanillaXSD() throws Exception { // Assemble final String path = "testdata/schemageneration/javadoc/expectedSemiDocumentedClass.xml"; @@ -34,7 +35,7 @@ public void validateProcessingNodesInVanillaXSD() throws Exception { final String processed = printDocument(document); // System.out.println("Got: " + processed); - Assert.assertTrue(compareXmlIgnoringWhitespace(expected, processed).identical()); + assertTrue(compareXmlIgnoringWhitespace(expected, processed).identical()); } /** diff --git a/src/test/java/org/codehaus/mojo/jaxb2/schemageneration/postprocessing/javadoc/XsdAnnotationProcessorTest.java b/src/test/java/org/codehaus/mojo/jaxb2/schemageneration/postprocessing/javadoc/XsdAnnotationProcessorTest.java index 29a7125f..a6ad8c35 100644 --- a/src/test/java/org/codehaus/mojo/jaxb2/schemageneration/postprocessing/javadoc/XsdAnnotationProcessorTest.java +++ b/src/test/java/org/codehaus/mojo/jaxb2/schemageneration/postprocessing/javadoc/XsdAnnotationProcessorTest.java @@ -4,21 +4,22 @@ import java.util.List; import org.codehaus.mojo.jaxb2.schemageneration.postprocessing.javadoc.wrappers.ExampleXmlWrapper; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.w3c.dom.Document; import org.w3c.dom.Node; +import static org.junit.jupiter.api.Assertions.assertTrue; + /** * @author Lennart Jörelid, jGuru Europe AB */ -public class XsdAnnotationProcessorTest extends AbstractSourceCodeAwareNodeProcessingTest { +class XsdAnnotationProcessorTest extends AbstractSourceCodeAwareNodeProcessingTest { // Shared state private JavaDocRenderer renderer = new DefaultJavaDocRenderer(); @Test - public void validateProcessingNodesInVanillaXSD() throws Exception { + void validateProcessingNodesInVanillaXSD() throws Exception { // Assemble final String path = "testdata/schemageneration/javadoc/expectedTransformedSomewhatNamedPerson.xml"; @@ -35,7 +36,7 @@ public void validateProcessingNodesInVanillaXSD() throws Exception { final String processed = printDocument(document); // System.out.println("Got: " + processed); - Assert.assertTrue(compareXmlIgnoringWhitespace(expected, processed).identical()); + assertTrue(compareXmlIgnoringWhitespace(expected, processed).identical()); } /** diff --git a/src/test/java/org/codehaus/mojo/jaxb2/schemageneration/postprocessing/javadoc/XsdEnumerationAnnotationProcessorTest.java b/src/test/java/org/codehaus/mojo/jaxb2/schemageneration/postprocessing/javadoc/XsdEnumerationAnnotationProcessorTest.java index a51e09fb..76a580dc 100644 --- a/src/test/java/org/codehaus/mojo/jaxb2/schemageneration/postprocessing/javadoc/XsdEnumerationAnnotationProcessorTest.java +++ b/src/test/java/org/codehaus/mojo/jaxb2/schemageneration/postprocessing/javadoc/XsdEnumerationAnnotationProcessorTest.java @@ -6,21 +6,22 @@ import org.codehaus.mojo.jaxb2.schemageneration.postprocessing.javadoc.enums.AmericanCoin; import org.codehaus.mojo.jaxb2.schemageneration.postprocessing.javadoc.enums.ExampleEnumHolder; import org.codehaus.mojo.jaxb2.schemageneration.postprocessing.javadoc.enums.FoodPreference; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.w3c.dom.Document; import org.w3c.dom.Node; +import static org.junit.jupiter.api.Assertions.assertTrue; + /** * @author Lennart Jörelid, jGuru Europe AB */ -public class XsdEnumerationAnnotationProcessorTest extends AbstractSourceCodeAwareNodeProcessingTest { +class XsdEnumerationAnnotationProcessorTest extends AbstractSourceCodeAwareNodeProcessingTest { // Shared state private JavaDocRenderer renderer = new DefaultJavaDocRenderer(); @Test - public void validateProcessingNodesInVanillaXSD() throws Exception { + void validateProcessingNodesInVanillaXSD() throws Exception { // Assemble final String path = "testdata/schemageneration/javadoc/enums/expectedTransformedExampleEnumHolder.xsd"; @@ -38,7 +39,7 @@ public void validateProcessingNodesInVanillaXSD() throws Exception { final String processed = printDocument(xsdGeneratedFromClassesInMethod); // System.out.println("Got: " + processed); - Assert.assertTrue(compareXmlIgnoringWhitespace(expected, processed).identical()); + assertTrue(compareXmlIgnoringWhitespace(expected, processed).identical()); } /** diff --git a/src/test/java/org/codehaus/mojo/jaxb2/schemageneration/postprocessing/javadoc/enums/XsdAnnotationProcessorAndEnumsTest.java b/src/test/java/org/codehaus/mojo/jaxb2/schemageneration/postprocessing/javadoc/enums/XsdAnnotationProcessorAndEnumsTest.java index 25ff3b0f..974afbdd 100644 --- a/src/test/java/org/codehaus/mojo/jaxb2/schemageneration/postprocessing/javadoc/enums/XsdAnnotationProcessorAndEnumsTest.java +++ b/src/test/java/org/codehaus/mojo/jaxb2/schemageneration/postprocessing/javadoc/enums/XsdAnnotationProcessorAndEnumsTest.java @@ -12,24 +12,25 @@ import org.codehaus.mojo.jaxb2.schemageneration.postprocessing.javadoc.NoAuthorJavaDocRenderer; import org.codehaus.mojo.jaxb2.schemageneration.postprocessing.javadoc.SomewhatNamedPerson; import org.codehaus.mojo.jaxb2.schemageneration.postprocessing.javadoc.XsdAnnotationProcessor; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.w3c.dom.Document; import org.w3c.dom.Node; import org.xmlunit.builder.DiffBuilder; import org.xmlunit.diff.Diff; import se.jguru.shared.algorithms.api.resources.PropertyResources; +import static org.junit.jupiter.api.Assertions.assertFalse; + /** * @author Lennart Jörelid, jGuru Europe AB */ -public class XsdAnnotationProcessorAndEnumsTest extends AbstractSourceCodeAwareNodeProcessingTest { +class XsdAnnotationProcessorAndEnumsTest extends AbstractSourceCodeAwareNodeProcessingTest { // Shared state private JavaDocRenderer renderer = new NoAuthorJavaDocRenderer(); @Test - public void validateGeneratedXmlForEnums() throws Exception { + void validateGeneratedXmlForEnums() throws Exception { // Assemble final String expected = @@ -54,12 +55,12 @@ public void validateGeneratedXmlForEnums() throws Exception { .ignoreWhitespace() .ignoreComments() .build(); - Assert.assertFalse(diff.hasDifferences()); + assertFalse(diff.hasDifferences()); // XmlTestUtils.compareXmlIgnoringWhitespace( expected, out.toString() ); } @Test - public void validateHandlingXmlElementWrapperDocumentation() throws Exception { + void validateHandlingXmlElementWrapperDocumentation() throws Exception { // Assmeble final Document document = namespace2DocumentMap.get(SomewhatNamedPerson.NAMESPACE); diff --git a/src/test/java/org/codehaus/mojo/jaxb2/schemageneration/postprocessing/schemaenhancement/ChangeFilenameProcessorTest.java b/src/test/java/org/codehaus/mojo/jaxb2/schemageneration/postprocessing/schemaenhancement/ChangeFilenameProcessorTest.java index e81d5aaf..88f5b53b 100644 --- a/src/test/java/org/codehaus/mojo/jaxb2/schemageneration/postprocessing/schemaenhancement/ChangeFilenameProcessorTest.java +++ b/src/test/java/org/codehaus/mojo/jaxb2/schemageneration/postprocessing/schemaenhancement/ChangeFilenameProcessorTest.java @@ -7,16 +7,17 @@ import org.codehaus.mojo.jaxb2.schemageneration.XsdGeneratorHelper; import org.codehaus.mojo.jaxb2.schemageneration.postprocessing.DebugNodeProcessor; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.w3c.dom.Document; import org.w3c.dom.Node; +import static org.junit.jupiter.api.Assertions.assertEquals; + /** @author Lennart Jörelid */ -public class ChangeFilenameProcessorTest { +class ChangeFilenameProcessorTest { @Test - public void validateAcceptCriteria() { + void validateAcceptCriteria() { // Assemble final String oldFileName = "foo"; @@ -36,9 +37,9 @@ public void validateAcceptCriteria() { // Assert final List acceptedNodes = debugNodeProcessor.getAcceptedNodes(); - Assert.assertEquals(1, acceptedNodes.size()); - Assert.assertEquals("schemaLocation", acceptedNodes.get(0).getNodeName()); - Assert.assertEquals(newFileName, acceptedNodes.get(0).getNodeValue()); + assertEquals(1, acceptedNodes.size()); + assertEquals("schemaLocation", acceptedNodes.get(0).getNodeName()); + assertEquals(newFileName, acceptedNodes.get(0).getNodeValue()); } // diff --git a/src/test/java/org/codehaus/mojo/jaxb2/schemageneration/postprocessing/schemaenhancement/ChangeNamespacePrefixProcessorTest.java b/src/test/java/org/codehaus/mojo/jaxb2/schemageneration/postprocessing/schemaenhancement/ChangeNamespacePrefixProcessorTest.java index 03100787..9ef42fc4 100644 --- a/src/test/java/org/codehaus/mojo/jaxb2/schemageneration/postprocessing/schemaenhancement/ChangeNamespacePrefixProcessorTest.java +++ b/src/test/java/org/codehaus/mojo/jaxb2/schemageneration/postprocessing/schemaenhancement/ChangeNamespacePrefixProcessorTest.java @@ -5,17 +5,18 @@ import org.codehaus.mojo.jaxb2.schemageneration.XsdGeneratorHelper; import org.codehaus.mojo.jaxb2.schemageneration.postprocessing.DebugNodeProcessor; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.w3c.dom.Document; import org.w3c.dom.Node; +import static org.junit.jupiter.api.Assertions.assertEquals; + /** * @author Lennart Jörelid */ -public class ChangeNamespacePrefixProcessorTest { +class ChangeNamespacePrefixProcessorTest { @Test - public void validateAcceptCriteria() { + void validateAcceptCriteria() { // Assemble final String oldNamespacePrefix = "oldNamespacePrefix"; final String newNamespacePrefix = "newNamespacePrefix"; @@ -32,22 +33,22 @@ public void validateAcceptCriteria() { // Assert final List acceptedNodes = debugNodeProcessor.getAcceptedNodes(); - Assert.assertEquals(3, acceptedNodes.size()); + assertEquals(3, acceptedNodes.size()); // Note that the DebugNodeProcessor acquires the node *before* it is actually // processed - implying that the nodeName is not yet changed. Node namespaceDefinitionAttribute = acceptedNodes.get(0); - Assert.assertEquals("xmlns:" + oldNamespacePrefix, namespaceDefinitionAttribute.getNodeName()); - Assert.assertEquals(namespaceURI, namespaceDefinitionAttribute.getNodeValue()); + assertEquals("xmlns:" + oldNamespacePrefix, namespaceDefinitionAttribute.getNodeName()); + assertEquals(namespaceURI, namespaceDefinitionAttribute.getNodeValue()); Node elementReferenceAttribute = acceptedNodes.get(1); - Assert.assertEquals("ref", elementReferenceAttribute.getNodeName()); - Assert.assertEquals( + assertEquals("ref", elementReferenceAttribute.getNodeName()); + assertEquals( newNamespacePrefix + ":aRequiredElementInAnotherNamespace", elementReferenceAttribute.getNodeValue()); Node extensionAttribute = acceptedNodes.get(2); - Assert.assertEquals("base", extensionAttribute.getNodeName()); - Assert.assertEquals(newNamespacePrefix + ":aBaseType", extensionAttribute.getNodeValue()); + assertEquals("base", extensionAttribute.getNodeName()); + assertEquals(newNamespacePrefix + ":aBaseType", extensionAttribute.getNodeValue()); } // diff --git a/src/test/java/org/codehaus/mojo/jaxb2/schemageneration/postprocessing/schemaenhancement/SimpleNamespaceResolverTest.java b/src/test/java/org/codehaus/mojo/jaxb2/schemageneration/postprocessing/schemaenhancement/SimpleNamespaceResolverTest.java index ab512655..6f2f99b2 100644 --- a/src/test/java/org/codehaus/mojo/jaxb2/schemageneration/postprocessing/schemaenhancement/SimpleNamespaceResolverTest.java +++ b/src/test/java/org/codehaus/mojo/jaxb2/schemageneration/postprocessing/schemaenhancement/SimpleNamespaceResolverTest.java @@ -9,8 +9,9 @@ import java.util.Map; import org.codehaus.plexus.util.FileUtils; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; /** * @author Lennart Jörelid @@ -24,7 +25,7 @@ private File getSchemaFile(String resource) { } @Test - public void validateCollectingSchemaInfoForSingleNamespaceSchemaFile() { + void validateCollectingSchemaInfoForSingleNamespaceSchemaFile() { // Assemble final String schemaFile = "yetAnotherSchema.xsd"; final File resolvedSchemaFile = getSchemaFile(SCHEMA_DIR + schemaFile); @@ -34,17 +35,17 @@ public void validateCollectingSchemaInfoForSingleNamespaceSchemaFile() { final Map namespaceURI2PrefixMap = unitUnderTest.getNamespaceURI2PrefixMap(); // Assert - Assert.assertEquals(schemaFile, unitUnderTest.getSourceFilename()); - Assert.assertEquals("http://yet/another/namespace", unitUnderTest.getLocalNamespaceURI()); + assertEquals(schemaFile, unitUnderTest.getSourceFilename()); + assertEquals("http://yet/another/namespace", unitUnderTest.getLocalNamespaceURI()); - Assert.assertEquals(1, namespaceURI2PrefixMap.size()); - Assert.assertEquals("xs", namespaceURI2PrefixMap.get(XMLConstants.W3C_XML_SCHEMA_NS_URI)); + assertEquals(1, namespaceURI2PrefixMap.size()); + assertEquals("xs", namespaceURI2PrefixMap.get(XMLConstants.W3C_XML_SCHEMA_NS_URI)); - Assert.assertEquals(XMLConstants.W3C_XML_SCHEMA_NS_URI, unitUnderTest.getNamespaceURI("xs")); + assertEquals(XMLConstants.W3C_XML_SCHEMA_NS_URI, unitUnderTest.getNamespaceURI("xs")); } @Test - public void validateCollectingSchemaInfoForMultipleNamespaceSchemaFile() { + void validateCollectingSchemaInfoForMultipleNamespaceSchemaFile() { // Assemble final String schemaFile = "anotherSchema.xsd"; final SimpleNamespaceResolver unitUnderTest = @@ -54,33 +55,35 @@ public void validateCollectingSchemaInfoForMultipleNamespaceSchemaFile() { final Map namespaceURI2PrefixMap = unitUnderTest.getNamespaceURI2PrefixMap(); // Assert - Assert.assertEquals(schemaFile, unitUnderTest.getSourceFilename()); - Assert.assertEquals("http://another/namespace", unitUnderTest.getLocalNamespaceURI()); + assertEquals(schemaFile, unitUnderTest.getSourceFilename()); + assertEquals("http://another/namespace", unitUnderTest.getLocalNamespaceURI()); - Assert.assertEquals(3, namespaceURI2PrefixMap.size()); - Assert.assertEquals("xs", namespaceURI2PrefixMap.get(XMLConstants.W3C_XML_SCHEMA_NS_URI)); - Assert.assertEquals("yetAnother", namespaceURI2PrefixMap.get("http://yet/another/namespace")); - Assert.assertEquals("some", namespaceURI2PrefixMap.get("http://some/namespace")); + assertEquals(3, namespaceURI2PrefixMap.size()); + assertEquals("xs", namespaceURI2PrefixMap.get(XMLConstants.W3C_XML_SCHEMA_NS_URI)); + assertEquals("yetAnother", namespaceURI2PrefixMap.get("http://yet/another/namespace")); + assertEquals("some", namespaceURI2PrefixMap.get("http://some/namespace")); for (String current : namespaceURI2PrefixMap.keySet()) { final String currentPrefix = namespaceURI2PrefixMap.get(current); - Assert.assertEquals(currentPrefix, unitUnderTest.getPrefix(current)); + assertEquals(currentPrefix, unitUnderTest.getPrefix(current)); } } - @Test(expected = IllegalArgumentException.class) - public void validateExceptionOnEmptyRelativePathToXmlFile() { - // Assemble - final String incorrectEmpty = ""; - - // Act & Assert - new SimpleNamespaceResolver(getSchemaFile(incorrectEmpty)); - Assert.fail("Creating a SimpleNamespaceResolver with empty argument " - + "should yield an IllegalArgumentException."); + @Test + void validateExceptionOnEmptyRelativePathToXmlFile() { + assertThrows(IllegalArgumentException.class, () -> { + // Assemble + final String incorrectEmpty = ""; + + // Act & Assert + new SimpleNamespaceResolver(getSchemaFile(incorrectEmpty)); + fail("Creating a SimpleNamespaceResolver with empty argument " + + "should yield an IllegalArgumentException."); + }); } @Test - public void validateExceptionOnNonexistentXmlSchemaFile() { + void validateExceptionOnNonexistentXmlSchemaFile() { // Assemble final String nonExistentPath = "this/file/does/not/exist.xml"; final File nonExistent = new File(nonExistentPath); @@ -88,18 +91,18 @@ public void validateExceptionOnNonexistentXmlSchemaFile() { // Act & Assert try { new SimpleNamespaceResolver(nonExistent); - Assert.fail("Creating a SimpleNamespaceResolver connected to a nonexistent file " + fail("Creating a SimpleNamespaceResolver connected to a nonexistent file " + "should yield an IllegalArgumentException."); } catch (IllegalArgumentException e) { // Expected } catch (Exception e) { - Assert.fail("Expected IllegalArgumentException, but received [" + fail("Expected IllegalArgumentException, but received [" + e.getClass().getName() + "]"); } } @Test - public void validateJaxbNamespaceResolverComplianceInThrowingExceptionOnNullNamespaceResolverArguments() { + void validateJaxbNamespaceResolverComplianceInThrowingExceptionOnNullNamespaceResolverArguments() { // Assemble final String schemaFile = "yetAnotherSchema.xsd"; final SimpleNamespaceResolver unitUnderTest = @@ -109,37 +112,37 @@ public void validateJaxbNamespaceResolverComplianceInThrowingExceptionOnNullName // Act & Assert try { unitUnderTest.getPrefix(incorrectNull); - Assert.fail("Running getPrefix with a null argument should yield an IllegalArgumentException."); + fail("Running getPrefix with a null argument should yield an IllegalArgumentException."); } catch (IllegalArgumentException e) { // Expected } catch (Exception e) { - Assert.fail("Expected IllegalArgumentException, but received [" + fail("Expected IllegalArgumentException, but received [" + e.getClass().getName() + "]"); } try { unitUnderTest.getNamespaceURI(incorrectNull); - Assert.fail("Running getNamespaceURI with a null argument should yield an IllegalArgumentException."); + fail("Running getNamespaceURI with a null argument should yield an IllegalArgumentException."); } catch (IllegalArgumentException e) { // Expected } catch (Exception e) { - Assert.fail("Expected IllegalArgumentException, but received [" + fail("Expected IllegalArgumentException, but received [" + e.getClass().getName() + "]"); } try { unitUnderTest.getPrefixes(incorrectNull); - Assert.fail("Running getPrefixes with a null argument should yield an IllegalArgumentException."); + fail("Running getPrefixes with a null argument should yield an IllegalArgumentException."); } catch (IllegalArgumentException e) { // Expected } catch (Exception e) { - Assert.fail("Expected IllegalArgumentException, but received [" + fail("Expected IllegalArgumentException, but received [" + e.getClass().getName() + "]"); } } @Test - public void validatePrefixesIterator() { + void validatePrefixesIterator() { // Assemble final String schemaFile = "yetAnotherSchema.xsd"; final SimpleNamespaceResolver unitUnderTest = @@ -152,7 +155,7 @@ public void validatePrefixesIterator() { } // Assert - Assert.assertEquals(1, prefixesList.size()); - Assert.assertEquals("xs", prefixesList.get(0)); + assertEquals(1, prefixesList.size()); + assertEquals("xs", prefixesList.get(0)); } } diff --git a/src/test/java/org/codehaus/mojo/jaxb2/schemageneration/postprocessing/schemaenhancement/TransformSchemaTest.java b/src/test/java/org/codehaus/mojo/jaxb2/schemageneration/postprocessing/schemaenhancement/TransformSchemaTest.java index 25134760..a37c4c96 100644 --- a/src/test/java/org/codehaus/mojo/jaxb2/schemageneration/postprocessing/schemaenhancement/TransformSchemaTest.java +++ b/src/test/java/org/codehaus/mojo/jaxb2/schemageneration/postprocessing/schemaenhancement/TransformSchemaTest.java @@ -1,11 +1,13 @@ package org.codehaus.mojo.jaxb2.schemageneration.postprocessing.schemaenhancement; -import org.junit.Test; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertThrows; /** * @author Lennart Jörelid */ -public class TransformSchemaTest { +class TransformSchemaTest { // Shared state private static final String URI = "http://www.mithlond.se/foo/bar"; @@ -13,24 +15,30 @@ public class TransformSchemaTest { private static final String FILENAME = "mithlondBar"; private static final TransformSchema unitUnderTest = new TransformSchema(URI, PREFIX, FILENAME); - @Test(expected = IllegalArgumentException.class) - public void validateExceptionOnEmptyToFileArgument() { + @Test + void validateExceptionOnEmptyToFileArgument() { + assertThrows(IllegalArgumentException.class, () -> { - // Act & Assert - unitUnderTest.setToFile(""); + // Act & Assert + unitUnderTest.setToFile(""); + }); } - @Test(expected = IllegalArgumentException.class) - public void validateExceptionOnEmptyToPrefixArgument() { + @Test + void validateExceptionOnEmptyToPrefixArgument() { + assertThrows(IllegalArgumentException.class, () -> { - // Act & Assert - unitUnderTest.setToPrefix(""); + // Act & Assert + unitUnderTest.setToPrefix(""); + }); } - @Test(expected = IllegalArgumentException.class) - public void validateExceptionOnEmptyUriArgument() { + @Test + void validateExceptionOnEmptyUriArgument() { + assertThrows(IllegalArgumentException.class, () -> { - // Act & Assert - unitUnderTest.setUri(""); + // Act & Assert + unitUnderTest.setUri(""); + }); } } diff --git a/src/test/java/org/codehaus/mojo/jaxb2/shared/FileSystemUtilitiesTest.java b/src/test/java/org/codehaus/mojo/jaxb2/shared/FileSystemUtilitiesTest.java index 2f23ba32..24d7a861 100644 --- a/src/test/java/org/codehaus/mojo/jaxb2/shared/FileSystemUtilitiesTest.java +++ b/src/test/java/org/codehaus/mojo/jaxb2/shared/FileSystemUtilitiesTest.java @@ -16,16 +16,17 @@ import org.codehaus.mojo.jaxb2.shared.filters.Filter; import org.codehaus.mojo.jaxb2.shared.filters.Filters; import org.codehaus.mojo.jaxb2.shared.filters.pattern.PatternFileFilter; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import se.jguru.shared.algorithms.api.resources.PropertyResources; +import static org.junit.jupiter.api.Assertions.*; + /** * @author Lennart Jörelid, jGuru Europe AB * @since 2.0 */ -public class FileSystemUtilitiesTest { +class FileSystemUtilitiesTest { // Shared state private File fsUtilitiesDirectory; @@ -35,8 +36,8 @@ public class FileSystemUtilitiesTest { private File srcTestResources; private BufferingLog log; - @Before - public void setupSharedState() { + @BeforeEach + void setupSharedState() { this.log = new BufferingLog(BufferingLog.LogLevel.DEBUG); @@ -44,22 +45,22 @@ public void setupSharedState() { fsUtilitiesDirectory = new File(fsUtilitiesDirUrl.getPath()); canonicalsDirectory = new File(fsUtilitiesDirectory, "canonicals"); - Assert.assertTrue(FileSystemUtilities.EXISTING_DIRECTORY.accept(fsUtilitiesDirectory)); - Assert.assertTrue(FileSystemUtilities.EXISTING_DIRECTORY.accept(canonicalsDirectory)); + assertTrue(FileSystemUtilities.EXISTING_DIRECTORY.accept(fsUtilitiesDirectory)); + assertTrue(FileSystemUtilities.EXISTING_DIRECTORY.accept(canonicalsDirectory)); testFile2 = new File(fsUtilitiesDirectory, "TestFile2.txt"); testFile1 = new File(canonicalsDirectory, "TestFile1.txt"); - Assert.assertTrue(FileSystemUtilities.EXISTING_FILE.accept(testFile1)); - Assert.assertTrue(FileSystemUtilities.EXISTING_FILE.accept(testFile2)); + assertTrue(FileSystemUtilities.EXISTING_FILE.accept(testFile1)); + assertTrue(FileSystemUtilities.EXISTING_FILE.accept(testFile2)); final URL testdataDir = getClass().getClassLoader().getResource("testdata"); srcTestResources = new File(testdataDir.getPath()).getParentFile(); - Assert.assertTrue(FileSystemUtilities.EXISTING_DIRECTORY.accept(srcTestResources)); + assertTrue(FileSystemUtilities.EXISTING_DIRECTORY.accept(srcTestResources)); } @Test - public void validateGettingUrlForFile() { + void validateGettingUrlForFile() { // Assemble final String relativePath = "testdata/shared/filesystemutilities/canonicals/TestFile1.txt"; @@ -69,11 +70,11 @@ public void validateGettingUrlForFile() { final URL result = FileSystemUtilities.getUrlFor(testFile1); // Assert - Assert.assertEquals(expected, result); + assertEquals(expected, result); } @Test - public void validateCanonicalFileAndPath() { + void validateCanonicalFileAndPath() { // Assemble final File unitUnderTest = new File(canonicalsDirectory, "../TestFile2.txt"); @@ -86,23 +87,25 @@ public void validateCanonicalFileAndPath() { final File cFile2 = FileSystemUtilities.getCanonicalFile(testFile2); // Assert - Assert.assertEquals(cPath1, cPath2); - Assert.assertEquals(cFile1, cFile2); + assertEquals(cPath1, cPath2); + assertEquals(cFile1, cFile2); } - @Test(expected = NullPointerException.class) - public void validateExceptionOnGettingExistingFileWithRelativePathAndNullBasedir() { + @Test + void validateExceptionOnGettingExistingFileWithRelativePathAndNullBasedir() { + assertThrows(NullPointerException.class, () -> { - // Assemble - final String relativePath = "testdata/shared/filesystemutilities/TestFile2.txt"; - final File incorrectNullBaseDir = null; + // Assemble + final String relativePath = "testdata/shared/filesystemutilities/TestFile2.txt"; + final File incorrectNullBaseDir = null; - // Act & Assert - FileSystemUtilities.getExistingFile(relativePath, incorrectNullBaseDir); + // Act & Assert + FileSystemUtilities.getExistingFile(relativePath, incorrectNullBaseDir); + }); } @Test - public void validateSimplifiedFileExistenceRetrieval() { + void validateSimplifiedFileExistenceRetrieval() { // Assemble final String absolutePath = FileSystemUtilities.getCanonicalPath(testFile2); @@ -119,24 +122,26 @@ public void validateSimplifiedFileExistenceRetrieval() { FileSystemUtilities.getExistingFile(aNonExistentRelativePath, fsUtilitiesDirectory); // Assert - Assert.assertNotNull(absoluteFile); - Assert.assertNull(nonExistentAbsoluteFile); - Assert.assertNotNull(relativeFile); - Assert.assertNull(nonExistentRelativeFile); + assertNotNull(absoluteFile); + assertNull(nonExistentAbsoluteFile); + assertNotNull(relativeFile); + assertNull(nonExistentRelativeFile); } - @Test(expected = NullPointerException.class) - public void validateExceptionOnNullFileListWhenResolvingFilesAndRemovingExclusions() { + @Test + void validateExceptionOnNullFileListWhenResolvingFilesAndRemovingExclusions() { + assertThrows(NullPointerException.class, () -> { - // Assemble - final List incorrectNullFileList = null; + // Assemble + final List incorrectNullFileList = null; - // Act & Assert - FileSystemUtilities.resolveRecursively(incorrectNullFileList, null, log); + // Act & Assert + FileSystemUtilities.resolveRecursively(incorrectNullFileList, null, log); + }); } @Test - public void validateFilteredDirectoryListingUsingIncludeFilters() { + void validateFilteredDirectoryListingUsingIncludeFilters() { // Assemble final URL aDirURL = getClass().getClassLoader().getResource("testdata/shared/filefilter/exclusion"); @@ -147,20 +152,20 @@ public void validateFilteredDirectoryListingUsingIncludeFilters() { final List> allFiles = PatternFileFilter.createIncludeFilterList(log, "\\.*"); // Act & Assert - Assert.assertEquals(2, FileSystemUtilities.listFiles(dir, allFiles, log).size()); + assertEquals(2, FileSystemUtilities.listFiles(dir, allFiles, log).size()); final List textFilesList = FileSystemUtilities.listFiles(dir, textFiles, log); - Assert.assertEquals(1, textFilesList.size()); - Assert.assertEquals("TextFile.txt", textFilesList.get(0).getName()); + assertEquals(1, textFilesList.size()); + assertEquals("TextFile.txt", textFilesList.get(0).getName()); final List xmlFilesList = FileSystemUtilities.listFiles(dir, xmlFiles, log); - Assert.assertEquals(1, xmlFilesList.size()); - Assert.assertEquals("AnXmlFile.xml", xmlFilesList.get(0).getName()); + assertEquals(1, xmlFilesList.size()); + assertEquals("AnXmlFile.xml", xmlFilesList.get(0).getName()); } @Test @SuppressWarnings("all") - public void validateFilteredDirectoryListingUsingExcludeFilters() { + void validateFilteredDirectoryListingUsingExcludeFilters() { // Assemble final URL aDirURL = getClass().getClassLoader().getResource("testdata/shared/filefilter/exclusion"); @@ -171,20 +176,20 @@ public void validateFilteredDirectoryListingUsingExcludeFilters() { final List> noFiles = PatternFileFilter.createExcludeFilterList(log, "\\.*"); // Act & Assert - Assert.assertEquals( + assertEquals( 0, FileSystemUtilities.listFiles(exclusionDir, noFiles, log).size()); final List noXmlFilesList = FileSystemUtilities.listFiles(exclusionDir, noXmlFiles, log); - Assert.assertEquals(1, noXmlFilesList.size()); - Assert.assertEquals("TextFile.txt", noXmlFilesList.get(0).getName()); + assertEquals(1, noXmlFilesList.size()); + assertEquals("TextFile.txt", noXmlFilesList.get(0).getName()); final List noTextFilesList = FileSystemUtilities.listFiles(exclusionDir, noTextFiles, log); - Assert.assertEquals(1, noTextFilesList.size()); - Assert.assertEquals("AnXmlFile.xml", noTextFilesList.get(0).getName()); + assertEquals(1, noTextFilesList.size()); + assertEquals("AnXmlFile.xml", noTextFilesList.get(0).getName()); } @Test - public void validateResolveRecursively() { + void validateResolveRecursively() { // Assemble final URL fileFilterDirUrl = getClass().getClassLoader().getResource("testdata/shared/filefilter"); @@ -200,12 +205,12 @@ public void validateResolveRecursively() { final List result = FileSystemUtilities.resolveRecursively(fileList, noTextFilesPattern, log); // Assert - Assert.assertEquals(1, result.size()); - Assert.assertEquals("AnXmlFile.xml", result.get(0).getName()); + assertEquals(1, result.size()); + assertEquals("AnXmlFile.xml", result.get(0).getName()); } @Test - public void validateDefaultExclusionsIncludeDotDirectories() { + void validateDefaultExclusionsIncludeDotDirectories() { // Assemble final URL fileFilterDirUrl = getClass().getClassLoader().getResource("testdata/shared/standard/exclusions"); @@ -225,12 +230,12 @@ public void validateDefaultExclusionsIncludeDotDirectories() { for (File current : result) { builder.append(current.getPath() + ", "); } - Assert.assertEquals(1, result.size()); - Assert.assertEquals("someFile.log", result.get(0).getName()); + assertEquals(1, result.size()); + assertEquals("someFile.log", result.get(0).getName()); } @Test - public void validateResolvingFilesAndRemovingExclusions() { + void validateResolvingFilesAndRemovingExclusions() { // Assemble final URL fileFilterDirUrl = getClass().getClassLoader().getResource("testdata/shared/filefilter"); @@ -254,38 +259,38 @@ public void validateResolvingFilesAndRemovingExclusions() { final List noFilterFiles = FileSystemUtilities.resolveRecursively(fileList, null, log); // Assert - Assert.assertEquals(2, noTextFiles.size()); - Assert.assertEquals(4, noXmlFiles.size()); - Assert.assertEquals(5, allFiles.size()); - Assert.assertEquals(5, noFilterFiles.size()); + assertEquals(2, noTextFiles.size()); + assertEquals(4, noXmlFiles.size()); + assertEquals(5, allFiles.size()); + assertEquals(5, noFilterFiles.size()); final List canonicalPathsForExplicitlyAddedFiles = getRelativeCanonicalPaths(noFilterFiles, depsPropertiesFile.getParentFile()); - Assert.assertTrue(canonicalPathsForExplicitlyAddedFiles.contains("/deps1.properties")); + assertTrue(canonicalPathsForExplicitlyAddedFiles.contains("/deps1.properties")); final List canonicalPathsForNoTextFiles = getRelativeCanonicalPaths(noTextFiles, depsPropertiesFile.getParentFile()); - Assert.assertTrue(canonicalPathsForNoTextFiles.contains("/deps1.properties")); - Assert.assertTrue(canonicalPathsForNoTextFiles.contains("/filefilter/exclusion/AnXmlFile.xml")); + assertTrue(canonicalPathsForNoTextFiles.contains("/deps1.properties")); + assertTrue(canonicalPathsForNoTextFiles.contains("/filefilter/exclusion/AnXmlFile.xml")); final List canonicalPathsForNoXmlFiles = getRelativeCanonicalPaths(noXmlFiles, depsPropertiesFile.getParentFile()); - Assert.assertTrue(canonicalPathsForNoXmlFiles.contains("/deps1.properties")); - Assert.assertTrue(canonicalPathsForNoXmlFiles.contains("/filefilter/exclusion/TextFile.txt")); - Assert.assertTrue(canonicalPathsForNoXmlFiles.contains("/filesystemutilities/TestFile2.txt")); - Assert.assertTrue(canonicalPathsForNoXmlFiles.contains("/filesystemutilities/canonicals/TestFile1.txt")); + assertTrue(canonicalPathsForNoXmlFiles.contains("/deps1.properties")); + assertTrue(canonicalPathsForNoXmlFiles.contains("/filefilter/exclusion/TextFile.txt")); + assertTrue(canonicalPathsForNoXmlFiles.contains("/filesystemutilities/TestFile2.txt")); + assertTrue(canonicalPathsForNoXmlFiles.contains("/filesystemutilities/canonicals/TestFile1.txt")); final List canonicalPathsForAllFiles = getRelativeCanonicalPaths(allFiles, depsPropertiesFile.getParentFile()); - Assert.assertTrue(canonicalPathsForAllFiles.contains("/deps1.properties")); - Assert.assertTrue(canonicalPathsForAllFiles.contains("/filefilter/exclusion/TextFile.txt")); - Assert.assertTrue(canonicalPathsForAllFiles.contains("/filesystemutilities/TestFile2.txt")); - Assert.assertTrue(canonicalPathsForAllFiles.contains("/filesystemutilities/canonicals/TestFile1.txt")); - Assert.assertTrue(canonicalPathsForAllFiles.contains("/filefilter/exclusion/AnXmlFile.xml")); + assertTrue(canonicalPathsForAllFiles.contains("/deps1.properties")); + assertTrue(canonicalPathsForAllFiles.contains("/filefilter/exclusion/TextFile.txt")); + assertTrue(canonicalPathsForAllFiles.contains("/filesystemutilities/TestFile2.txt")); + assertTrue(canonicalPathsForAllFiles.contains("/filesystemutilities/canonicals/TestFile1.txt")); + assertTrue(canonicalPathsForAllFiles.contains("/filefilter/exclusion/AnXmlFile.xml")); } @Test - public void validateBufferingLog() { + void validateBufferingLog() { // Assemble final BufferingLog log = new BufferingLog(BufferingLog.LogLevel.INFO); @@ -300,19 +305,19 @@ public void validateBufferingLog() { final SortedMap logBuffer = log.getLogBuffer(); final List keys = new ArrayList(logBuffer.keySet()); - Assert.assertEquals(3, keys.size()); + assertEquals(3, keys.size()); - Assert.assertEquals("000: (INFO) info", keys.get(0)); - Assert.assertEquals("001: (WARN) warn", keys.get(1)); - Assert.assertEquals("002: (ERROR) ", keys.get(2)); + assertEquals("000: (INFO) info", keys.get(0)); + assertEquals("001: (WARN) warn", keys.get(1)); + assertEquals("002: (ERROR) ", keys.get(2)); - Assert.assertEquals("Blah!", logBuffer.get(keys.get(0)).getMessage()); - Assert.assertNull(logBuffer.get(keys.get(1))); - Assert.assertTrue(logBuffer.get(keys.get(2)) instanceof IllegalArgumentException); + assertEquals("Blah!", logBuffer.get(keys.get(0)).getMessage()); + assertNull(logBuffer.get(keys.get(1))); + assertTrue(logBuffer.get(keys.get(2)) instanceof IllegalArgumentException); } @Test - public void validateFilteringFiles() { + void validateFilteringFiles() { // Assemble final BufferingLog log = new BufferingLog(BufferingLog.LogLevel.DEBUG); @@ -325,14 +330,14 @@ public void validateFilteringFiles() { basedir, null, "filefilter/exclusion", log, "testFiles", excludeTextFiles); // Assert - Assert.assertEquals(1, result.size()); + assertEquals(1, result.size()); final File theFile = result.get(0); - Assert.assertEquals("AnXmlFile.xml", theFile.getName()); + assertEquals("AnXmlFile.xml", theFile.getName()); } @Test - public void validateFilterFilesWithSuppliedSourcesAndExcludePatterns() { + void validateFilterFilesWithSuppliedSourcesAndExcludePatterns() { // Assemble final BufferingLog log = new BufferingLog(BufferingLog.LogLevel.DEBUG); @@ -347,81 +352,81 @@ public void validateFilterFilesWithSuppliedSourcesAndExcludePatterns() { basedir, sources, "filefilter/exclusion", log, "testFiles", excludeTextFiles); // Assert - Assert.assertEquals(1, result.size()); + assertEquals(1, result.size()); final File theFile = result.get(0); - Assert.assertEquals("AnXmlFile.xml", theFile.getName()); + assertEquals("AnXmlFile.xml", theFile.getName()); } @Test - public void validateGettingFileForJar() { + void validateGettingFileForJar() { // Assemble final String jarPath = "testdata/shared/nazgul-tools-validation-aspect-4.0.1.jar"; final URL resource = getClass().getClassLoader().getResource(jarPath); - Assert.assertNotNull(resource); + assertNotNull(resource); // Act final File jarFile = FileSystemUtilities.getFileFor(resource, "UTF-8"); final String relativized = FileSystemUtilities.relativize(jarFile.getPath(), srcTestResources, true); // Assert - Assert.assertTrue(jarFile.exists()); - Assert.assertTrue(jarFile.isFile()); - Assert.assertEquals(jarPath.replace("/", File.separator), relativized); + assertTrue(jarFile.exists()); + assertTrue(jarFile.isFile()); + assertEquals(jarPath.replace("/", File.separator), relativized); } @Test - public void validateGettingFileForClassURL() { + void validateGettingFileForClassURL() { // Assemble final URL streamingDhURL = PropertyResources.class.getProtectionDomain().getCodeSource().getLocation(); - Assert.assertNotNull(streamingDhURL); + assertNotNull(streamingDhURL); // Act final File jarFile = FileSystemUtilities.getFileFor(streamingDhURL, "UTF-8"); // Assert - Assert.assertTrue(jarFile.exists()); - Assert.assertTrue(jarFile.isFile()); + assertTrue(jarFile.exists()); + assertTrue(jarFile.isFile()); } @Test - public void validateGettingFileForClassResourceURL() { + void validateGettingFileForClassResourceURL() { // Assemble final String classResource = PropertyResources.class.getName().replace(".", "/") + ".class"; final URL resource = getClass().getClassLoader().getResource(classResource); - Assert.assertNotNull(resource); + assertNotNull(resource); // Act final File jarFile = FileSystemUtilities.getFileFor(resource, "UTF-8"); // Assert - Assert.assertTrue(jarFile.exists()); - Assert.assertTrue(jarFile.isFile()); + assertTrue(jarFile.exists()); + assertTrue(jarFile.isFile()); } @Test - public void validateUrlEncodingAndDecoding() throws Exception { + void validateUrlEncodingAndDecoding() throws Exception { // Assemble final String resourcePath = "testdata/shared/urlhandling/file with spaces.txt"; final URL dirUrl = getClass().getClassLoader().getResource(resourcePath); - Assert.assertNotNull(dirUrl); + assertNotNull(dirUrl); // Act final String normalizedPath = dirUrl.toURI().normalize().toURL().getPath(); final String decoded = URLDecoder.decode(normalizedPath, "UTF-8"); // Assert - Assert.assertTrue(normalizedPath.endsWith("file%20with%20spaces.txt")); - Assert.assertTrue(decoded.endsWith("file with spaces.txt")); + assertTrue(normalizedPath.endsWith("file%20with%20spaces.txt")); + assertTrue(decoded.endsWith("file with spaces.txt")); } @Test - public void validateRelativizingPaths() throws Exception { + void validateRelativizingPaths() throws Exception { // Assemble final String path = "/project/backend/foobar/my-schema.xsd"; @@ -440,7 +445,7 @@ public void validateRelativizingPaths() throws Exception { final String result = FileSystemUtilities.relativize(path, new File(current.getKey()), true); - Assert.assertEquals(expectedMessage + result, current.getValue(), result); + assertEquals(current.getValue(), result, expectedMessage + result); } } diff --git a/src/test/java/org/codehaus/mojo/jaxb2/shared/ValidateTest.java b/src/test/java/org/codehaus/mojo/jaxb2/shared/ValidateTest.java index 8b07bb67..f0d4446c 100644 --- a/src/test/java/org/codehaus/mojo/jaxb2/shared/ValidateTest.java +++ b/src/test/java/org/codehaus/mojo/jaxb2/shared/ValidateTest.java @@ -1,15 +1,17 @@ package org.codehaus.mojo.jaxb2.shared; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; /** * @author Lennart Jörelid */ -public class ValidateTest { +class ValidateTest { @Test - public void validateErrorMessageOnSuppliedArgumentName() { + void validateErrorMessageOnSuppliedArgumentName() { // Assemble final String argumentName = "fooBar"; @@ -19,27 +21,27 @@ public void validateErrorMessageOnSuppliedArgumentName() { try { Validate.notEmpty("", argumentName); } catch (IllegalArgumentException expected) { - Assert.assertEquals(expectedMsg, expected.getMessage()); + assertEquals(expectedMsg, expected.getMessage()); } catch (Exception e) { - Assert.fail("Expected IllegalArgumentException, but got " + e); + fail("Expected IllegalArgumentException, but got " + e); } } @Test - public void validateErrorMessageOnNullArgumentName() { + void validateErrorMessageOnNullArgumentName() { // Act & Assert try { Validate.notEmpty("", null); } catch (IllegalArgumentException expected) { - Assert.assertEquals("Cannot handle empty argument.", expected.getMessage()); + assertEquals("Cannot handle empty argument.", expected.getMessage()); } catch (Exception e) { - Assert.fail("Expected IllegalArgumentException, but got " + e); + fail("Expected IllegalArgumentException, but got " + e); } } @Test - public void validateErrorMessageOnNullArgument() { + void validateErrorMessageOnNullArgument() { // Assemble final String argumentName = "fooBar"; @@ -49,22 +51,22 @@ public void validateErrorMessageOnNullArgument() { try { Validate.notNull(null, argumentName); } catch (NullPointerException expected) { - Assert.assertEquals(expectedMsg, expected.getMessage()); + assertEquals(expectedMsg, expected.getMessage()); } catch (Exception e) { - Assert.fail("Expected IllegalArgumentException, but got " + e); + fail("Expected IllegalArgumentException, but got " + e); } } @Test - public void validateErrorMessageOnNullArgumentWithNullName() { + void validateErrorMessageOnNullArgumentWithNullName() { // Act & Assert try { Validate.notNull(null, null); } catch (NullPointerException expected) { - Assert.assertEquals("Cannot handle null argument.", expected.getMessage()); + assertEquals("Cannot handle null argument.", expected.getMessage()); } catch (Exception e) { - Assert.fail("Expected IllegalArgumentException, but got " + e); + fail("Expected IllegalArgumentException, but got " + e); } } } diff --git a/src/test/java/org/codehaus/mojo/jaxb2/shared/arguments/ArgumentBuilderTest.java b/src/test/java/org/codehaus/mojo/jaxb2/shared/arguments/ArgumentBuilderTest.java index cd70cf17..4d2b9164 100644 --- a/src/test/java/org/codehaus/mojo/jaxb2/shared/arguments/ArgumentBuilderTest.java +++ b/src/test/java/org/codehaus/mojo/jaxb2/shared/arguments/ArgumentBuilderTest.java @@ -2,56 +2,66 @@ import java.util.Arrays; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; /** * @author Lennart Jörelid */ -public class ArgumentBuilderTest { +class ArgumentBuilderTest { - @Test(expected = IllegalArgumentException.class) - public void validateExceptionOnAddingAllWhitespaceFlag() { + @Test + void validateExceptionOnAddingAllWhitespaceFlag() { + assertThrows(IllegalArgumentException.class, () -> { - // Assemble - final ArgumentBuilder unitUnderTest = new ArgumentBuilder(); + // Assemble + final ArgumentBuilder unitUnderTest = new ArgumentBuilder(); - // Act & Assert - unitUnderTest.withFlag(true, " "); + // Act & Assert + unitUnderTest.withFlag(true, " "); + }); } - @Test(expected = IllegalArgumentException.class) - public void validateExceptionOnAddingFlagContainingWhitespace() { + @Test + void validateExceptionOnAddingFlagContainingWhitespace() { + assertThrows(IllegalArgumentException.class, () -> { - // Assemble - final ArgumentBuilder unitUnderTest = new ArgumentBuilder(); + // Assemble + final ArgumentBuilder unitUnderTest = new ArgumentBuilder(); - // Act & Assert - unitUnderTest.withFlag(true, "foo bar"); + // Act & Assert + unitUnderTest.withFlag(true, "foo bar"); + }); } - @Test(expected = NullPointerException.class) - public void validateExceptionOnAddingNullFlag() { + @Test + void validateExceptionOnAddingNullFlag() { + assertThrows(NullPointerException.class, () -> { - // Assemble - final ArgumentBuilder unitUnderTest = new ArgumentBuilder(); + // Assemble + final ArgumentBuilder unitUnderTest = new ArgumentBuilder(); - // Act & Assert - unitUnderTest.withFlag(true, null); + // Act & Assert + unitUnderTest.withFlag(true, null); + }); } - @Test(expected = NullPointerException.class) - public void validateExceptionOnAddingNullNamedArgument() { + @Test + void validateExceptionOnAddingNullNamedArgument() { + assertThrows(NullPointerException.class, () -> { - // Assemble - final ArgumentBuilder unitUnderTest = new ArgumentBuilder(); + // Assemble + final ArgumentBuilder unitUnderTest = new ArgumentBuilder(); - // Act & Assert - unitUnderTest.withNamedArgument(null, "irrelevant"); + // Act & Assert + unitUnderTest.withNamedArgument(null, "irrelevant"); + }); } @Test - public void validateArgumentOrder() { + void validateArgumentOrder() { // Assemble final ArgumentBuilder unitUnderTest = new ArgumentBuilder(); @@ -61,13 +71,13 @@ public void validateArgumentOrder() { unitUnderTest.withFlag(true, "flag1").withFlag(true, "-flag2").build(); // Assert - Assert.assertEquals(2, result.length); - Assert.assertEquals("-flag1", result[0]); - Assert.assertEquals("-flag2", result[1]); + assertEquals(2, result.length); + assertEquals("-flag1", result[0]); + assertEquals("-flag2", result[1]); } @Test - public void validateMixedArguments() { + void validateMixedArguments() { // Assemble final ArgumentBuilder unitUnderTest = new ArgumentBuilder(); @@ -81,14 +91,14 @@ public void validateMixedArguments() { .build(); // Assert - Assert.assertEquals(3, result.length); - Assert.assertEquals("-name1", result[0]); - Assert.assertEquals("value1", result[1]); - Assert.assertEquals("-flag2", result[2]); + assertEquals(3, result.length); + assertEquals("-name1", result[0]); + assertEquals("value1", result[1]); + assertEquals("-flag2", result[2]); } @Test - public void validatePrefixedArgument() { + void validatePrefixedArgument() { // Assemble final ArgumentBuilder unitUnderTest = new ArgumentBuilder(); @@ -100,10 +110,10 @@ public void validatePrefixedArgument() { .build(); // Assert - Assert.assertEquals(4, result.length); - Assert.assertEquals("-Xplugin1", result[0]); - Assert.assertEquals("-Xplugin2", result[1]); - Assert.assertEquals("-Xplugin3", result[2]); - Assert.assertEquals("-Xplugin4", result[3]); + assertEquals(4, result.length); + assertEquals("-Xplugin1", result[0]); + assertEquals("-Xplugin2", result[1]); + assertEquals("-Xplugin3", result[2]); + assertEquals("-Xplugin4", result[3]); } } diff --git a/src/test/java/org/codehaus/mojo/jaxb2/shared/classloader/ThreadContextClassLoaderBuilderTest.java b/src/test/java/org/codehaus/mojo/jaxb2/shared/classloader/ThreadContextClassLoaderBuilderTest.java index f98e6205..08a0d145 100644 --- a/src/test/java/org/codehaus/mojo/jaxb2/shared/classloader/ThreadContextClassLoaderBuilderTest.java +++ b/src/test/java/org/codehaus/mojo/jaxb2/shared/classloader/ThreadContextClassLoaderBuilderTest.java @@ -11,16 +11,17 @@ import org.codehaus.mojo.jaxb2.shared.JavaVersion; import org.codehaus.mojo.jaxb2.shared.environment.classloading.ThreadContextClassLoaderBuilder; import org.codehaus.mojo.jaxb2.shared.environment.classloading.ThreadContextClassLoaderHolder; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; /** * @author Lennart Jörelid, jGuru Europe AB */ -public class ThreadContextClassLoaderBuilderTest { +class ThreadContextClassLoaderBuilderTest { // Shared state private ThreadContextClassLoaderHolder holder; private URL extraClassLoaderDirURL; @@ -29,24 +30,24 @@ public class ThreadContextClassLoaderBuilderTest { private ClassLoader originalClassLoader; private String encoding = "UTF-8"; - @Before - public void setupSharedState() { + @BeforeEach + void setupSharedState() { log = new BufferingLog(BufferingLog.LogLevel.DEBUG); final String extraPath = "testdata/shared/classloader"; extraClassLoaderDirURL = getClass().getClassLoader().getResource(extraPath); - Assert.assertNotNull(extraClassLoaderDirURL); + assertNotNull(extraClassLoaderDirURL); extraClassLoaderDirFile = new File(extraClassLoaderDirURL.getPath()); - Assert.assertTrue(extraClassLoaderDirFile.exists() && extraClassLoaderDirFile.isDirectory()); + assertTrue(extraClassLoaderDirFile.exists() && extraClassLoaderDirFile.isDirectory()); // Stash the original ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader(); } - @After - public void teardownSharedState() { + @AfterEach + void teardownSharedState() { if (holder != null) { holder.restoreClassLoaderAndReleaseThread(); } else { @@ -55,8 +56,8 @@ public void teardownSharedState() { } @Test - @Ignore - public void validateAddingURLsToThreadContextClassLoader() throws Exception { + @Disabled + void validateAddingURLsToThreadContextClassLoader() throws Exception { // Assemble final int numExpectedResources = JavaVersion.isJdk8OrLower() ? 3 : 6; @@ -95,11 +96,11 @@ public void validateAddingURLsToThreadContextClassLoader() throws Exception { */ // Assert - Assert.assertEquals( - "Expected [" + numExpectedResources + "] resources but got [" + resources.size() + "]: " - + getNewLineSeparated(resources), + assertEquals( numExpectedResources, - resources.size()); + resources.size(), + "Expected [" + numExpectedResources + "] resources but got [" + resources.size() + "]: " + + getNewLineSeparated(resources)); // validateContains(resources, "target/classes"); validateContains(resources, "target/test-classes"); validateContains(resources, "target/test-classes/testdata/shared/classloader"); @@ -109,18 +110,18 @@ public void validateAddingURLsToThreadContextClassLoader() throws Exception { if (current.getProtocol().equalsIgnoreCase("file")) { final File aFile = new File(current.getPath()); - Assert.assertTrue(aFile.exists() && aFile.isDirectory()); + assertTrue(aFile.exists() && aFile.isDirectory()); } else if (current.getProtocol().equalsIgnoreCase("jar")) { // This happens in JDK 9 - Assert.assertTrue(current.toString().contains("!/META-INF/versions/")); + assertTrue(current.toString().contains("!/META-INF/versions/")); } } } @Test - public void validateResourceAccessInAugmentedClassLoader() { + void validateResourceAccessInAugmentedClassLoader() { // Assemble holder = ThreadContextClassLoaderBuilder.createFor(originalClassLoader, log, encoding) @@ -134,18 +135,18 @@ public void validateResourceAccessInAugmentedClassLoader() { final URL subResource = ctxClassLoader.getResource("subdirectory/SubdirectoryTestResource.txt"); // Assert - Assert.assertNotNull(immediateResource); - Assert.assertNotNull(subResource); + assertNotNull(immediateResource); + assertNotNull(subResource); final File immediateFile = new File(immediateResource.getPath()); final File subFile = new File(subResource.getPath()); - Assert.assertTrue(immediateFile.exists() && immediateFile.isFile()); - Assert.assertTrue(subFile.exists() && subFile.isFile()); + assertTrue(immediateFile.exists() && immediateFile.isFile()); + assertTrue(subFile.exists() && subFile.isFile()); } @Test - public void validateLoadingResourcesInJars() { + void validateLoadingResourcesInJars() { // Assemble final File theJar = new File(extraClassLoaderDirFile, "jarSubDirectory/aJarWithResources.jar"); @@ -161,8 +162,8 @@ public void validateLoadingResourcesInJars() { final URL containedSubLevelResource = ctxClassLoader.getResource("internalSubDir/SubContainedResource.txt"); // Assert - Assert.assertNotNull(containedTopLevelResource); - Assert.assertNotNull(containedSubLevelResource); + assertNotNull(containedTopLevelResource); + assertNotNull(containedSubLevelResource); } // @@ -192,6 +193,6 @@ private void validateContains(final List resources, final String snippet) { } } - Assert.fail("Snippet [" + snippet + "] was not found within URL resources."); + fail("Snippet [" + snippet + "] was not found within URL resources."); } } diff --git a/src/test/java/org/codehaus/mojo/jaxb2/shared/environment/locale/LocaleFacetTest.java b/src/test/java/org/codehaus/mojo/jaxb2/shared/environment/locale/LocaleFacetTest.java index 13ddf6e6..9f7b4ed8 100644 --- a/src/test/java/org/codehaus/mojo/jaxb2/shared/environment/locale/LocaleFacetTest.java +++ b/src/test/java/org/codehaus/mojo/jaxb2/shared/environment/locale/LocaleFacetTest.java @@ -7,45 +7,46 @@ import org.apache.maven.plugin.MojoExecutionException; import org.codehaus.mojo.jaxb2.BufferingLog; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; /** * @author Lennart Jörelid, jGuru Europe AB */ -public class LocaleFacetTest { +class LocaleFacetTest { // Shared state private static final Locale FRENCH_LOCALE = Locale.FRENCH; private Locale defaultLocale; private BufferingLog log; - @Before - public void setupSharedState() { + @BeforeEach + void setupSharedState() { this.log = new BufferingLog(BufferingLog.LogLevel.DEBUG); defaultLocale = Locale.getDefault(); } @Test - public void validateLocaleParsing() throws MojoExecutionException { + void validateLocaleParsing() throws MojoExecutionException { // Assemble final String frenchLocaleString = "fr"; // Act & Assert final LocaleFacet facet = LocaleFacet.createFor(frenchLocaleString, log); - Assert.assertEquals(defaultLocale, Locale.getDefault()); + assertEquals(defaultLocale, Locale.getDefault()); facet.setup(); - Assert.assertEquals(FRENCH_LOCALE.toString(), Locale.getDefault().toString()); + assertEquals(FRENCH_LOCALE.toString(), Locale.getDefault().toString()); facet.restore(); - Assert.assertEquals(defaultLocale.toString(), Locale.getDefault().toString()); + assertEquals(defaultLocale.toString(), Locale.getDefault().toString()); } @Test - public void validateOptimalLocaleFindingIgnoringScripts() throws MojoExecutionException { + void validateOptimalLocaleFindingIgnoringScripts() throws MojoExecutionException { // Assemble final SortedMap lang2Locale = new TreeMap(); @@ -63,22 +64,24 @@ public void validateOptimalLocaleFindingIgnoringScripts() throws MojoExecutionEx // Ignore Locales with Scripts. if (script == null) { - Assert.assertSame( + assertSame( Locale.forLanguageTag(current.getValue().toLanguageTag()), LocaleFacet.findOptimumLocale(language, country, variant)); } } } - @Test(expected = MojoExecutionException.class) - public void validateExceptionOnIncorrectLocaleString() throws MojoExecutionException { + @Test + void validateExceptionOnIncorrectLocaleString() throws MojoExecutionException { + assertThrows(MojoExecutionException.class, () -> { - // Act & Assert - LocaleFacet.createFor("not,a,properly,formatted,locale_string", log); + // Act & Assert + LocaleFacet.createFor("not,a,properly,formatted,locale_string", log); + }); } @Test - public void validateNoExceptionOnUnknownLocaleString() throws MojoExecutionException { + void validateNoExceptionOnUnknownLocaleString() throws MojoExecutionException { // Act & Assert LocaleFacet.createFor("thisIsAnUnknownLocale", log); diff --git a/src/test/java/org/codehaus/mojo/jaxb2/shared/environment/sysprops/SystemPropertySaveEnvironmentFacetTest.java b/src/test/java/org/codehaus/mojo/jaxb2/shared/environment/sysprops/SystemPropertySaveEnvironmentFacetTest.java index c89a80e2..57bdeefa 100644 --- a/src/test/java/org/codehaus/mojo/jaxb2/shared/environment/sysprops/SystemPropertySaveEnvironmentFacetTest.java +++ b/src/test/java/org/codehaus/mojo/jaxb2/shared/environment/sysprops/SystemPropertySaveEnvironmentFacetTest.java @@ -1,11 +1,12 @@ package org.codehaus.mojo.jaxb2.shared.environment.sysprops; import org.codehaus.mojo.jaxb2.BufferingLog; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; -public class SystemPropertySaveEnvironmentFacetTest { +class SystemPropertySaveEnvironmentFacetTest { private static final String PROPERTY_KEY_NOT_SAVED = "some.other.property"; private static final String PROPERTY_KEY_SAVED = "http.proxyHost"; @@ -18,7 +19,7 @@ private SystemPropertySaveEnvironmentFacet createAndSetupFacet() { } @Test - public void onRestoreAfterChangeOriginalOtherPropertyValueIsNotRestored() { + void onRestoreAfterChangeOriginalOtherPropertyValueIsNotRestored() { // Given: System.setProperty(PROPERTY_KEY_NOT_SAVED, "originalValue"); final SystemPropertySaveEnvironmentFacet facet = createAndSetupFacet(); @@ -32,7 +33,7 @@ public void onRestoreAfterChangeOriginalOtherPropertyValueIsNotRestored() { } @Test - public void onRestoreAfterChangeOriginalSavedPropertyValueIsRestored() { + void onRestoreAfterChangeOriginalSavedPropertyValueIsRestored() { // Given: System.setProperty(PROPERTY_KEY_SAVED, "originalValue"); final SystemPropertySaveEnvironmentFacet facet = createAndSetupFacet(); @@ -46,7 +47,7 @@ public void onRestoreAfterChangeOriginalSavedPropertyValueIsRestored() { } @Test - public void onRestoreAfterClearOriginalOtherPropertyValueIsNotRestored() { + void onRestoreAfterClearOriginalOtherPropertyValueIsNotRestored() { // Given: System.setProperty(PROPERTY_KEY_NOT_SAVED, "originalValue"); final SystemPropertySaveEnvironmentFacet facet = createAndSetupFacet(); @@ -56,11 +57,11 @@ public void onRestoreAfterClearOriginalOtherPropertyValueIsNotRestored() { facet.restore(); // Then: - assertEquals(null, System.getProperty(PROPERTY_KEY_NOT_SAVED)); + assertNull(System.getProperty(PROPERTY_KEY_NOT_SAVED)); } @Test - public void onRestoreAfterClearOriginalSavedPropertyValueIsRestored() { + void onRestoreAfterClearOriginalSavedPropertyValueIsRestored() { // Given: System.setProperty(PROPERTY_KEY_SAVED, "originalValue"); final SystemPropertySaveEnvironmentFacet facet = createAndSetupFacet(); @@ -74,7 +75,7 @@ public void onRestoreAfterClearOriginalSavedPropertyValueIsRestored() { } @Test - public void onRestoreAfterSetOriginallyUnsetOtherPropertyIsNotCleared() { + void onRestoreAfterSetOriginallyUnsetOtherPropertyIsNotCleared() { // Given: System.clearProperty(PROPERTY_KEY_NOT_SAVED); final SystemPropertySaveEnvironmentFacet facet = createAndSetupFacet(); @@ -88,7 +89,7 @@ public void onRestoreAfterSetOriginallyUnsetOtherPropertyIsNotCleared() { } @Test - public void onRestoreAfterSetOriginallyUnsetSavedPropertyIsCleared() { + void onRestoreAfterSetOriginallyUnsetSavedPropertyIsCleared() { // Given: System.clearProperty(PROPERTY_KEY_SAVED); final SystemPropertySaveEnvironmentFacet facet = createAndSetupFacet(); @@ -98,6 +99,6 @@ public void onRestoreAfterSetOriginallyUnsetSavedPropertyIsCleared() { facet.restore(); // Then: - assertEquals(null, System.getProperty(PROPERTY_KEY_SAVED)); + assertNull(System.getProperty(PROPERTY_KEY_SAVED)); } } diff --git a/src/test/java/org/codehaus/mojo/jaxb2/shared/filters/FiltersTest.java b/src/test/java/org/codehaus/mojo/jaxb2/shared/filters/FiltersTest.java index c46a995d..cf33a920 100644 --- a/src/test/java/org/codehaus/mojo/jaxb2/shared/filters/FiltersTest.java +++ b/src/test/java/org/codehaus/mojo/jaxb2/shared/filters/FiltersTest.java @@ -7,22 +7,24 @@ import org.codehaus.mojo.jaxb2.BufferingLog; import org.codehaus.mojo.jaxb2.shared.filters.pattern.PatternFileFilter; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * @author Lennart Jörelid, jGuru Europe AB */ -public class FiltersTest { +class FiltersTest { // Shared data private File exclusionDir; private File anXmlFile; private File aTextFile; - @Before - public void setupSharedState() { + @BeforeEach + void setupSharedState() { final String dirPath = "testdata/shared/filefilter/exclusion"; final URL resource = getClass().getClassLoader().getResource(dirPath); @@ -32,12 +34,12 @@ public void setupSharedState() { this.anXmlFile = new File(exclusionDir, "AnXmlFile.xml"); this.aTextFile = new File(exclusionDir, "TextFile.txt"); - Assert.assertTrue(anXmlFile.exists() && anXmlFile.isFile()); - Assert.assertTrue(aTextFile.exists() && aTextFile.isFile()); + assertTrue(anXmlFile.exists() && anXmlFile.isFile()); + assertTrue(aTextFile.exists() && aTextFile.isFile()); } @Test - public void validateMatchAtLeastOnce() { + void validateMatchAtLeastOnce() { // Assemble final BufferingLog log = new BufferingLog(BufferingLog.LogLevel.DEBUG); @@ -46,18 +48,18 @@ public void validateMatchAtLeastOnce() { final List> noFilters = new ArrayList>(); // Act & Assert - Assert.assertFalse(Filters.matchAtLeastOnce(anXmlFile, noFilters)); - Assert.assertFalse(Filters.matchAtLeastOnce(aTextFile, noFilters)); + assertFalse(Filters.matchAtLeastOnce(anXmlFile, noFilters)); + assertFalse(Filters.matchAtLeastOnce(aTextFile, noFilters)); - Assert.assertTrue(Filters.matchAtLeastOnce(anXmlFile, excludeFilters)); - Assert.assertFalse(Filters.matchAtLeastOnce(aTextFile, excludeFilters)); + assertTrue(Filters.matchAtLeastOnce(anXmlFile, excludeFilters)); + assertFalse(Filters.matchAtLeastOnce(aTextFile, excludeFilters)); - Assert.assertFalse(Filters.matchAtLeastOnce(anXmlFile, includeFilters)); - Assert.assertTrue(Filters.matchAtLeastOnce(aTextFile, includeFilters)); + assertFalse(Filters.matchAtLeastOnce(anXmlFile, includeFilters)); + assertTrue(Filters.matchAtLeastOnce(aTextFile, includeFilters)); } @Test - public void validateNoMatches() { + void validateNoMatches() { // Assemble final BufferingLog log = new BufferingLog(BufferingLog.LogLevel.DEBUG); @@ -66,18 +68,18 @@ public void validateNoMatches() { final List> noFilters = new ArrayList>(); // Act & Assert - Assert.assertTrue(Filters.noFilterMatches(anXmlFile, noFilters)); - Assert.assertTrue(Filters.noFilterMatches(aTextFile, noFilters)); + assertTrue(Filters.noFilterMatches(anXmlFile, noFilters)); + assertTrue(Filters.noFilterMatches(aTextFile, noFilters)); - Assert.assertFalse(Filters.noFilterMatches(anXmlFile, excludeFilters)); - Assert.assertTrue(Filters.noFilterMatches(aTextFile, excludeFilters)); + assertFalse(Filters.noFilterMatches(anXmlFile, excludeFilters)); + assertTrue(Filters.noFilterMatches(aTextFile, excludeFilters)); - Assert.assertTrue(Filters.noFilterMatches(anXmlFile, includeFilters)); - Assert.assertFalse(Filters.noFilterMatches(aTextFile, includeFilters)); + assertTrue(Filters.noFilterMatches(anXmlFile, includeFilters)); + assertFalse(Filters.noFilterMatches(aTextFile, includeFilters)); } @Test - public void validateRejectIfMatchedAtLeastOnce() { + void validateRejectIfMatchedAtLeastOnce() { // Assemble final BufferingLog log = new BufferingLog(BufferingLog.LogLevel.DEBUG); @@ -86,13 +88,13 @@ public void validateRejectIfMatchedAtLeastOnce() { final List> noFilters = new ArrayList>(); // Act & Assert - Assert.assertFalse(Filters.rejectAtLeastOnce(anXmlFile, noFilters)); - Assert.assertFalse(Filters.rejectAtLeastOnce(aTextFile, noFilters)); + assertFalse(Filters.rejectAtLeastOnce(anXmlFile, noFilters)); + assertFalse(Filters.rejectAtLeastOnce(aTextFile, noFilters)); - Assert.assertFalse(Filters.rejectAtLeastOnce(anXmlFile, excludeFilters)); - Assert.assertTrue(Filters.rejectAtLeastOnce(aTextFile, excludeFilters)); + assertFalse(Filters.rejectAtLeastOnce(anXmlFile, excludeFilters)); + assertTrue(Filters.rejectAtLeastOnce(aTextFile, excludeFilters)); - Assert.assertTrue(Filters.rejectAtLeastOnce(anXmlFile, includeFilters)); - Assert.assertFalse(Filters.rejectAtLeastOnce(aTextFile, includeFilters)); + assertTrue(Filters.rejectAtLeastOnce(anXmlFile, includeFilters)); + assertFalse(Filters.rejectAtLeastOnce(aTextFile, includeFilters)); } } diff --git a/src/test/java/org/codehaus/mojo/jaxb2/shared/filters/PackageFilterInclusionTest.java b/src/test/java/org/codehaus/mojo/jaxb2/shared/filters/PackageFilterInclusionTest.java index a17826c2..2c9800f0 100644 --- a/src/test/java/org/codehaus/mojo/jaxb2/shared/filters/PackageFilterInclusionTest.java +++ b/src/test/java/org/codehaus/mojo/jaxb2/shared/filters/PackageFilterInclusionTest.java @@ -12,16 +12,17 @@ import org.codehaus.mojo.jaxb2.shared.FileSystemUtilities; import org.codehaus.mojo.jaxb2.shared.filters.pattern.FileFilterAdapter; import org.codehaus.mojo.jaxb2.shared.filters.pattern.PatternFileFilter; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import static java.io.File.separator; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * @author Lennart Jörelid, jGuru Europe AB */ -public class PackageFilterInclusionTest { +class PackageFilterInclusionTest { // Shared state private File baseDirectory; @@ -29,8 +30,8 @@ public class PackageFilterInclusionTest { private BufferingLog log; private String contextRoot; - @Before - public void setupSharedState() { + @BeforeEach + void setupSharedState() { log = new BufferingLog(BufferingLog.LogLevel.DEBUG); @@ -46,17 +47,17 @@ public void setupSharedState() { } else { baseDirectory = new File(basedir); } - Assert.assertTrue(baseDirectory.exists() && baseDirectory.isDirectory()); + assertTrue(baseDirectory.exists() && baseDirectory.isDirectory()); // Find all source files under the src/main/java directory. srcMainJavaDir = new File(basedir, "src/main/java"); - Assert.assertTrue(srcMainJavaDir.exists() && srcMainJavaDir.isDirectory()); + assertTrue(srcMainJavaDir.exists() && srcMainJavaDir.isDirectory()); contextRoot = FileSystemUtilities.relativize(srcMainJavaDir.getPath(), baseDirectory, true); } @Test - public void validateExcludingPackageInfoFiles() { + void validateExcludingPackageInfoFiles() { // Assemble final String rootPackagePath = @@ -77,15 +78,15 @@ public void validateExcludingPackageInfoFiles() { ? current.substring(baseDirectory.getPath().length() + 1) : current; - Assert.assertTrue( - "Path " + relativePath + " did not start with the root package path " + rootPackagePath, - relativePath.startsWith(rootPackagePath)); - Assert.assertTrue("Path " + current + " was a package-info.java file.", !current.contains("package-info")); + assertTrue( + relativePath.startsWith(rootPackagePath), + "Path " + relativePath + " did not start with the root package path " + rootPackagePath); + assertFalse(current.contains("package-info"), "Path " + current + " was a package-info.java file."); } } @Test - public void validateIncludingSubTrees() { + void validateIncludingSubTrees() { // Assemble final String locationPackageDirName = separator + "location" + separator; @@ -105,11 +106,11 @@ public boolean accept(final File pathname) { final SortedMap path2FileMap = mapFiles(result); // Assert - Assert.assertTrue(result.size() > 1); + assertTrue(result.size() > 1); for (String current : path2FileMap.keySet()) { - Assert.assertTrue( - "Path " + current + " contained disallowed pattern " + locationPackageDirName, - current.contains(locationPackageDirName)); + assertTrue( + current.contains(locationPackageDirName), + "Path " + current + " contained disallowed pattern " + locationPackageDirName); } } diff --git a/src/test/java/org/codehaus/mojo/jaxb2/shared/filters/T_AbstractFilterTest.java b/src/test/java/org/codehaus/mojo/jaxb2/shared/filters/T_AbstractFilterTest.java index b7427488..0ce7cc40 100644 --- a/src/test/java/org/codehaus/mojo/jaxb2/shared/filters/T_AbstractFilterTest.java +++ b/src/test/java/org/codehaus/mojo/jaxb2/shared/filters/T_AbstractFilterTest.java @@ -3,35 +3,38 @@ import java.util.SortedMap; import org.codehaus.mojo.jaxb2.BufferingLog; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; /** * @author Lennart Jörelid, jGuru Europe AB */ -public class T_AbstractFilterTest { +class T_AbstractFilterTest { // Shared state private BufferingLog log; - @Before - public void setupSharedState() { + @BeforeEach + void setupSharedState() { log = new BufferingLog(); } - @Test(expected = IllegalStateException.class) - public void validateExceptionOnNotInitializingFilterBeforeFirstCall() { + @Test + void validateExceptionOnNotInitializingFilterBeforeFirstCall() { + assertThrows(IllegalStateException.class, () -> { - // Assemble - final DebugFilter unitUnderTest = new DebugFilter(false); + // Assemble + final DebugFilter unitUnderTest = new DebugFilter(false); - // Act & Assert - unitUnderTest.accept("foobar!"); + // Act & Assert + unitUnderTest.accept("foobar!"); + }); } @Test - public void validateCallOrderIfNotProcessingNulls() { + void validateCallOrderIfNotProcessingNulls() { // Assemble final DebugFilter unitUnderTest = new DebugFilter(false); @@ -44,13 +47,13 @@ public void validateCallOrderIfNotProcessingNulls() { // Assert final SortedMap invocations = unitUnderTest.invocations; - Assert.assertEquals(2, invocations.size()); - Assert.assertEquals("first", invocations.get(1)); - Assert.assertEquals("third", invocations.get(2)); + assertEquals(2, invocations.size()); + assertEquals("first", invocations.get(1)); + assertEquals("third", invocations.get(2)); } @Test - public void validateCallOrderIfProcessingNulls() { + void validateCallOrderIfProcessingNulls() { // Assemble final DebugFilter unitUnderTest = new DebugFilter(true); @@ -63,9 +66,9 @@ public void validateCallOrderIfProcessingNulls() { // Assert final SortedMap invocations = unitUnderTest.invocations; - Assert.assertEquals(3, invocations.size()); - Assert.assertEquals("first", invocations.get(1)); - Assert.assertEquals(null, invocations.get(2)); - Assert.assertEquals("third", invocations.get(3)); + assertEquals(3, invocations.size()); + assertEquals("first", invocations.get(1)); + assertNull(invocations.get(2)); + assertEquals("third", invocations.get(3)); } } diff --git a/src/test/java/org/codehaus/mojo/jaxb2/shared/filters/pattern/AbstractPatternFilterTest.java b/src/test/java/org/codehaus/mojo/jaxb2/shared/filters/pattern/AbstractPatternFilterTest.java index 4549d49a..f833d29a 100644 --- a/src/test/java/org/codehaus/mojo/jaxb2/shared/filters/pattern/AbstractPatternFilterTest.java +++ b/src/test/java/org/codehaus/mojo/jaxb2/shared/filters/pattern/AbstractPatternFilterTest.java @@ -7,8 +7,9 @@ import org.codehaus.mojo.jaxb2.BufferingLog; import org.codehaus.mojo.jaxb2.shared.FileSystemUtilities; -import org.junit.Assert; -import org.junit.Before; +import org.junit.jupiter.api.BeforeEach; + +import static org.junit.jupiter.api.Assertions.assertTrue; /** * @author Lennart Jörelid, jGuru Europe AB @@ -29,7 +30,7 @@ public AbstractPatternFilterTest() { this("testdata/shared/filefilter/exclusion"); } - @Before + @BeforeEach @SuppressWarnings("all") public void setupSharedState() { @@ -37,11 +38,11 @@ public void setupSharedState() { final URL exclusionDirUrl = getClass().getClassLoader().getResource(defaultExclusionDirectory); exclusionDirectory = new File(exclusionDirUrl.getPath()); - Assert.assertTrue(FileSystemUtilities.EXISTING_DIRECTORY.accept(exclusionDirectory)); + assertTrue(FileSystemUtilities.EXISTING_DIRECTORY.accept(exclusionDirectory)); fileList = exclusionDirectory.listFiles(); for (File current : fileList) { - Assert.assertTrue(FileSystemUtilities.EXISTING_FILE.accept(current)); + assertTrue(FileSystemUtilities.EXISTING_FILE.accept(current)); } // Delegate diff --git a/src/test/java/org/codehaus/mojo/jaxb2/shared/filters/pattern/PatternFileFilterTest.java b/src/test/java/org/codehaus/mojo/jaxb2/shared/filters/pattern/PatternFileFilterTest.java index 7912fdb7..9d4bb7e5 100644 --- a/src/test/java/org/codehaus/mojo/jaxb2/shared/filters/pattern/PatternFileFilterTest.java +++ b/src/test/java/org/codehaus/mojo/jaxb2/shared/filters/pattern/PatternFileFilterTest.java @@ -5,8 +5,10 @@ import java.util.List; import java.util.Map; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * @author Lennart Jörelid, jGuru Europe AB @@ -29,7 +31,7 @@ public String convert(final File toConvert) { */ @Test - public void validateAcceptNothingOnNullPatterns() { + void validateAcceptNothingOnNullPatterns() { // Assemble final PatternFileFilter unitUnderTest = new PatternFileFilter(null, true); @@ -40,12 +42,12 @@ public void validateAcceptNothingOnNullPatterns() { // Assert for (Map.Entry current : result.entrySet()) { - Assert.assertFalse(current.getValue()); + assertFalse(current.getValue()); } } @Test - public void validateAcceptAllOnNullPatternsForExcludeOperation() { + void validateAcceptAllOnNullPatternsForExcludeOperation() { // Assemble final PatternFileFilter unitUnderTest = new PatternFileFilter(false, null, null, FILENAME_CONVERTER, false); @@ -56,12 +58,12 @@ public void validateAcceptAllOnNullPatternsForExcludeOperation() { // Assert for (Map.Entry current : result.entrySet()) { - Assert.assertTrue(current.getValue()); + assertTrue(current.getValue()); } } @Test - public void validateExcludingMatchingFiles() { + void validateExcludingMatchingFiles() { // Assemble final List txtFileSuffixExclusion = Arrays.asList("\\.txt"); @@ -72,12 +74,12 @@ public void validateExcludingMatchingFiles() { final Map result = applyFilterAndRetrieveResults(unitUnderTest, fileList, FILENAME_CONVERTER); // Assert - Assert.assertTrue(result.get("AnXmlFile.xml")); - Assert.assertFalse(result.get("TextFile.txt")); + assertTrue(result.get("AnXmlFile.xml")); + assertFalse(result.get("TextFile.txt")); } @Test - public void validateExcludingNoFilesOnNonMatchingPattern() { + void validateExcludingNoFilesOnNonMatchingPattern() { // Assemble final PatternFileFilter unitUnderTest = new PatternFileFilter(Arrays.asList("\\.nonexistent"), false); @@ -87,12 +89,12 @@ public void validateExcludingNoFilesOnNonMatchingPattern() { final Map result = applyFilterAndRetrieveResults(unitUnderTest, fileList, FILENAME_CONVERTER); // Assert - Assert.assertTrue(result.get("AnXmlFile.xml")); - Assert.assertTrue(result.get("TextFile.txt")); + assertTrue(result.get("AnXmlFile.xml")); + assertTrue(result.get("TextFile.txt")); } @Test - public void validatePatternMatchExclusion() { + void validatePatternMatchExclusion() { // Assemble final PatternFileFilter unitUnderTest = new PatternFileFilter(Arrays.asList("\\.*File\\..*"), false); @@ -102,7 +104,7 @@ public void validatePatternMatchExclusion() { final Map result = applyFilterAndRetrieveResults(unitUnderTest, fileList, FILENAME_CONVERTER); // Assert - Assert.assertFalse(result.get("AnXmlFile.xml")); - Assert.assertFalse(result.get("TextFile.txt")); + assertFalse(result.get("AnXmlFile.xml")); + assertFalse(result.get("TextFile.txt")); } } diff --git a/src/test/java/org/codehaus/mojo/jaxb2/shared/filters/pattern/PatternURLFilterTest.java b/src/test/java/org/codehaus/mojo/jaxb2/shared/filters/pattern/PatternURLFilterTest.java index 62204425..46e99965 100644 --- a/src/test/java/org/codehaus/mojo/jaxb2/shared/filters/pattern/PatternURLFilterTest.java +++ b/src/test/java/org/codehaus/mojo/jaxb2/shared/filters/pattern/PatternURLFilterTest.java @@ -7,13 +7,14 @@ import java.util.Map; import org.codehaus.mojo.jaxb2.shared.FileSystemUtilities; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; /** * @author Lennart Jörelid, jGuru Europe AB */ -public class PatternURLFilterTest extends AbstractPatternFilterTest { +class PatternURLFilterTest extends AbstractPatternFilterTest { // Shared state private URL[] urlList; @@ -27,7 +28,7 @@ protected void onSetup() { urlList = new URL[fileList.length]; for (int i = 0; i < fileList.length; i++) { - Assert.assertTrue(FileSystemUtilities.EXISTING_FILE.accept(fileList[i])); + assertTrue(FileSystemUtilities.EXISTING_FILE.accept(fileList[i])); try { urlList[i] = fileList[i].toURI().normalize().toURL(); } catch (MalformedURLException e) { @@ -36,18 +37,20 @@ protected void onSetup() { } } - @Test(expected = IllegalStateException.class) - public void validateExceptionOnNotInitializingFilterBeforeUse() { + @Test + void validateExceptionOnNotInitializingFilterBeforeUse() { + assertThrows(IllegalStateException.class, () -> { - // Assemble - final PatternURLFilter unitUnderTest = new PatternURLFilter(null); + // Assemble + final PatternURLFilter unitUnderTest = new PatternURLFilter(null); - // Act & Assert - unitUnderTest.accept(urlList[0]); + // Act & Assert + unitUnderTest.accept(urlList[0]); + }); } @Test - public void validateAcceptNothingOnNullPatterns() { + void validateAcceptNothingOnNullPatterns() { // Assemble final PatternURLFilter unitUnderTest = new PatternURLFilter(null); @@ -59,12 +62,12 @@ public void validateAcceptNothingOnNullPatterns() { // Assert for (Map.Entry current : result.entrySet()) { - Assert.assertFalse(current.getValue()); + assertFalse(current.getValue()); } } @Test - public void validateExcludingMatchingURLs() { + void validateExcludingMatchingURLs() { // Assemble final String urlProtocol = "file"; @@ -81,9 +84,9 @@ public void validateExcludingMatchingURLs() { // Assert for (Map.Entry current : result.entrySet()) { if (current.getKey().endsWith("xml")) { - Assert.assertTrue(result.get(current.getKey())); + assertTrue(result.get(current.getKey())); } else { - Assert.assertFalse(result.get(current.getKey())); + assertFalse(result.get(current.getKey())); } } } diff --git a/src/test/java/org/codehaus/mojo/jaxb2/shared/filters/pattern/T_AbstractPatternFilterTest.java b/src/test/java/org/codehaus/mojo/jaxb2/shared/filters/pattern/T_AbstractPatternFilterTest.java index 980b03e9..0664b50b 100644 --- a/src/test/java/org/codehaus/mojo/jaxb2/shared/filters/pattern/T_AbstractPatternFilterTest.java +++ b/src/test/java/org/codehaus/mojo/jaxb2/shared/filters/pattern/T_AbstractPatternFilterTest.java @@ -5,14 +5,15 @@ import java.util.SortedMap; import org.codehaus.mojo.jaxb2.BufferingLog; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; /** * @author Lennart Jörelid, jGuru Europe AB */ -public class T_AbstractPatternFilterTest { +class T_AbstractPatternFilterTest { private static final StringConverter UNITY_STRING_CONVERTER = new StringConverter() { @Override @@ -24,25 +25,27 @@ public String convert(final String toConvert) { // Shared state private BufferingLog log; - @Before - public void setupSharedState() { + @BeforeEach + void setupSharedState() { log = new BufferingLog(BufferingLog.LogLevel.DEBUG); } - @Test(expected = NullPointerException.class) - public void validateExceptionOnNullStringConverter() { + @Test + void validateExceptionOnNullStringConverter() { + assertThrows(NullPointerException.class, () -> { - // Assemble - final boolean processNullValues = false; - final List patterns = null; - final boolean acceptCandidateOnPatternMatch = true; + // Assemble + final boolean processNullValues = false; + final List patterns = null; + final boolean acceptCandidateOnPatternMatch = true; - // Act & Assert - new DebugPatternFilter(processNullValues, patterns, null, acceptCandidateOnPatternMatch); + // Act & Assert + new DebugPatternFilter(processNullValues, patterns, null, acceptCandidateOnPatternMatch); + }); } @Test - public void validateNoAcceptedResultsWhenProcessingMessagesOnNullFilters() { + void validateNoAcceptedResultsWhenProcessingMessagesOnNullFilters() { // Assemble final boolean processNullValues = false; @@ -60,15 +63,15 @@ public void validateNoAcceptedResultsWhenProcessingMessagesOnNullFilters() { // Assert final SortedMap invocations = unitUnderTest.invocations; - Assert.assertEquals(2, invocations.size()); - Assert.assertEquals("first", invocations.get(1)[0]); - Assert.assertEquals(false, Boolean.parseBoolean(invocations.get(1)[1])); - Assert.assertEquals("third", invocations.get(2)[0]); - Assert.assertEquals(false, Boolean.parseBoolean(invocations.get(2)[1])); + assertEquals(2, invocations.size()); + assertEquals("first", invocations.get(1)[0]); + assertFalse(Boolean.parseBoolean(invocations.get(1)[1])); + assertEquals("third", invocations.get(2)[0]); + assertFalse(Boolean.parseBoolean(invocations.get(2)[1])); } @Test - public void validateAcceptingFilterMessages() { + void validateAcceptingFilterMessages() { // Assemble final boolean processNullValues = false; @@ -86,10 +89,10 @@ public void validateAcceptingFilterMessages() { // Assert final SortedMap invocations = unitUnderTest.invocations; - Assert.assertEquals(2, invocations.size()); - Assert.assertEquals("first", invocations.get(1)[0]); - Assert.assertEquals(true, Boolean.parseBoolean(invocations.get(1)[1])); - Assert.assertEquals("third", invocations.get(2)[0]); - Assert.assertEquals(false, Boolean.parseBoolean(invocations.get(2)[1])); + assertEquals(2, invocations.size()); + assertEquals("first", invocations.get(1)[0]); + assertTrue(Boolean.parseBoolean(invocations.get(1)[1])); + assertEquals("third", invocations.get(2)[0]); + assertFalse(Boolean.parseBoolean(invocations.get(2)[1])); } } diff --git a/src/test/java/org/codehaus/mojo/jaxb2/shared/version/DependencyFileParserTest.java b/src/test/java/org/codehaus/mojo/jaxb2/shared/version/DependencyFileParserTest.java index 80c7962d..4cccc9dd 100644 --- a/src/test/java/org/codehaus/mojo/jaxb2/shared/version/DependencyFileParserTest.java +++ b/src/test/java/org/codehaus/mojo/jaxb2/shared/version/DependencyFileParserTest.java @@ -6,23 +6,24 @@ import java.util.List; import java.util.SortedMap; -import org.junit.After; -import org.junit.Assert; -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 static org.junit.jupiter.api.Assertions.*; /** * @author Lennart Jörelid */ -public class DependencyFileParserTest { +class DependencyFileParserTest { // Internal state private URL urlToTestJar; private static final String DEPS1_PROPERTYFILE = "/testdata/shared/deps1.properties"; private ClassLoader originalThreadContextClassLoader; - @Before - public void setupSharedState() throws Exception { + @BeforeEach + void setupSharedState() throws Exception { // Stash the original ClassLoader originalThreadContextClassLoader = Thread.currentThread().getContextClassLoader(); @@ -30,19 +31,19 @@ public void setupSharedState() throws Exception { // Add the local test JAR to the ClassLoader path final String jarPath = "testdata/shared/nazgul-tools-validation-aspect-4.0.1.jar"; final URL extraURL = getClass().getClassLoader().getResource(jarPath); - Assert.assertNotNull("No resource found for path [" + jarPath + "]", extraURL); + assertNotNull(extraURL, "No resource found for path [" + jarPath + "]"); final URLClassLoader decoratedClassLoader = new URLClassLoader(new URL[] {extraURL}, originalThreadContextClassLoader); - Assert.assertNotNull("Could not create decorated ClassLoader", decoratedClassLoader); + assertNotNull(decoratedClassLoader, "Could not create decorated ClassLoader"); Thread.currentThread().setContextClassLoader(decoratedClassLoader); // Assert that the decorated ClassLoader can load resource within the extraURL JAR. final String internalResourcePath = "META-INF/maven/se.jguru.nazgul.tools.validation.aspect/" + "nazgul-tools-validation-aspect/pom.properties"; final List resourceList = Collections.list(decoratedClassLoader.getResources(internalResourcePath)); - Assert.assertNotNull(resourceList); - Assert.assertNotEquals(0, resourceList.size()); + assertNotNull(resourceList); + assertNotEquals(0, resourceList.size()); for (URL current : resourceList) { if (current.getPath().contains("testdata")) { @@ -50,19 +51,19 @@ public void setupSharedState() throws Exception { break; } } - Assert.assertNotNull( - "Expected resource not found for internal resource path [" + internalResourcePath + "] ", urlToTestJar); + assertNotNull( + urlToTestJar, "Expected resource not found for internal resource path [" + internalResourcePath + "] "); } - @After - public void teardownSharedState() { + @AfterEach + void teardownSharedState() { // Restore the original ClassLoader Thread.currentThread().setContextClassLoader(originalThreadContextClassLoader); } @Test - public void validateParsingDependencyPropertiesFile() { + void validateParsingDependencyPropertiesFile() { // Assemble final URL depsPropResource = getClass().getResource(DEPS1_PROPERTYFILE); @@ -71,10 +72,10 @@ public void validateParsingDependencyPropertiesFile() { final SortedMap versionMap = DependsFileParser.getVersionMap(depsPropResource); // Assert - Assert.assertEquals("Wed Nov 19 20:11:15 CET 2014", versionMap.get(DependsFileParser.BUILDTIME_KEY)); - Assert.assertEquals("compile", versionMap.get("jakarta.xml.bind/jaxb-api/scope")); - Assert.assertEquals("jar", versionMap.get("jakarta.xml.bind/jaxb-api/type")); - Assert.assertEquals("3.0.0", versionMap.get("jakarta.xml.bind/jaxb-api/version")); + assertEquals("Wed Nov 19 20:11:15 CET 2014", versionMap.get(DependsFileParser.BUILDTIME_KEY)); + assertEquals("compile", versionMap.get("jakarta.xml.bind/jaxb-api/scope")); + assertEquals("jar", versionMap.get("jakarta.xml.bind/jaxb-api/type")); + assertEquals("3.0.0", versionMap.get("jakarta.xml.bind/jaxb-api/version")); /* for(Map.Entry current : versionMap.entrySet()) { @@ -84,7 +85,7 @@ public void validateParsingDependencyPropertiesFile() { } @Test - public void validateCreatingDependencyInformationMapFromDependencyPropertiesFile() { + void validateCreatingDependencyInformationMapFromDependencyPropertiesFile() { // Assemble final String jaxbApiKey = "jakarta.xml.bind/jaxb-api"; @@ -96,13 +97,13 @@ public void validateCreatingDependencyInformationMapFromDependencyPropertiesFile // Assert final DependencyInfo dependencyInfo = diMap.get(jaxbApiKey); - Assert.assertNotNull(dependencyInfo); + assertNotNull(dependencyInfo); - Assert.assertEquals("jakarta.xml.bind", dependencyInfo.getGroupId()); - Assert.assertEquals("jaxb-api", dependencyInfo.getArtifactId()); - Assert.assertEquals("3.0.0", dependencyInfo.getVersion()); - Assert.assertEquals("jar", dependencyInfo.getType()); - Assert.assertEquals("compile", dependencyInfo.getScope()); + assertEquals("jakarta.xml.bind", dependencyInfo.getGroupId()); + assertEquals("jaxb-api", dependencyInfo.getArtifactId()); + assertEquals("3.0.0", dependencyInfo.getVersion()); + assertEquals("jar", dependencyInfo.getType()); + assertEquals("compile", dependencyInfo.getScope()); /* for(Map.Entry current : diMap.entrySet()) { @@ -112,7 +113,7 @@ public void validateCreatingDependencyInformationMapFromDependencyPropertiesFile } @Test - public void validateParsingDependencyInformationPackagedInJarFileInClassPath() { + void validateParsingDependencyInformationPackagedInJarFileInClassPath() { // Assemble final String artifactId = "nazgul-tools-validation-aspect"; @@ -124,19 +125,19 @@ public void validateParsingDependencyInformationPackagedInJarFileInClassPath() { final SortedMap diMap = DependsFileParser.createDependencyInfoMap(versionMap); // Assert - Assert.assertEquals("Mon Oct 06 07:51:23 CEST 2014", versionMap.get(DependsFileParser.BUILDTIME_KEY)); - Assert.assertEquals(groupId, versionMap.get(DependsFileParser.OWN_GROUPID_KEY)); - Assert.assertEquals(artifactId, versionMap.get(DependsFileParser.OWN_ARTIFACTID_KEY)); - Assert.assertEquals("4.0.1", versionMap.get(DependsFileParser.OWN_VERSION_KEY)); + assertEquals("Mon Oct 06 07:51:23 CEST 2014", versionMap.get(DependsFileParser.BUILDTIME_KEY)); + assertEquals(groupId, versionMap.get(DependsFileParser.OWN_GROUPID_KEY)); + assertEquals(artifactId, versionMap.get(DependsFileParser.OWN_ARTIFACTID_KEY)); + assertEquals("4.0.1", versionMap.get(DependsFileParser.OWN_VERSION_KEY)); final DependencyInfo dependencyInfo = diMap.get(slf4jApiKey); - Assert.assertNotNull(dependencyInfo); + assertNotNull(dependencyInfo); - Assert.assertEquals("org.slf4j", dependencyInfo.getGroupId()); - Assert.assertEquals("slf4j-api", dependencyInfo.getArtifactId()); - Assert.assertEquals("1.7.7", dependencyInfo.getVersion()); - Assert.assertEquals("jar", dependencyInfo.getType()); - Assert.assertEquals("compile", dependencyInfo.getScope()); + assertEquals("org.slf4j", dependencyInfo.getGroupId()); + assertEquals("slf4j-api", dependencyInfo.getArtifactId()); + assertEquals("1.7.7", dependencyInfo.getVersion()); + assertEquals("jar", dependencyInfo.getType()); + assertEquals("compile", dependencyInfo.getScope()); /* for(Map.Entry current : diMap.entrySet()) { @@ -145,15 +146,17 @@ public void validateParsingDependencyInformationPackagedInJarFileInClassPath() { */ } - @Test(expected = IllegalArgumentException.class) - public void validateExceptionOnAttemptingToParseIncorrectlyFormedPropertiesFile() { + @Test + void validateExceptionOnAttemptingToParseIncorrectlyFormedPropertiesFile() { + assertThrows(IllegalArgumentException.class, () -> { - // Assemble - final String resourcePath = "testdata/shared/not_a_dependency.properties"; - final URL incorrectResource = - Thread.currentThread().getContextClassLoader().getResource(resourcePath); + // Assemble + final String resourcePath = "testdata/shared/not_a_dependency.properties"; + final URL incorrectResource = + Thread.currentThread().getContextClassLoader().getResource(resourcePath); - // Act & Assert - DependsFileParser.getVersionMap(incorrectResource); + // Act & Assert + DependsFileParser.getVersionMap(incorrectResource); + }); } }