This is an automated email from the ASF dual-hosted git repository. pottlinger pushed a commit to branch rewriteTests in repository https://gitbox.apache.org/repos/asf/creadur-whisker.git
commit 730c2ceab53f749f09c3b02653805036c9220fb6 Author: P. Ottlinger <[email protected]> AuthorDate: Thu May 1 23:56:58 2025 +0200 WHISKER-30: Rewrite run with first manual changes --- apache-whisker-app/pom.xml | 5 - .../whisker/app/TestConfigurationBuilder.java | 22 ++- .../apache/creadur/whisker/app/TestWhisker.java | 25 +-- .../app/load/TestStreamableResourceFactory.java | 21 ++- apache-whisker-cli/pom.xml | 5 - .../creadur/whisker/cli/TestCommandParsing.java | 59 ++++--- .../org/apache/creadur/whisker/cli/TestMain.java | 26 +-- apache-whisker-maven-plugin/pom.xml | 5 - .../apache/creadur/whisker/it/TestAllCheck.java | 35 ++-- .../apache/creadur/whisker/it/TestAnyCheck.java | 35 ++-- .../whisker/it/TestNoLineContainsCheck.java | 22 ++- apache-whisker-model/pom.xml | 5 - .../whisker/model/TestDescriptorOnlyPrimary.java | 23 ++- .../whisker/model/TestDescriptorPrimaryOnly.java | 36 ++-- ...scriptorRequiredNoticesNoThirdPartyNotices.java | 45 +++-- ...quiredNoticesWithRequiredThirdPartyNotices.java | 46 ++--- ...redNoticesWithThirdPartyNoticesButNoneUsed.java | 47 +++--- .../model/TestNoCopyrightNoticeVerifier.java | 17 +- .../creadur/whisker/model/TestWithLicense.java | 18 +- apache-whisker-scan/pom.xml | 7 - apache-whisker-velocity/pom.xml | 5 - .../out/velocity/TestLicenseGeneration.java | 82 ++++----- .../velocity/TestLicenseGenerationSourceURLs.java | 28 ++-- .../whisker/out/velocity/TestNoticeGeneration.java | 30 ++-- .../whisker/out/velocity/TestRenderingHelper.java | 24 +-- apache-whisker-xml/pom.xml | 5 - .../fromxml/JDomBuilderByOrganisationTest.java | 143 +++++++++------- .../whisker/fromxml/JDomBuilderLicenseTest.java | 114 +++++++------ .../fromxml/JDomBuilderOrganisationTest.java | 31 ++-- .../whisker/fromxml/JDomBuilderResourceTest.java | 54 +++--- .../fromxml/JDomBuilderWithDirectoryTest.java | 61 ++++--- .../fromxml/JDomBuilderWithLicenseTest.java | 126 ++++++++------ .../whisker/fromxml/JDomBuilderWorkTest.java | 186 ++++++++++++--------- pom.xml | 30 ++++ 34 files changed, 823 insertions(+), 600 deletions(-) diff --git a/apache-whisker-app/pom.xml b/apache-whisker-app/pom.xml index 30e3489..cb5f34d 100644 --- a/apache-whisker-app/pom.xml +++ b/apache-whisker-app/pom.xml @@ -35,11 +35,6 @@ <groupId>commons-io</groupId> <artifactId>commons-io</artifactId> </dependency> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <scope>test</scope> - </dependency> <dependency> <groupId>${project.groupId}</groupId> <artifactId>apache-whisker-scan</artifactId> diff --git a/apache-whisker-app/src/test/java/org/apache/creadur/whisker/app/TestConfigurationBuilder.java b/apache-whisker-app/src/test/java/org/apache/creadur/whisker/app/TestConfigurationBuilder.java index a5e03a3..5d99360 100644 --- a/apache-whisker-app/src/test/java/org/apache/creadur/whisker/app/TestConfigurationBuilder.java +++ b/apache-whisker-app/src/test/java/org/apache/creadur/whisker/app/TestConfigurationBuilder.java @@ -18,29 +18,35 @@ */ package org.apache.creadur.whisker.app; -import junit.framework.TestCase; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; -public class TestConfigurationBuilder extends TestCase { +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +class TestConfigurationBuilder { ConfigurationBuilder subject; - @Override - protected void setUp() throws Exception { - super.setUp(); + @BeforeEach + void setUp() throws Exception { subject = ConfigurationBuilder.aConfiguration(); } - public void testWithNoSourceURLsInLicense() { + @Test + void withNoSourceURLsInLicense() { assertFalse(subject.noSourceURLsInLicense().build().includeSourceURLsInLicense()); } - public void testSourceURLsInLicenseDefault() { + @Test + void sourceURLsInLicenseDefault() { assertTrue(subject.withSourceURLsInLicense().build().includeSourceURLsInLicense()); } - public void testWithSourceURLsInLicense() { + @Test + void withSourceURLsInLicense() { assertTrue(subject.withSourceURLsInLicense().build().includeSourceURLsInLicense()); } diff --git a/apache-whisker-app/src/test/java/org/apache/creadur/whisker/app/TestWhisker.java b/apache-whisker-app/src/test/java/org/apache/creadur/whisker/app/TestWhisker.java index 756cfa5..5a9dca8 100644 --- a/apache-whisker-app/src/test/java/org/apache/creadur/whisker/app/TestWhisker.java +++ b/apache-whisker-app/src/test/java/org/apache/creadur/whisker/app/TestWhisker.java @@ -18,32 +18,37 @@ */ package org.apache.creadur.whisker.app; -import junit.framework.TestCase; +import static org.junit.jupiter.api.Assertions.*; -public class TestWhisker extends TestCase { +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +class TestWhisker { Whisker subject; - @Override - protected void setUp() throws Exception { - super.setUp(); + @BeforeEach + void setUp() throws Exception { subject = new Whisker(); } - public void testSetNullLicenseConfiguration() { + @Test + void setNullLicenseConfiguration() { assertEquals( - subject.setLicenseConfiguration(null).getLicenseConfiguration(), - LicenseConfiguration.DEFAULT_LICENSE_CONFIGURATION); + LicenseConfiguration.DEFAULT_LICENSE_CONFIGURATION, + subject.setLicenseConfiguration(null).getLicenseConfiguration()); } - public void testMinimalLicenseConfigurationConfiguresNoSourceUrls() { + @Test + void minimalLicenseConfigurationConfiguresNoSourceUrls() { assertFalse( subject .setLicenseConfiguration(LicenseConfiguration.MINIMAL) .configuration().includeSourceURLsInLicense()); } - public void testIncludeSourceUrlsLicenseConfigurationConfiguresNoSourceUrls() { + @Test + void includeSourceUrlsLicenseConfigurationConfiguresNoSourceUrls() { assertTrue( subject .setLicenseConfiguration(LicenseConfiguration.INCLUDE_SOURCE_URLS) diff --git a/apache-whisker-app/src/test/java/org/apache/creadur/whisker/app/load/TestStreamableResourceFactory.java b/apache-whisker-app/src/test/java/org/apache/creadur/whisker/app/load/TestStreamableResourceFactory.java index 56ffcaa..10516c4 100644 --- a/apache-whisker-app/src/test/java/org/apache/creadur/whisker/app/load/TestStreamableResourceFactory.java +++ b/apache-whisker-app/src/test/java/org/apache/creadur/whisker/app/load/TestStreamableResourceFactory.java @@ -21,23 +21,26 @@ package org.apache.creadur.whisker.app.load; import java.io.InputStream; import org.apache.creadur.whisker.app.StreamableResource; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -import junit.framework.TestCase; +import static org.junit.jupiter.api.Assertions.*; -public class TestStreamableResourceFactory extends TestCase { +class TestStreamableResourceFactory { StreamableResourceFactory subject; - @Override - protected void setUp() throws Exception { - super.setUp(); + @BeforeEach + void setUp() throws Exception { subject = new StreamableResourceFactory(); } - public void testWhenResourceExistsOnClasspathThisResourceShouldBeStreamed() throws Exception { - StreamableResource streamableResource = subject.streamFromResource("junit/framework/TestCase.class"); + @Test + void whenResourceExistsOnClasspathThisResourceShouldBeStreamed() throws Exception { + StreamableResource streamableResource = subject.streamFromResource("org/junit/jupiter/api/Test.class"); assertNotNull(streamableResource); - InputStream in = streamableResource.open(); - assertFalse(in.read() == -1); + try(InputStream in = streamableResource.open()) { + assertNotEquals(-1, in.read()); + }; } } diff --git a/apache-whisker-cli/pom.xml b/apache-whisker-cli/pom.xml index eca1daa..771b248 100644 --- a/apache-whisker-cli/pom.xml +++ b/apache-whisker-cli/pom.xml @@ -35,11 +35,6 @@ <groupId>commons-cli</groupId> <artifactId>commons-cli</artifactId> </dependency> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <scope>test</scope> - </dependency> <dependency> <groupId>${project.groupId}</groupId> <artifactId>apache-whisker-scan</artifactId> diff --git a/apache-whisker-cli/src/test/java/org/apache/creadur/whisker/cli/TestCommandParsing.java b/apache-whisker-cli/src/test/java/org/apache/creadur/whisker/cli/TestCommandParsing.java index a827e96..ade8630 100644 --- a/apache-whisker-cli/src/test/java/org/apache/creadur/whisker/cli/TestCommandParsing.java +++ b/apache-whisker-cli/src/test/java/org/apache/creadur/whisker/cli/TestCommandParsing.java @@ -18,7 +18,8 @@ */ package org.apache.creadur.whisker.cli; -import junit.framework.TestCase; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; import org.apache.commons.cli.AlreadySelectedException; import org.apache.commons.cli.ParseException; @@ -27,19 +28,22 @@ import org.apache.creadur.whisker.app.StreamableResource; import org.apache.creadur.whisker.app.Whisker; import org.apache.creadur.whisker.app.load.StreamableClassPathResource; import org.apache.creadur.whisker.app.load.StreamableFileNameResource; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -public class TestCommandParsing extends TestCase { +class TestCommandParsing { private static final String LONG_OPT = "--"; private static final String SHORT_OPT = "-"; private Main subject; - @Override - protected void setUp() throws Exception { + @BeforeEach + void setUp() throws Exception { subject = new Main(new Whisker()); } - public void testGenerateAndAuditAreMutuallyExclusive() throws Exception { + @Test + void generateAndAuditAreMutuallyExclusive() throws Exception { try { subject.configure( args(longOpt(CommandLineOption.LICENSE_DESCRIPTION.getLongName()), "PATH", @@ -52,7 +56,8 @@ public class TestCommandParsing extends TestCase { } } - public void testGenerateAndSkeletonAreMutuallyExclusive() throws Exception { + @Test + void generateAndSkeletonAreMutuallyExclusive() throws Exception { try { subject.configure( args(longOpt(CommandLineOption.LICENSE_DESCRIPTION.getLongName()), "PATH", @@ -65,7 +70,8 @@ public class TestCommandParsing extends TestCase { } } - public void testSkeletonAndAuditAreMutuallyExclusive() throws Exception { + @Test + void skeletonAndAuditAreMutuallyExclusive() throws Exception { try { subject.configure( args(longOpt(CommandLineOption.LICENSE_DESCRIPTION.getLongName()), "PATH", @@ -79,15 +85,18 @@ public class TestCommandParsing extends TestCase { } - public void testSetGenerateAct() throws Exception { + @Test + void setGenerateAct() throws Exception { checkSetActForOption(Act.GENERATE, CommandLineOption.ACT_TO_GENERATE); } - public void testSetAuditAct() throws Exception { + @Test + void setAuditAct() throws Exception { checkSetActForOption(Act.AUDIT, CommandLineOption.ACT_TO_AUDIT); } - public void testSetSkeletonAct() throws Exception { + @Test + void setSkeletonAct() throws Exception { checkSetActForOption(Act.SKELETON, CommandLineOption.ACT_TO_SKELETON); } @@ -99,21 +108,23 @@ public class TestCommandParsing extends TestCase { */ private void checkSetActForOption(Act act, CommandLineOption option) throws ParseException { - assertEquals(act + " arg should set property on Whisker", act, subject.configure( + assertEquals(act, subject.configure( args(longOpt(CommandLineOption.LICENSE_DESCRIPTION.getLongName()), "PATH", - shortOpt(CommandLineOption.SOURCE.getShortName()), "path", longOpt(option.getLongName()))).getAct()); - assertEquals(act + "Audit arg should set property on Whisker", act, subject.configure( + shortOpt(CommandLineOption.SOURCE.getShortName()), "path", longOpt(option.getLongName()))).getAct(), act + " arg should set property on Whisker"); + assertEquals(act, subject.configure( args(longOpt(CommandLineOption.LICENSE_DESCRIPTION.getLongName()), "PATH", - shortOpt(CommandLineOption.SOURCE.getShortName()), "path", shortOpt(option.getShortName()))).getAct()); + shortOpt(CommandLineOption.SOURCE.getShortName()), "path", shortOpt(option.getShortName()))).getAct(), act + "Audit arg should set property on Whisker"); } - public void testSetSourceByCli() throws Exception { + @Test + void setSourceByCli() throws Exception { checkSourceWithPath("/some/path"); checkSourceWithPath("/"); checkSourceWithPath("relative"); } - public void testAuditRequiresSource() throws Exception { + @Test + void auditRequiresSource() throws Exception { try { subject.configure(args( longOpt(CommandLineOption.ACT_TO_AUDIT.getLongName()), @@ -134,14 +145,16 @@ public class TestCommandParsing extends TestCase { private void checkSource(String aPath, String arg) throws ParseException { - assertEquals("Source arg should set property on Whisker", aPath, + assertEquals(aPath, subject.configure(args(arg, aPath, longOpt(CommandLineOption.ACT_TO_AUDIT.getLongName()), - shortOpt(CommandLineOption.LICENSE_DESCRIPTION.getShortName()), "Whatever/bin")).getSource()); + shortOpt(CommandLineOption.LICENSE_DESCRIPTION.getShortName()), "Whatever/bin")).getSource(), + "Source arg should set property on Whisker"); } - public void testSetLicenseDescriptorShortByCLI() throws Exception { + @Test + void setLicenseDescriptorShortByCLI() throws Exception { exerciseShortLicenseDescriptionWithPath("/some/path"); exerciseShortLicenseDescriptionWithPath("another/path"); exerciseShortLicenseDescriptionWithPath("short"); @@ -149,7 +162,8 @@ public class TestCommandParsing extends TestCase { exerciseShortLicenseDescriptionWithPath("http://url.style/path"); } - public void testSetLicenseDescriptorLongByCLI() throws Exception { + @Test + void setLicenseDescriptorLongByCLI() throws Exception { exerciseLongLicenseDescriptionWithPath("/some/path"); exerciseLongLicenseDescriptionWithPath("another/path"); exerciseLongLicenseDescriptionWithPath("short"); @@ -201,8 +215,9 @@ public class TestCommandParsing extends TestCase { args(arg, aPath, longOpt(CommandLineOption.ACT_TO_GENERATE.getLongName()))) .getLicenseDescriptor(); - assertEquals("License descriptor arg should set property on Whisker", aPath, - name(streamableResource)); + assertEquals(aPath, + name(streamableResource), + "License descriptor arg should set property on Whisker"); } private String name(final StreamableResource streamableResource) { diff --git a/apache-whisker-cli/src/test/java/org/apache/creadur/whisker/cli/TestMain.java b/apache-whisker-cli/src/test/java/org/apache/creadur/whisker/cli/TestMain.java index d700e4f..ed778a7 100644 --- a/apache-whisker-cli/src/test/java/org/apache/creadur/whisker/cli/TestMain.java +++ b/apache-whisker-cli/src/test/java/org/apache/creadur/whisker/cli/TestMain.java @@ -18,33 +18,39 @@ */ package org.apache.creadur.whisker.cli; -import org.apache.creadur.whisker.app.Whisker; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; -import junit.framework.TestCase; +import org.apache.creadur.whisker.app.Whisker; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -public class TestMain extends TestCase { +class TestMain { Main subject; - @Override - protected void setUp() throws Exception { - super.setUp(); + @BeforeEach + void setUp() throws Exception { subject = new Main(new Whisker()); } - public void testIsHelpHelp() throws Exception { + @Test + void isHelpHelp() throws Exception { assertTrue(subject.printHelp(args("--help"))); } - public void testIsGenerateHelp() throws Exception { + @Test + void isGenerateHelp() throws Exception { assertFalse(subject.printHelp(args("--generate"))); } - public void testIsAuditHelp() throws Exception { + @Test + void isAuditHelp() throws Exception { assertFalse(subject.printHelp(args("--audit"))); } - public void testIsSkeletonHelp() throws Exception { + @Test + void isSkeletonHelp() throws Exception { assertFalse(subject.printHelp(args("--skeleton"))); } diff --git a/apache-whisker-maven-plugin/pom.xml b/apache-whisker-maven-plugin/pom.xml index 194a8cd..7ea6e10 100644 --- a/apache-whisker-maven-plugin/pom.xml +++ b/apache-whisker-maven-plugin/pom.xml @@ -56,11 +56,6 @@ <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-to-slf4j</artifactId> </dependency> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <scope>test</scope> - </dependency> <dependency> <groupId>${project.groupId}</groupId> <artifactId>apache-whisker-scan</artifactId> diff --git a/apache-whisker-maven-plugin/src/test/java/org/apache/creadur/whisker/it/TestAllCheck.java b/apache-whisker-maven-plugin/src/test/java/org/apache/creadur/whisker/it/TestAllCheck.java index 0af0423..c288dab 100644 --- a/apache-whisker-maven-plugin/src/test/java/org/apache/creadur/whisker/it/TestAllCheck.java +++ b/apache-whisker-maven-plugin/src/test/java/org/apache/creadur/whisker/it/TestAllCheck.java @@ -18,36 +18,43 @@ */ package org.apache.creadur.whisker.it; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + import java.util.ArrayList; import java.util.Collection; import java.util.Collections; -import junit.framework.TestCase; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -public class TestAllCheck extends TestCase { +class TestAllCheck { Collection<Check> checks; Results results; AllCheck subject; - protected void setUp() throws Exception { - super.setUp(); + @BeforeEach + void setUp() throws Exception { results = new Results(); checks = new ArrayList<Check>(); } - protected void tearDown() throws Exception { - super.tearDown(); + @AfterEach + void tearDown() throws Exception { } - public void testNoChecksPass() { + @Test + void noChecksPass() { subject = new AllCheck(Collections.<Check> emptyList()); subject.check("a line"); verifyPass(); } - public void testOneCheckFail() { + @Test + void oneCheckFail() { final String value = "some value"; checks.add(new AnyLineContainsCheck(value)); @@ -62,7 +69,8 @@ public class TestAllCheck extends TestCase { assertTrue(results.hasFailed()); } - public void testOneCheckPass() { + @Test + void oneCheckPass() { final String value = "some value"; checks.add(new AnyLineContainsCheck(value)); @@ -77,7 +85,8 @@ public class TestAllCheck extends TestCase { assertFalse(results.hasFailed()); } - public void testTwoChecksPass() { + @Test + void twoChecksPass() { final String value = "some value"; final String anotherValue = "another value"; checks.add(new AnyLineContainsCheck(value)); @@ -88,7 +97,8 @@ public class TestAllCheck extends TestCase { verifyPass(); } - public void testTwoChecksFail() { + @Test + void twoChecksFail() { final String value = "some value"; final String anotherValue = "another value"; checks.add(new AnyLineContainsCheck(value)); @@ -98,7 +108,8 @@ public class TestAllCheck extends TestCase { verifyFail(); } - public void testTwoChecksWhenOneMatchFailsAllFail() { + @Test + void twoChecksWhenOneMatchFailsAllFail() { final String value = "some value"; final String anotherValue = "another value"; checks.add(new AnyLineContainsCheck(value)); diff --git a/apache-whisker-maven-plugin/src/test/java/org/apache/creadur/whisker/it/TestAnyCheck.java b/apache-whisker-maven-plugin/src/test/java/org/apache/creadur/whisker/it/TestAnyCheck.java index c61489e..6b0f0d1 100644 --- a/apache-whisker-maven-plugin/src/test/java/org/apache/creadur/whisker/it/TestAnyCheck.java +++ b/apache-whisker-maven-plugin/src/test/java/org/apache/creadur/whisker/it/TestAnyCheck.java @@ -18,36 +18,43 @@ */ package org.apache.creadur.whisker.it; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + import java.util.ArrayList; import java.util.Collection; import java.util.Collections; -import junit.framework.TestCase; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -public class TestAnyCheck extends TestCase { +class TestAnyCheck { Collection<Check> checks; Results results; AnyCheck subject; - protected void setUp() throws Exception { - super.setUp(); + @BeforeEach + void setUp() throws Exception { results = new Results(); checks = new ArrayList<>(); } - protected void tearDown() throws Exception { - super.tearDown(); + @AfterEach + void tearDown() throws Exception { } - public void testNoChecksPass() { + @Test + void noChecksPass() { subject = new AnyCheck(Collections.<Check> emptyList()); subject.check("a line"); verifyPass(); } - public void testOneCheckFail() { + @Test + void oneCheckFail() { final String value = "some value"; checks.add(new AnyLineContainsCheck(value)); @@ -62,7 +69,8 @@ public class TestAnyCheck extends TestCase { assertTrue(results.hasFailed()); } - public void testOneCheckPass() { + @Test + void oneCheckPass() { final String value = "some value"; checks.add(new AnyLineContainsCheck(value)); @@ -77,7 +85,8 @@ public class TestAnyCheck extends TestCase { assertFalse(results.hasFailed()); } - public void testTwoChecksPass() { + @Test + void twoChecksPass() { final String value = "some value"; final String anotherValue = "another value"; checks.add(new AnyLineContainsCheck(value)); @@ -88,7 +97,8 @@ public class TestAnyCheck extends TestCase { verifyPass(); } - public void testTwoChecksFail() { + @Test + void twoChecksFail() { final String value = "some value"; final String anotherValue = "another value"; checks.add(new AnyLineContainsCheck(value)); @@ -98,7 +108,8 @@ public class TestAnyCheck extends TestCase { verifyFail(); } - public void testTwoChecksPassWhenOneMatchFails() { + @Test + void twoChecksPassWhenOneMatchFails() { final String value = "some value"; final String anotherValue = "another value"; checks.add(new AnyLineContainsCheck(value)); diff --git a/apache-whisker-maven-plugin/src/test/java/org/apache/creadur/whisker/it/TestNoLineContainsCheck.java b/apache-whisker-maven-plugin/src/test/java/org/apache/creadur/whisker/it/TestNoLineContainsCheck.java index 87c552d..db11ebc 100644 --- a/apache-whisker-maven-plugin/src/test/java/org/apache/creadur/whisker/it/TestNoLineContainsCheck.java +++ b/apache-whisker-maven-plugin/src/test/java/org/apache/creadur/whisker/it/TestNoLineContainsCheck.java @@ -18,21 +18,26 @@ */ package org.apache.creadur.whisker.it; -import junit.framework.TestCase; +import static org.junit.jupiter.api.Assertions.*; -public class TestNoLineContainsCheck extends TestCase { +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +class TestNoLineContainsCheck { private static final String CHECKED_FOR_VALUE = "some value"; NoLineContainsCheck subject; Results results; - public void setUp() { + @BeforeEach + void setUp() { subject = new NoLineContainsCheck(CHECKED_FOR_VALUE); results = new Results(); } - public void testNullLine() { + @Test + void nullLine() { subject.check(null); assertTrue(subject.hasPassed()); subject.report(results); @@ -40,7 +45,8 @@ public class TestNoLineContainsCheck extends TestCase { assertNull(results.collate()); } - public void testDifferentLine() { + @Test + void differentLine() { subject.check("something different"); assertTrue(subject.hasPassed()); subject.report(results); @@ -48,7 +54,8 @@ public class TestNoLineContainsCheck extends TestCase { assertNull(results.collate()); } - public void testSameLine() { + @Test + void sameLine() { subject.check(CHECKED_FOR_VALUE); assertFalse(subject.hasPassed()); subject.report(results); @@ -56,7 +63,8 @@ public class TestNoLineContainsCheck extends TestCase { assertTrue(results.collate().contains(NoLineContainsCheck.WARNING + CHECKED_FOR_VALUE)); } - public void testLineContainingText() { + @Test + void lineContainingText() { subject.check("prefix " + CHECKED_FOR_VALUE + " suffix"); assertFalse(subject.hasPassed()); subject.report(results); diff --git a/apache-whisker-model/pom.xml b/apache-whisker-model/pom.xml index be16257..91cc0ae 100644 --- a/apache-whisker-model/pom.xml +++ b/apache-whisker-model/pom.xml @@ -31,11 +31,6 @@ <groupId>org.apache.commons</groupId> <artifactId>commons-lang3</artifactId> </dependency> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <scope>test</scope> - </dependency> </dependencies> <name>Apache Whisker::Model</name> <description>Models licensing meta-data.</description> diff --git a/apache-whisker-model/src/test/java/org/apache/creadur/whisker/model/TestDescriptorOnlyPrimary.java b/apache-whisker-model/src/test/java/org/apache/creadur/whisker/model/TestDescriptorOnlyPrimary.java index 4763148..9a26b86 100644 --- a/apache-whisker-model/src/test/java/org/apache/creadur/whisker/model/TestDescriptorOnlyPrimary.java +++ b/apache-whisker-model/src/test/java/org/apache/creadur/whisker/model/TestDescriptorOnlyPrimary.java @@ -18,26 +18,31 @@ */ package org.apache.creadur.whisker.model; -import junit.framework.TestCase; +import static org.junit.jupiter.api.Assertions.assertFalse; -public class TestDescriptorOnlyPrimary extends TestCase { +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +class TestDescriptorOnlyPrimary { DescriptorBuilderForTesting builder; Descriptor subject; - protected void setUp() throws Exception { - super.setUp(); + @BeforeEach + void setUp() throws Exception { builder = new DescriptorBuilderForTesting(); } - protected void tearDown() throws Exception { - super.tearDown(); + @AfterEach + void tearDown() throws Exception { } - public void testIsOnlyPrimaryWithSubsidaryCopyrightNotice() throws Exception { + @Test + void isOnlyPrimaryWithSubsidaryCopyrightNotice() throws Exception { builder.withSubsidaryCopyrightNotice().withThirdParty().withDirectory("."); subject = builder.build(); - assertFalse("Work is not only primary when subsidary copyright notices exist.", - subject.isOnlyPrimary(builder.contents.iterator().next())); + assertFalse(subject.isOnlyPrimary(builder.contents.iterator().next()), + "Work is not only primary when subsidary copyright notices exist."); } } diff --git a/apache-whisker-model/src/test/java/org/apache/creadur/whisker/model/TestDescriptorPrimaryOnly.java b/apache-whisker-model/src/test/java/org/apache/creadur/whisker/model/TestDescriptorPrimaryOnly.java index 9403018..cdd4575 100644 --- a/apache-whisker-model/src/test/java/org/apache/creadur/whisker/model/TestDescriptorPrimaryOnly.java +++ b/apache-whisker-model/src/test/java/org/apache/creadur/whisker/model/TestDescriptorPrimaryOnly.java @@ -18,42 +18,50 @@ */ package org.apache.creadur.whisker.model; -import junit.framework.TestCase; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; -public class TestDescriptorPrimaryOnly extends TestCase { +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +class TestDescriptorPrimaryOnly { DescriptorBuilderForTesting builder; Descriptor subject; - protected void setUp() throws Exception { - super.setUp(); + @BeforeEach + void setUp() throws Exception { builder = new DescriptorBuilderForTesting(); builder.withThirdParty().withDirectory("."); } - protected void tearDown() throws Exception { - super.tearDown(); + @AfterEach + void tearDown() throws Exception { } - public void testIsPrimaryOnlyWithThirdPartyResources() throws Exception { + @Test + void isPrimaryOnlyWithThirdPartyResources() throws Exception { subject = builder.build(); builder.withThirdPartyDirectory("lib"); - assertFalse("Work is not primary only when third party resources exist.", subject.isPrimaryOnly()); + assertFalse(subject.isPrimaryOnly(), "Work is not primary only when third party resources exist."); } - public void testIsPrimaryOnlyWithoutThirdPartyResources() throws Exception { + @Test + void isPrimaryOnlyWithoutThirdPartyResources() throws Exception { subject = builder.build(); - assertTrue("Work is primary only when no third party resources exist.", - subject.isPrimaryOnly()); + assertTrue(subject.isPrimaryOnly(), + "Work is primary only when no third party resources exist."); } - public void testIsPrimaryOnlyWithoutResources() throws Exception { + @Test + void isPrimaryOnlyWithoutResources() throws Exception { subject = builder.build(); builder.contents.clear(); - assertTrue("Work is primary only when no third party resources exist.", - subject.isPrimaryOnly()); + assertTrue(subject.isPrimaryOnly(), + "Work is primary only when no third party resources exist."); } } diff --git a/apache-whisker-model/src/test/java/org/apache/creadur/whisker/model/TestDescriptorRequiredNoticesNoThirdPartyNotices.java b/apache-whisker-model/src/test/java/org/apache/creadur/whisker/model/TestDescriptorRequiredNoticesNoThirdPartyNotices.java index dc44822..02f6800 100644 --- a/apache-whisker-model/src/test/java/org/apache/creadur/whisker/model/TestDescriptorRequiredNoticesNoThirdPartyNotices.java +++ b/apache-whisker-model/src/test/java/org/apache/creadur/whisker/model/TestDescriptorRequiredNoticesNoThirdPartyNotices.java @@ -18,15 +18,20 @@ */ package org.apache.creadur.whisker.model; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.Map; -import junit.framework.TestCase; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -public class TestDescriptorRequiredNoticesNoThirdPartyNotices extends TestCase { +class TestDescriptorRequiredNoticesNoThirdPartyNotices { License primaryLicense = new License(false, "This is the license text", Collections.<String> emptyList(), "example.org", "http://example.org", "Example License"); String primaryOrg = "example.org"; @@ -37,44 +42,48 @@ public class TestDescriptorRequiredNoticesNoThirdPartyNotices extends TestCase { Map<String, Organisation> organisations = new HashMap<String, Organisation>(); Descriptor subject; - - protected void setUp() throws Exception { - super.setUp(); + + @BeforeEach + void setUp() throws Exception { primaryLicense.storeIn(licenses); } - protected void tearDown() throws Exception { - super.tearDown(); + @AfterEach + void tearDown() throws Exception { } - public void testNoticeRequiredWhenPrimaryNoticeExists() throws Exception { + @Test + void noticeRequiredWhenPrimaryNoticeExists() throws Exception { subject = new Descriptor(primaryLicense, primaryOrg, primaryNotice, licenses, notices, organisations, contents); - assertTrue("When primary notices exists, even if there are not other notices display is required", subject.isNoticeRequired()); + assertTrue(subject.isNoticeRequired(), "When primary notices exists, even if there are not other notices display is required"); } - public void testNoticeNotRequiredWhenPrimaryNoticeIsNullAndNoNotices() throws Exception { + @Test + void noticeNotRequiredWhenPrimaryNoticeIsNullAndNoNotices() throws Exception { subject = new Descriptor(primaryLicense, primaryOrg, null, licenses, notices, organisations, contents); - assertFalse("When no other notices exist and no primary notice, display is not required", - subject.isNoticeRequired()); + assertFalse(subject.isNoticeRequired(), + "When no other notices exist and no primary notice, display is not required"); } - public void testNoticeNotRequiredWhenPrimaryNoticeIsEmptyAndNoNotices() throws Exception { + @Test + void noticeNotRequiredWhenPrimaryNoticeIsEmptyAndNoNotices() throws Exception { subject = new Descriptor(primaryLicense, primaryOrg, "", licenses, notices, organisations, contents); - assertFalse("When no other notices exist and no primary notice, display is not required", - subject.isNoticeRequired()); + assertFalse(subject.isNoticeRequired(), + "When no other notices exist and no primary notice, display is not required"); } - public void testNoticeNotRequiredWhenPrimaryNoticeIsWhitespaceAndNoNotices() throws Exception { + @Test + void noticeNotRequiredWhenPrimaryNoticeIsWhitespaceAndNoNotices() throws Exception { subject = new Descriptor(primaryLicense, primaryOrg, " ", licenses, notices, organisations, contents); - assertFalse("When no other notices exist and no primary notice, display is not required", - subject.isNoticeRequired()); + assertFalse(subject.isNoticeRequired(), + "When no other notices exist and no primary notice, display is not required"); } } diff --git a/apache-whisker-model/src/test/java/org/apache/creadur/whisker/model/TestDescriptorRequiredNoticesWithRequiredThirdPartyNotices.java b/apache-whisker-model/src/test/java/org/apache/creadur/whisker/model/TestDescriptorRequiredNoticesWithRequiredThirdPartyNotices.java index 18753b2..8eccd72 100644 --- a/apache-whisker-model/src/test/java/org/apache/creadur/whisker/model/TestDescriptorRequiredNoticesWithRequiredThirdPartyNotices.java +++ b/apache-whisker-model/src/test/java/org/apache/creadur/whisker/model/TestDescriptorRequiredNoticesWithRequiredThirdPartyNotices.java @@ -18,15 +18,19 @@ */ package org.apache.creadur.whisker.model; +import static org.junit.jupiter.api.Assertions.assertTrue; + import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.Map; -import junit.framework.TestCase; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -public class TestDescriptorRequiredNoticesWithRequiredThirdPartyNotices extends TestCase { +class TestDescriptorRequiredNoticesWithRequiredThirdPartyNotices { License primaryLicense = new License(false, "This is the license text", Collections.<String> emptyList(), "example.org", "http://example.org", "Example License"); String primaryOrg = "example.org"; @@ -37,9 +41,9 @@ public class TestDescriptorRequiredNoticesWithRequiredThirdPartyNotices extends Map<String, Organisation> organisations = new HashMap<String, Organisation>(); Descriptor subject; - - protected void setUp() throws Exception { - super.setUp(); + + @BeforeEach + void setUp() throws Exception { primaryLicense.storeIn(licenses); String noticeId = "notice:id"; notices.put(noticeId, "Some notice text"); @@ -62,39 +66,43 @@ public class TestDescriptorRequiredNoticesWithRequiredThirdPartyNotices extends contents.add(new WithinDirectory(".", withLicenses, publicDomain)); } - protected void tearDown() throws Exception { - super.tearDown(); + @AfterEach + void tearDown() throws Exception { } - public void testNoticeRequiredWhenPrimaryNoticeExists() throws Exception { + @Test + void noticeRequiredWhenPrimaryNoticeExists() throws Exception { subject = new Descriptor(primaryLicense, primaryOrg, primaryNotice, licenses, notices, organisations, contents); - assertTrue("When primary notices exists and third party notices needed then display is required", - subject.isNoticeRequired()); + assertTrue(subject.isNoticeRequired(), + "When primary notices exists and third party notices needed then display is required"); } - public void testNoticeRequiredWhenPrimaryNoticeIsNullAndThirdPartyNotices() throws Exception { + @Test + void noticeRequiredWhenPrimaryNoticeIsNullAndThirdPartyNotices() throws Exception { subject = new Descriptor(primaryLicense, primaryOrg, null, licenses, notices, organisations, contents); - assertTrue("When no other notices exist and third party notices needed then display is required", - subject.isNoticeRequired()); + assertTrue(subject.isNoticeRequired(), + "When no other notices exist and third party notices needed then display is required"); } - public void testNoticeRequiredWhenPrimaryNoticeIsEmptyAndThirdPartyNotices() throws Exception { + @Test + void noticeRequiredWhenPrimaryNoticeIsEmptyAndThirdPartyNotices() throws Exception { subject = new Descriptor(primaryLicense, primaryOrg, "", licenses, notices, organisations, contents); - assertTrue("When no other notices exist and third party notices needed then display is required", - subject.isNoticeRequired()); + assertTrue(subject.isNoticeRequired(), + "When no other notices exist and third party notices needed then display is required"); } - public void testNoticeRequiredWhenPrimaryNoticeIsWhitespaceAndThirdPartyNotices() throws Exception { + @Test + void noticeRequiredWhenPrimaryNoticeIsWhitespaceAndThirdPartyNotices() throws Exception { subject = new Descriptor(primaryLicense, primaryOrg, " ", licenses, notices, organisations, contents); - assertTrue("When no other notices exist and third party notices needed then display is required", - subject.isNoticeRequired()); + assertTrue(subject.isNoticeRequired(), + "When no other notices exist and third party notices needed then display is required"); } } diff --git a/apache-whisker-model/src/test/java/org/apache/creadur/whisker/model/TestDescriptorRequiredNoticesWithThirdPartyNoticesButNoneUsed.java b/apache-whisker-model/src/test/java/org/apache/creadur/whisker/model/TestDescriptorRequiredNoticesWithThirdPartyNoticesButNoneUsed.java index 03f50eb..5b368b1 100644 --- a/apache-whisker-model/src/test/java/org/apache/creadur/whisker/model/TestDescriptorRequiredNoticesWithThirdPartyNoticesButNoneUsed.java +++ b/apache-whisker-model/src/test/java/org/apache/creadur/whisker/model/TestDescriptorRequiredNoticesWithThirdPartyNoticesButNoneUsed.java @@ -18,15 +18,20 @@ */ package org.apache.creadur.whisker.model; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.Map; -import junit.framework.TestCase; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -public class TestDescriptorRequiredNoticesWithThirdPartyNoticesButNoneUsed extends TestCase { +class TestDescriptorRequiredNoticesWithThirdPartyNoticesButNoneUsed { License primaryLicense = new License(false, "This is the license text", Collections.<String> emptyList(), "example.org", "http://example.org", "Example License"); String primaryOrg = "example.org"; @@ -37,46 +42,50 @@ public class TestDescriptorRequiredNoticesWithThirdPartyNoticesButNoneUsed exten Map<String, Organisation> organisations = new HashMap<String, Organisation>(); Descriptor subject; - - protected void setUp() throws Exception { - super.setUp(); + + @BeforeEach + void setUp() throws Exception { primaryLicense.storeIn(licenses); notices.put("bogus", "some notice chaff"); } - protected void tearDown() throws Exception { - super.tearDown(); + @AfterEach + void tearDown() throws Exception { } - public void testNoticeRequiredWhenPrimaryNoticeExists() throws Exception { + @Test + void noticeRequiredWhenPrimaryNoticeExists() throws Exception { subject = new Descriptor(primaryLicense, primaryOrg, primaryNotice, licenses, notices, organisations, contents); - assertTrue("When primary notices exists and third party notices needed then display is required", - subject.isNoticeRequired()); + assertTrue(subject.isNoticeRequired(), + "When primary notices exists and third party notices needed then display is required"); } - public void testNoticeNotRequiredWhenPrimaryNoticeIsNullAndAllThirdPartyNoticesUnused() throws Exception { + @Test + void noticeNotRequiredWhenPrimaryNoticeIsNullAndAllThirdPartyNoticesUnused() throws Exception { subject = new Descriptor(primaryLicense, primaryOrg, null, licenses, notices, organisations, contents); - assertFalse("When no other notices exist and third party notices needed then display is required", - subject.isNoticeRequired()); + assertFalse(subject.isNoticeRequired(), + "When no other notices exist and third party notices needed then display is required"); } - public void testNoticeNotRequiredWhenPrimaryNoticeIsEmptyAndAllThirdPartyNoticesUnused() throws Exception { + @Test + void noticeNotRequiredWhenPrimaryNoticeIsEmptyAndAllThirdPartyNoticesUnused() throws Exception { subject = new Descriptor(primaryLicense, primaryOrg, "", licenses, notices, organisations, contents); - assertFalse("When no other notices exist and third party notices needed then display is required", - subject.isNoticeRequired()); + assertFalse(subject.isNoticeRequired(), + "When no other notices exist and third party notices needed then display is required"); } - public void testNoticeNotRequiredWhenPrimaryNoticeIsWhitespaceAndAllThirdPartyNoticesUnused() throws Exception { + @Test + void noticeNotRequiredWhenPrimaryNoticeIsWhitespaceAndAllThirdPartyNoticesUnused() throws Exception { subject = new Descriptor(primaryLicense, primaryOrg, " ", licenses, notices, organisations, contents); - assertFalse("When no other notices exist and third party notices needed then display is required", - subject.isNoticeRequired()); + assertFalse(subject.isNoticeRequired(), + "When no other notices exist and third party notices needed then display is required"); } } diff --git a/apache-whisker-model/src/test/java/org/apache/creadur/whisker/model/TestNoCopyrightNoticeVerifier.java b/apache-whisker-model/src/test/java/org/apache/creadur/whisker/model/TestNoCopyrightNoticeVerifier.java index dfaa7e2..105c77b 100644 --- a/apache-whisker-model/src/test/java/org/apache/creadur/whisker/model/TestNoCopyrightNoticeVerifier.java +++ b/apache-whisker-model/src/test/java/org/apache/creadur/whisker/model/TestNoCopyrightNoticeVerifier.java @@ -18,22 +18,29 @@ */ package org.apache.creadur.whisker.model; -import junit.framework.TestCase; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; -public class TestNoCopyrightNoticeVerifier extends TestCase { +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +class TestNoCopyrightNoticeVerifier { NoCopyrightNoticeVerifier subject; - public void setUp() throws Exception { + @BeforeEach + void setUp() throws Exception { subject = new NoCopyrightNoticeVerifier(); } - public void testWithLicenseNoCopyrightNotice() throws Exception { + @Test + void withLicenseNoCopyrightNotice() throws Exception { new WithLicenseBuilderForTesting().withNoCopyrightNotice().build().accept(subject); assertFalse(subject.isCopyrightNoticePresent()); } - public void testWithLicenseWithCopyrightNotice() throws Exception { + @Test + void withLicenseWithCopyrightNotice() throws Exception { new WithLicenseBuilderForTesting().withCopyrightNotice().build().accept(subject); assertTrue(subject.isCopyrightNoticePresent()); } diff --git a/apache-whisker-model/src/test/java/org/apache/creadur/whisker/model/TestWithLicense.java b/apache-whisker-model/src/test/java/org/apache/creadur/whisker/model/TestWithLicense.java index a89a5f2..8ba46fc 100644 --- a/apache-whisker-model/src/test/java/org/apache/creadur/whisker/model/TestWithLicense.java +++ b/apache-whisker-model/src/test/java/org/apache/creadur/whisker/model/TestWithLicense.java @@ -19,22 +19,28 @@ package org.apache.creadur.whisker.model; -import junit.framework.TestCase; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; -public class TestWithLicense extends TestCase { +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; - protected void setUp() throws Exception { - super.setUp(); +class TestWithLicense { + + @BeforeEach + void setUp() throws Exception { } - public void testWhenCopyrightNoticeIsNull() { + @Test + void whenCopyrightNoticeIsNull() { assertFalse(new WithLicenseBuilderForTesting() .withCopyrightNotice(null).build() .hasCopyrightNotice()); } - public void testWhenCopyrightNoticeIsNotNull() { + @Test + void whenCopyrightNoticeIsNotNull() { assertTrue(new WithLicenseBuilderForTesting() .withCopyrightNotice("some notice").build() .hasCopyrightNotice()); diff --git a/apache-whisker-scan/pom.xml b/apache-whisker-scan/pom.xml index 0aaf288..fc8b2fb 100644 --- a/apache-whisker-scan/pom.xml +++ b/apache-whisker-scan/pom.xml @@ -26,13 +26,6 @@ </parent> <artifactId>apache-whisker-scan</artifactId> <packaging>jar</packaging> - <dependencies> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <scope>test</scope> - </dependency> - </dependencies> <name>Apache Whisker::Scan</name> <description>Scans directories for resources</description> <url>https://creadur.apache.org/whisker/apache-whisker-scan</url> diff --git a/apache-whisker-velocity/pom.xml b/apache-whisker-velocity/pom.xml index 37ca5c8..490644c 100644 --- a/apache-whisker-velocity/pom.xml +++ b/apache-whisker-velocity/pom.xml @@ -47,11 +47,6 @@ <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-core</artifactId> </dependency> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <scope>test</scope> - </dependency> <dependency> <groupId>org.jmock</groupId> <artifactId>jmock-junit3</artifactId> diff --git a/apache-whisker-velocity/src/test/java/org/apache/creadur/whisker/out/velocity/TestLicenseGeneration.java b/apache-whisker-velocity/src/test/java/org/apache/creadur/whisker/out/velocity/TestLicenseGeneration.java index 469dfbf..b929be7 100644 --- a/apache-whisker-velocity/src/test/java/org/apache/creadur/whisker/out/velocity/TestLicenseGeneration.java +++ b/apache-whisker-velocity/src/test/java/org/apache/creadur/whisker/out/velocity/TestLicenseGeneration.java @@ -19,112 +19,118 @@ package org.apache.creadur.whisker.out.velocity; import static org.apache.creadur.whisker.app.ConfigurationBuilder.*; - -import junit.framework.TestCase; +import static org.junit.jupiter.api.Assertions.*; import org.apache.commons.lang3.StringUtils; import org.apache.creadur.whisker.app.Result; import org.apache.creadur.whisker.model.Descriptor; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -public class TestLicenseGeneration extends TestCase { +class TestLicenseGeneration { StringResultWriterFactory writerFactory; LoggingVelocityEngine subject; DescriptorBuilderForTesting builder; - @Override - protected void setUp() throws Exception { - super.setUp(); + @BeforeEach + void setUp() throws Exception { writerFactory = new StringResultWriterFactory(); subject = new LoggingVelocityEngine(); builder = new DescriptorBuilderForTesting(); } - @Override - protected void tearDown() throws Exception { - super.tearDown(); + @AfterEach + void tearDown() throws Exception { } - public void testThatWhenThereAreNoThirdPartyContentsFooterIsNotShown() throws Exception { + @Test + void thatWhenThereAreNoThirdPartyContentsFooterIsNotShown() throws Exception { Descriptor work = builder.build(); subject.generate(work, writerFactory, aConfiguration().build()); - assertTrue("Check that work is suitable for this test", work.isPrimaryOnly()); - assertEquals("Only one request for LICENSE writer", 1, writerFactory.requestsFor(Result.LICENSE)); - assertEquals("When no third party contents, expect that only the license text is output", - builder.getPrimaryLicenseText(), - writerFactory.firstOutputFor(Result.LICENSE).trim()); + assertTrue(work.isPrimaryOnly(), "Check that work is suitable for this test"); + assertEquals(1, writerFactory.requestsFor(Result.LICENSE), "Only one request for LICENSE writer"); + assertEquals(builder.getPrimaryLicenseText(), + writerFactory.firstOutputFor(Result.LICENSE).trim(), + "When no third party contents, expect that only the license text is output"); } - public void testThatFooterIsShownWhenThereAreThirdPartyContents() throws Exception { + @Test + void thatFooterIsShownWhenThereAreThirdPartyContents() throws Exception { Descriptor work = builder.withPrimaryLicenseAndThirdPartyOrgInDirectory("lib").build(); - assertFalse("Check that work is suitable for this test", work.isPrimaryOnly()); + assertFalse(work.isPrimaryOnly(), "Check that work is suitable for this test"); subject.generate(work, writerFactory, aConfiguration().build()); - assertEquals("Only one request for LICENSE writer", 1, writerFactory.requestsFor(Result.LICENSE)); - assertTrue("Expect information when third party contents present: " + writerFactory.firstOutputFor(Result.LICENSE), - StringUtils.contains(writerFactory.firstOutputFor(Result.LICENSE), - "This distribution contains third party resources.")); + assertEquals(1, writerFactory.requestsFor(Result.LICENSE), "Only one request for LICENSE writer"); + assertTrue(StringUtils.contains(writerFactory.firstOutputFor(Result.LICENSE), + "This distribution contains third party resources."), + "Expect information when third party contents present: " + writerFactory.firstOutputFor(Result.LICENSE)); } - public void testSecondaryCopyrightNoticeForPrimaryLicense() throws Exception { + @Test + void secondaryCopyrightNoticeForPrimaryLicense() throws Exception { subject.generate( builder .withSecondaryCopyrightNotice() .withPrimaryCopyrightNotice() .withPrimaryLicenseAndOrgInDirectory("lib").build(), writerFactory, aConfiguration().build()); - assertEquals("Only one request for LICENSE writer", 1, writerFactory.requestsFor(Result.LICENSE)); - assertTrue("Expect secondary copyright to be presented: " + writerFactory.firstOutputFor(Result.LICENSE), - StringUtils.contains(writerFactory.firstOutputFor(Result.LICENSE), - builder.getSecondaryCopyright())); + assertEquals(1, writerFactory.requestsFor(Result.LICENSE), "Only one request for LICENSE writer"); + assertTrue(StringUtils.contains(writerFactory.firstOutputFor(Result.LICENSE), + builder.getSecondaryCopyright()), + "Expect secondary copyright to be presented: " + writerFactory.firstOutputFor(Result.LICENSE)); verifyThatResourceNameIsWritten(); } private void verifyThatResourceNameIsWritten() { - assertTrue("Expect resource to be indicated: " + writerFactory.firstOutputFor(Result.LICENSE), - StringUtils.contains(writerFactory.firstOutputFor(Result.LICENSE), - builder.getResourceName())); + assertTrue(StringUtils.contains(writerFactory.firstOutputFor(Result.LICENSE), + builder.getResourceName()), + "Expect resource to be indicated: " + writerFactory.firstOutputFor(Result.LICENSE)); } private void verifyThatResourceNameIsNotWritten() { - assertFalse("Expect resource to be indicated: " + writerFactory.firstOutputFor(Result.LICENSE), - StringUtils.contains(writerFactory.firstOutputFor(Result.LICENSE), - builder.getResourceName())); + assertFalse(StringUtils.contains(writerFactory.firstOutputFor(Result.LICENSE), + builder.getResourceName()), + "Expect resource to be indicated: " + writerFactory.firstOutputFor(Result.LICENSE)); } - public void testPrimaryOrganisationSecondaryLicense() throws Exception { + @Test + void primaryOrganisationSecondaryLicense() throws Exception { subject.generate( builder.withSecondaryLicensePrimaryOrganisationInDirectory("lib").build(), writerFactory, aConfiguration().build()); - assertEquals("Only one request for LICENSE writer", 1, writerFactory.requestsFor(Result.LICENSE)); + assertEquals(1, writerFactory.requestsFor(Result.LICENSE), "Only one request for LICENSE writer"); verifyThatResourceNameIsWritten(); } - public void testIgnorePrimaryOrganisationPrimaryLicense() throws Exception { + @Test + void ignorePrimaryOrganisationPrimaryLicense() throws Exception { subject.generate( builder.withPrimaryLicenseAndOrgInDirectory("lib").build(), writerFactory, aConfiguration().build()); - assertEquals("Only one request for LICENSE writer", 1, writerFactory.requestsFor(Result.LICENSE)); + assertEquals(1, writerFactory.requestsFor(Result.LICENSE), "Only one request for LICENSE writer"); verifyThatResourceNameIsNotWritten(); } - public void testIgnorePrimaryOrganisationPrimaryLicensePrimaryCopyrightNotice() throws Exception { + @Test + void ignorePrimaryOrganisationPrimaryLicensePrimaryCopyrightNotice() throws Exception { subject.generate( builder .withPrimaryCopyrightNotice() .withPrimaryLicenseAndOrgInDirectory("lib") .build(), writerFactory, aConfiguration().build()); - assertEquals("Only one request for LICENSE writer", 1, writerFactory.requestsFor(Result.LICENSE)); + assertEquals(1, writerFactory.requestsFor(Result.LICENSE), "Only one request for LICENSE writer"); verifyThatResourceNameIsNotWritten(); } diff --git a/apache-whisker-velocity/src/test/java/org/apache/creadur/whisker/out/velocity/TestLicenseGenerationSourceURLs.java b/apache-whisker-velocity/src/test/java/org/apache/creadur/whisker/out/velocity/TestLicenseGenerationSourceURLs.java index 0dd21cf..69cbe61 100644 --- a/apache-whisker-velocity/src/test/java/org/apache/creadur/whisker/out/velocity/TestLicenseGenerationSourceURLs.java +++ b/apache-whisker-velocity/src/test/java/org/apache/creadur/whisker/out/velocity/TestLicenseGenerationSourceURLs.java @@ -19,36 +19,39 @@ package org.apache.creadur.whisker.out.velocity; import static org.apache.creadur.whisker.app.ConfigurationBuilder.aConfiguration; -import junit.framework.TestCase; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; import org.apache.commons.lang3.StringUtils; import org.apache.creadur.whisker.app.Result; import org.apache.creadur.whisker.model.Descriptor; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -public class TestLicenseGenerationSourceURLs extends TestCase { +class TestLicenseGenerationSourceURLs { StringResultWriterFactory writerFactory; LoggingVelocityEngine subject; DescriptorBuilderForTesting builder; Descriptor work; - @Override - protected void setUp() throws Exception { - super.setUp(); + @BeforeEach + void setUp() throws Exception { writerFactory = new StringResultWriterFactory(); subject = new LoggingVelocityEngine(); builder = new DescriptorBuilderForTesting().withSourceURL(); work = builder.withPrimaryLicenseAndThirdPartyOrgInDirectory(".").build(); } - @Override - protected void tearDown() throws Exception { - super.tearDown(); + @AfterEach + void tearDown() throws Exception { } - public void testNoSourceUrlsConfiguration() throws Exception { + @Test + void noSourceUrlsConfiguration() throws Exception { subject.generate(work, writerFactory, aConfiguration().noSourceURLsInLicense().build()); - assertFalse(failureMessage(), outputContainsSourceUrl()); + assertFalse(outputContainsSourceUrl(), failureMessage()); } @@ -61,10 +64,11 @@ public class TestLicenseGenerationSourceURLs extends TestCase { return "Expect information when third party contents present: " + writerFactory.firstOutputFor(Result.LICENSE); } - public void testWithSourceUrlsConfiguration() throws Exception { + @Test + void withSourceUrlsConfiguration() throws Exception { subject.generate(work, writerFactory, aConfiguration().withSourceURLsInLicense().build()); - assertTrue(failureMessage(), outputContainsSourceUrl()); + assertTrue(outputContainsSourceUrl(), failureMessage()); } } diff --git a/apache-whisker-velocity/src/test/java/org/apache/creadur/whisker/out/velocity/TestNoticeGeneration.java b/apache-whisker-velocity/src/test/java/org/apache/creadur/whisker/out/velocity/TestNoticeGeneration.java index 20ba194..69ea98d 100644 --- a/apache-whisker-velocity/src/test/java/org/apache/creadur/whisker/out/velocity/TestNoticeGeneration.java +++ b/apache-whisker-velocity/src/test/java/org/apache/creadur/whisker/out/velocity/TestNoticeGeneration.java @@ -19,6 +19,7 @@ package org.apache.creadur.whisker.out.velocity; import static org.apache.creadur.whisker.app.ConfigurationBuilder.*; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.util.ArrayList; import java.util.Collection; @@ -31,10 +32,11 @@ import org.apache.creadur.whisker.model.Descriptor; import org.apache.creadur.whisker.model.License; import org.apache.creadur.whisker.model.Organisation; import org.apache.creadur.whisker.model.WithinDirectory; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -import junit.framework.TestCase; - -public class TestNoticeGeneration extends TestCase { +class TestNoticeGeneration { StringResultWriterFactory writerFactory; LoggingVelocityEngine subject; @@ -46,38 +48,38 @@ public class TestNoticeGeneration extends TestCase { Map<String, String> notices = new HashMap<String, String>(); Map<String, Organisation> organisations = new HashMap<String, Organisation>(); - @Override - protected void setUp() throws Exception { - super.setUp(); + @BeforeEach + void setUp() throws Exception { writerFactory = new StringResultWriterFactory(); subject = new LoggingVelocityEngine(); primaryLicense.storeIn(licenses); } - @Override - protected void tearDown() throws Exception { - super.tearDown(); + @AfterEach + void tearDown() throws Exception { } - public void testThatWhenThereAreNoThirdPartyNoticesHeaderIsNotShown() throws Exception { + @Test + void thatWhenThereAreNoThirdPartyNoticesHeaderIsNotShown() throws Exception { Descriptor work = new Descriptor(primaryLicense, primaryOrg, primaryNotice, licenses, notices, organisations, contents); subject.generate(work, writerFactory, aConfiguration().build()); - assertEquals("Only one request for NOTICE writer", 1, writerFactory.requestsFor(Result.NOTICE)); - assertEquals("When no third party notices, expect that only the primary notice is output", primaryNotice, writerFactory.firstOutputFor(Result.NOTICE).trim()); + assertEquals(1, writerFactory.requestsFor(Result.NOTICE), "Only one request for NOTICE writer"); + assertEquals(primaryNotice, writerFactory.firstOutputFor(Result.NOTICE).trim(), "When no third party notices, expect that only the primary notice is output"); } - public void testThatNoticeOutputIsSkippedWhenThereAreNoNotices() throws Exception { + @Test + void thatNoticeOutputIsSkippedWhenThereAreNoNotices() throws Exception { Descriptor work = new Descriptor(primaryLicense, primaryOrg, "", licenses, notices, organisations, contents); subject.generate(work, writerFactory, aConfiguration().build()); - assertEquals("No requests for NOTICE writer", 0, writerFactory.requestsFor(Result.NOTICE)); + assertEquals(0, writerFactory.requestsFor(Result.NOTICE), "No requests for NOTICE writer"); } } diff --git a/apache-whisker-velocity/src/test/java/org/apache/creadur/whisker/out/velocity/TestRenderingHelper.java b/apache-whisker-velocity/src/test/java/org/apache/creadur/whisker/out/velocity/TestRenderingHelper.java index 50fd5ce..2fc2a28 100644 --- a/apache-whisker-velocity/src/test/java/org/apache/creadur/whisker/out/velocity/TestRenderingHelper.java +++ b/apache-whisker-velocity/src/test/java/org/apache/creadur/whisker/out/velocity/TestRenderingHelper.java @@ -19,13 +19,14 @@ package org.apache.creadur.whisker.out.velocity; import static org.apache.creadur.whisker.app.ConfigurationBuilder.*; +import static org.junit.jupiter.api.Assertions.assertEquals; import org.apache.creadur.whisker.model.Descriptor; import org.apache.creadur.whisker.model.Resource; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -import junit.framework.TestCase; - -public class TestRenderingHelper extends TestCase { +class TestRenderingHelper { private static final String A_SOURCE_URL = "http://example.org/sample"; @@ -36,32 +37,35 @@ public class TestRenderingHelper extends TestCase { Descriptor work; - @Override - protected void setUp() throws Exception { - super.setUp(); + @BeforeEach + void setUp() throws Exception { resourceWithSourceUrl = new Resource("a name", "an:id", A_SOURCE_URL); resourceNoSourceUrl = new Resource("a name", "an:id", null); } - public void testSourceWithSourceUrlsConfiguration() { + @Test + void sourceWithSourceUrlsConfiguration() { subject = new RenderingHelper(work, aConfiguration().withSourceURLsInLicense().build()); assertEquals(" from " + A_SOURCE_URL, subject.sourceUrl(resourceWithSourceUrl)); } - public void testSourceNoSourceUrlsConfiguration() { + @Test + void sourceNoSourceUrlsConfiguration() { subject = new RenderingHelper(work, aConfiguration().noSourceURLsInLicense().build()); assertEquals("", subject.sourceUrl(resourceWithSourceUrl)); } - public void testNoSourceWithSourceUrlsConfiguration() { + @Test + void noSourceWithSourceUrlsConfiguration() { subject = new RenderingHelper(work, aConfiguration().withSourceURLsInLicense().build()); assertEquals("", subject.sourceUrl(resourceNoSourceUrl)); } - public void testNoSourceNoSourceUrlsConfiguration() { + @Test + void noSourceNoSourceUrlsConfiguration() { subject = new RenderingHelper(work, aConfiguration().noSourceURLsInLicense().build()); assertEquals("", subject.sourceUrl(resourceNoSourceUrl)); diff --git a/apache-whisker-xml/pom.xml b/apache-whisker-xml/pom.xml index 38d5b72..f6df11f 100644 --- a/apache-whisker-xml/pom.xml +++ b/apache-whisker-xml/pom.xml @@ -35,11 +35,6 @@ <groupId>org.apache.commons</groupId> <artifactId>commons-lang3</artifactId> </dependency> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <scope>test</scope> - </dependency> <dependency> <groupId>${project.groupId}</groupId> <artifactId>apache-whisker-model</artifactId> diff --git a/apache-whisker-xml/src/test/java/org/apache/creadur/whisker/fromxml/JDomBuilderByOrganisationTest.java b/apache-whisker-xml/src/test/java/org/apache/creadur/whisker/fromxml/JDomBuilderByOrganisationTest.java index 0f7fc01..3d2199a 100644 --- a/apache-whisker-xml/src/test/java/org/apache/creadur/whisker/fromxml/JDomBuilderByOrganisationTest.java +++ b/apache-whisker-xml/src/test/java/org/apache/creadur/whisker/fromxml/JDomBuilderByOrganisationTest.java @@ -18,58 +18,65 @@ */ package org.apache.creadur.whisker.fromxml; +import static org.junit.jupiter.api.Assertions.*; + import java.util.Collection; import java.util.Collections; import java.util.HashMap; -import junit.framework.TestCase; - import org.apache.creadur.whisker.model.ByOrganisation; import org.apache.creadur.whisker.model.Organisation; import org.apache.creadur.whisker.model.Resource; import org.jdom2.Element; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** * */ -public class JDomBuilderByOrganisationTest extends TestCase { +class JDomBuilderByOrganisationTest { private JDomBuilder subject; - - @Override - protected void setUp() throws Exception { - super.setUp(); + + @BeforeEach + void setUp() throws Exception { subject = new JDomBuilder(); } - @Override - protected void tearDown() throws Exception { - super.tearDown(); + @AfterEach + void tearDown() throws Exception { } - public void testBuildResourcesFromNoResources() throws Exception { + @Test + void buildResourcesFromNoResources() throws Exception { final Collection<Resource> results = subject.collectResources(new Element("by-organisation")); - assertNotNull("Expected empty collection to be returned", results); - assertEquals("Expected collection to be empty", 0, results.size()); + assertNotNull(results, "Expected empty collection to be returned"); + assertEquals(0, results.size(), "Expected collection to be empty"); } - - public void testCollectResourcesNumbered1() throws Exception { + + @Test + void collectResourcesNumbered1() throws Exception { checkCollectResourcesNumbered(1); } - public void testCollectResourcesNumbered2() throws Exception { + @Test + void collectResourcesNumbered2() throws Exception { checkCollectResourcesNumbered(2); } - - public void testCollectResourcesNumbered3() throws Exception { + + @Test + void collectResourcesNumbered3() throws Exception { checkCollectResourcesNumbered(3); } - - public void testCollectResourcesNumbered4() throws Exception { + + @Test + void collectResourcesNumbered4() throws Exception { checkCollectResourcesNumbered(4); } - public void testOrganisationByIdThrowsIllegalArgumentWhenOrganisationsEmpty() throws Exception { + @Test + void organisationByIdThrowsIllegalArgumentWhenOrganisationsEmpty() throws Exception { try { subject.organisation( new Element("by-organisation").setAttribute("id", "some id"), @@ -83,7 +90,8 @@ public class JDomBuilderByOrganisationTest extends TestCase { } } - public void testOrganisationByIdThrowsIllegalArgumentWhenOrganisationsMissing() throws Exception { + @Test + void organisationByIdThrowsIllegalArgumentWhenOrganisationsMissing() throws Exception { try { final HashMap<String, Organisation> map = new HashMap<String, Organisation>(); new Organisation("BOGUS", "name", "url").storeIn(map); @@ -99,27 +107,32 @@ public class JDomBuilderByOrganisationTest extends TestCase { } } - public void testOrganisationByIdFindsOrganisationsPresent() throws Exception { + @Test + void organisationByIdFindsOrganisationsPresent() throws Exception { final String idValue = "some id"; final HashMap<String, Organisation> map = new HashMap<String, Organisation>(); final Organisation expected = new Organisation(idValue, "name", "url"); expected.storeIn(map); - assertEquals("Expected organisation with matching ID to be found", expected, + assertEquals(expected, subject.organisation( new Element("by-organisation").setAttribute("id", idValue), - Collections.unmodifiableMap(map))); + Collections.unmodifiableMap(map)), + "Expected organisation with matching ID to be found"); } - public void testByOrganisationBuildsFromOrganisationAndElementWith3ChildResources() throws Exception { + @Test + void byOrganisationBuildsFromOrganisationAndElementWith3ChildResources() throws Exception { checkOrganisationAndElementBuild(3); } - public void testByOrganisationBuildsFromOrganisationAndElementWith5ChildResources() throws Exception { + @Test + void byOrganisationBuildsFromOrganisationAndElementWith5ChildResources() throws Exception { checkOrganisationAndElementBuild(5); } - public void testByOrganisationBuildsFromOrganisationAndElementWith10ChildResources() throws Exception { + @Test + void byOrganisationBuildsFromOrganisationAndElementWith10ChildResources() throws Exception { checkOrganisationAndElementBuild(10); } @@ -133,43 +146,51 @@ public class JDomBuilderByOrganisationTest extends TestCase { final String idValue = "some id"; final Organisation input = new Organisation(idValue, "name", "url"); final ByOrganisation result = subject.byOrganisation(byOrganisation, input); - assertNotNull("Expected builder to build", result); - assertNotNull("Expected resources to be built", result.getResources()); - assertNotNull("Expected organisation to be set", result.getOrganisation()); - assertEquals("Expected number of resources built matches children", numberOfChildResources, result.getResources().size()); - assertEquals("Expected organisation to be set to input", input, result.getOrganisation()); + assertNotNull(result, "Expected builder to build"); + assertNotNull(result.getResources(), "Expected resources to be built"); + assertNotNull(result.getOrganisation(), "Expected organisation to be set"); + assertEquals(numberOfChildResources, result.getResources().size(), "Expected number of resources built matches children"); + assertEquals(input, result.getOrganisation(), "Expected organisation to be set to input"); } - public void testByOrganisationBuildsFromMapAndElementWith1ChildResources() throws Exception { + @Test + void byOrganisationBuildsFromMapAndElementWith1ChildResources() throws Exception { checkElementAndMapBuild(1); } - - public void testByOrganisationBuildsFromMapAndElementWith5ChildResources() throws Exception { + + @Test + void byOrganisationBuildsFromMapAndElementWith5ChildResources() throws Exception { checkElementAndMapBuild(5); } - - public void testByOrganisationBuildsFromMapAndElementWith10ChildResources() throws Exception { + + @Test + void byOrganisationBuildsFromMapAndElementWith10ChildResources() throws Exception { checkElementAndMapBuild(10); } - public void testByOrganisationCollectiveOneChild()throws Exception { + @Test + void byOrganisationCollectiveOneChild() throws Exception { checkCollectByOrganisations(1); } - public void testByOrganisationCollective2Children()throws Exception { + @Test + void byOrganisationCollective2Children() throws Exception { checkCollectByOrganisations(2); } - public void testByOrganisationCollective5Child()throws Exception { + @Test + void byOrganisationCollective5Child() throws Exception { checkCollectByOrganisations(5); } - public void testByOrganisationCollective3Child()throws Exception { + @Test + void byOrganisationCollective3Child() throws Exception { checkCollectByOrganisations(3); } - - public void testByOrganisationCollective7Child()throws Exception { + + @Test + void byOrganisationCollective7Child() throws Exception { checkCollectByOrganisations(7); } @@ -187,28 +208,30 @@ public class JDomBuilderByOrganisationTest extends TestCase { new Organisation(nextIdValue, "name" + i, "url").storeIn(map); } final Collection<ByOrganisation> results = subject.collectByOrganisations(parent, map); - assertNotNull("Builder should build something", results); - assertEquals("Expected an by-organisation in collection per child", numberOfChildren, results.size()); + assertNotNull(results, "Builder should build something"); + assertEquals(numberOfChildren, results.size(), "Expected an by-organisation in collection per child"); } - - public void testByOrganisationEmptyCollective()throws Exception { + + @Test + void byOrganisationEmptyCollective() throws Exception { final Element parent = new Element("with-license"); final Organisation input = new Organisation("id", "name", "url"); final HashMap<String, Organisation> map = new HashMap<String, Organisation>(); input.storeIn(map); final Collection<ByOrganisation> results = subject.collectByOrganisations(parent, map); - assertNotNull("Builder should build something", results); - assertTrue("No children so expected an empty collection", results.isEmpty()); + assertNotNull(results, "Builder should build something"); + assertTrue(results.isEmpty(), "No children so expected an empty collection"); } - - public void testByOrganisationCollectiveUnmodifiable()throws Exception { + + @Test + void byOrganisationCollectiveUnmodifiable() throws Exception { final Element parent = new Element("with-license"); final Organisation input = new Organisation("id", "name", "url"); final HashMap<String, Organisation> map = new HashMap<String, Organisation>(); input.storeIn(map); final Collection<ByOrganisation> results = subject.collectByOrganisations(parent, map); - assertNotNull("Builder should build something", results); + assertNotNull(results, "Builder should build something"); try { results.clear(); fail("Expected collection to be unmodifiable"); @@ -228,11 +251,11 @@ public class JDomBuilderByOrganisationTest extends TestCase { final HashMap<String, Organisation> map = new HashMap<String, Organisation>(); input.storeIn(map); final ByOrganisation result = subject.byOrganisation(byOrganisation, map); - assertNotNull("Expected builder to build", result); - assertNotNull("Expected resources to be built", result.getResources()); - assertNotNull("Expected organisation to be set", result.getOrganisation()); - assertEquals("Expected number of resources built matches children", numberOfChildResources, result.getResources().size()); - assertEquals("Expected organisation to be set to input", input, result.getOrganisation()); + assertNotNull(result, "Expected builder to build"); + assertNotNull(result.getResources(), "Expected resources to be built"); + assertNotNull(result.getOrganisation(), "Expected organisation to be set"); + assertEquals(numberOfChildResources, result.getResources().size(), "Expected number of resources built matches children"); + assertEquals(input, result.getOrganisation(), "Expected organisation to be set to input"); } @@ -242,8 +265,8 @@ public class JDomBuilderByOrganisationTest extends TestCase { */ private void checkCollectResourcesNumbered(final int numberOfResources) { final Collection<Resource> results = subject.collectResources(withChildResources(numberOfResources)); - assertNotNull("Expected empty collection to be returned", results); - assertEquals("Expected collection to be empty", numberOfResources, results.size()); + assertNotNull(results, "Expected empty collection to be returned"); + assertEquals(numberOfResources, results.size(), "Expected collection to be empty"); } /** diff --git a/apache-whisker-xml/src/test/java/org/apache/creadur/whisker/fromxml/JDomBuilderLicenseTest.java b/apache-whisker-xml/src/test/java/org/apache/creadur/whisker/fromxml/JDomBuilderLicenseTest.java index 8cc80bd..6b569c4 100644 --- a/apache-whisker-xml/src/test/java/org/apache/creadur/whisker/fromxml/JDomBuilderLicenseTest.java +++ b/apache-whisker-xml/src/test/java/org/apache/creadur/whisker/fromxml/JDomBuilderLicenseTest.java @@ -18,31 +18,34 @@ */ package org.apache.creadur.whisker.fromxml; +import static org.junit.jupiter.api.Assertions.*; + import org.apache.creadur.whisker.model.License; -import junit.framework.TestCase; import org.jdom2.CDATA; import org.jdom2.Element; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** * */ -public class JDomBuilderLicenseTest extends TestCase { +class JDomBuilderLicenseTest { private JDomBuilder subject; - - @Override - protected void setUp() throws Exception { - super.setUp(); + + @BeforeEach + void setUp() throws Exception { subject = new JDomBuilder(); } - @Override - protected void tearDown() throws Exception { - super.tearDown(); + @AfterEach + void tearDown() throws Exception { } - - public void testLicenseWithNameUrl() throws Exception { + + @Test + void licenseWithNameUrl() throws Exception { checkSetNameUrlId("a name", "some url", "some id"); checkSetNameUrlId("name", "url", "id"); checkSetNameUrlId("NAME", "URL", "ID"); @@ -60,37 +63,42 @@ public class JDomBuilderLicenseTest extends TestCase { .setAttribute("name", nameValue) .setAttribute("url", urlValue) .setAttribute("id", idValue)); - assertNotNull("Builder should build", result); - assertEquals("Set id", idValue, result.getId()); - assertEquals("Set url", urlValue, result.getURL()); - assertEquals("Set name", nameValue, result.getName()); + assertNotNull(result, "Builder should build"); + assertEquals(idValue, result.getId(), "Set id"); + assertEquals(urlValue, result.getURL(), "Set url"); + assertEquals(nameValue, result.getName(), "Set name"); } - - public void testLicenseRequiresSourceTrue() throws Exception { - assertTrue("Expected required source to be set", licenseWithSource("yes").isSourceRequired()); + + @Test + void licenseRequiresSourceTrue() throws Exception { + assertTrue(licenseWithSource("yes").isSourceRequired(), "Expected required source to be set"); } - - public void testLicenseRequiresSourceTrueAllCaps() throws Exception { - assertTrue("Expected required source to be set even when yes is in all caps case. This is against the schema.", - licenseWithSource("YES").isSourceRequired()); + + @Test + void licenseRequiresSourceTrueAllCaps() throws Exception { + assertTrue(licenseWithSource("YES").isSourceRequired(), + "Expected required source to be set even when yes is in all caps case. This is against the schema."); } - - public void testLicenseRequiresSourceTrueMixedCase() throws Exception { - assertTrue("Expected required source to be set even when yes is in mixed case. This is against the schema.", - licenseWithSource("Yes").isSourceRequired()); + + @Test + void licenseRequiresSourceTrueMixedCase() throws Exception { + assertTrue(licenseWithSource("Yes").isSourceRequired(), + "Expected required source to be set even when yes is in mixed case. This is against the schema."); } - public void testLicenseRequiresSourceFalse() throws Exception { - assertFalse("Expected required source to be set", licenseWithSource("no").isSourceRequired()); + @Test + void licenseRequiresSourceFalse() throws Exception { + assertFalse(licenseWithSource("no").isSourceRequired(), "Expected required source to be set"); } - - public void testLicenseRequiresSourceDefault() throws Exception { + + @Test + void licenseRequiresSourceDefault() throws Exception { final License result = subject.license(new Element("license") .setAttribute("name", "name Value") .setAttribute("url", "urlValue") .setAttribute("id", "idValue")); - assertNotNull("Builder should build", result); - assertFalse("Expected to default to false", result.isSourceRequired()); + assertNotNull(result, "Builder should build"); + assertFalse(result.isSourceRequired(), "Expected to default to false"); } /** @@ -103,35 +111,38 @@ public class JDomBuilderLicenseTest extends TestCase { .setAttribute("url", "urlValue") .setAttribute("id", "idValue") .setAttribute("requires-source", requireSourceValue)); - assertNotNull("Builder should build", result); + assertNotNull(result, "Builder should build"); return result; } - - public void testLicenseNoParameters() throws Exception { + + @Test + void licenseNoParameters() throws Exception { final License result = subject.license(new Element("license") .setAttribute("name", "name Value") .setAttribute("url", "urlValue") .setAttribute("id", "idValue") .setContent(new Element("template"))); - assertNotNull("Builder should build", result); - assertNotNull("Builder should always set parameters even when empty", result.getExpectedParameters()); - assertTrue("No parameters in template so collection should be empty", result.getExpectedParameters().isEmpty()); + assertNotNull(result, "Builder should build"); + assertNotNull(result.getExpectedParameters(), "Builder should always set parameters even when empty"); + assertTrue(result.getExpectedParameters().isEmpty(), "No parameters in template so collection should be empty"); } - public void testLicenseOneParameter() throws Exception { + @Test + void licenseOneParameter() throws Exception { final String parameterName = "whatever"; final License result = subject.license(new Element("license") .setAttribute("name", "name Value") .setAttribute("url", "urlValue") .setAttribute("id", "idValue") .setContent(new Element("template").setContent(new Element("parameter-name").setContent(new CDATA(parameterName))))); - assertNotNull("Builder should build", result); - assertNotNull("Builder should always set parameters even when empty", result.getExpectedParameters()); - assertEquals("One parameters in template", 1, result.getExpectedParameters().size()); - assertEquals("Parameter name should be set from xml", parameterName, result.getExpectedParameters().iterator().next()); + assertNotNull(result, "Builder should build"); + assertNotNull(result.getExpectedParameters(), "Builder should always set parameters even when empty"); + assertEquals(1, result.getExpectedParameters().size(), "One parameters in template"); + assertEquals(parameterName, result.getExpectedParameters().iterator().next(), "Parameter name should be set from xml"); } - public void testLicenseTwoParameters() throws Exception { + @Test + void licenseTwoParameters() throws Exception { final String parameterName = "whatever"; final License result = subject.license(new Element("license") .setAttribute("name", "name Value") @@ -141,21 +152,22 @@ public class JDomBuilderLicenseTest extends TestCase { .addContent(new Element("parameter-name").setContent(new CDATA(parameterName))) .addContent(new Element("parameter-name").setContent(new CDATA(parameterName + "2"))) )); - assertNotNull("Builder should build", result); - assertNotNull("Builder should always set parameters even when empty", result.getExpectedParameters()); - assertEquals("One parameters in template", 2, result.getExpectedParameters().size()); + assertNotNull(result, "Builder should build"); + assertNotNull(result.getExpectedParameters(), "Builder should always set parameters even when empty"); + assertEquals(2, result.getExpectedParameters().size(), "One parameters in template"); } - - public void testLicenseBaseText() throws Exception { + + @Test + void licenseBaseText() throws Exception { final String text = "Some text"; final License result = subject.license(new Element("license") .setAttribute("name", "name Value") .setAttribute("url", "urlValue") .setAttribute("id", "idValue") .setContent(new Element("text").setContent(new CDATA(text)))); - assertNotNull("Builder should build", result); - assertEquals("Expected base text to be set", text, result.getText()); + assertNotNull(result, "Builder should build"); + assertEquals(text, result.getText(), "Expected base text to be set"); } } diff --git a/apache-whisker-xml/src/test/java/org/apache/creadur/whisker/fromxml/JDomBuilderOrganisationTest.java b/apache-whisker-xml/src/test/java/org/apache/creadur/whisker/fromxml/JDomBuilderOrganisationTest.java index 19b93e0..a503d8b 100644 --- a/apache-whisker-xml/src/test/java/org/apache/creadur/whisker/fromxml/JDomBuilderOrganisationTest.java +++ b/apache-whisker-xml/src/test/java/org/apache/creadur/whisker/fromxml/JDomBuilderOrganisationTest.java @@ -18,39 +18,44 @@ */ package org.apache.creadur.whisker.fromxml; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.fail; + import org.apache.creadur.whisker.model.Organisation; -import junit.framework.TestCase; import org.jdom2.Element; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** * */ -public class JDomBuilderOrganisationTest extends TestCase { +class JDomBuilderOrganisationTest { private JDomBuilder subject; - - @Override - protected void setUp() throws Exception { - super.setUp(); + + @BeforeEach + void setUp() throws Exception { subject = new JDomBuilder(); } - @Override - protected void tearDown() throws Exception { - super.tearDown(); + @AfterEach + void tearDown() throws Exception { } - public void testOrganisationSetsIdNameUrl() throws Exception { + @Test + void organisationSetsIdNameUrl() throws Exception { final Organisation result = subject.organisation( new Element("organisation") .setAttribute("name", "a name") .setAttribute("url", "an url") .setAttribute("id", "an id")); - assertNotNull("Builder should build an organisation", result); + assertNotNull(result, "Builder should build an organisation"); } - - public void testThrowIllegalArgumentWhenResourceIsNotOrganisation() throws Exception { + + @Test + void throwIllegalArgumentWhenResourceIsNotOrganisation() throws Exception { try { subject.organisation( new Element("bogus") diff --git a/apache-whisker-xml/src/test/java/org/apache/creadur/whisker/fromxml/JDomBuilderResourceTest.java b/apache-whisker-xml/src/test/java/org/apache/creadur/whisker/fromxml/JDomBuilderResourceTest.java index 633495e..111a71a 100644 --- a/apache-whisker-xml/src/test/java/org/apache/creadur/whisker/fromxml/JDomBuilderResourceTest.java +++ b/apache-whisker-xml/src/test/java/org/apache/creadur/whisker/fromxml/JDomBuilderResourceTest.java @@ -18,37 +18,41 @@ */ package org.apache.creadur.whisker.fromxml; +import static org.junit.jupiter.api.Assertions.*; + import org.apache.creadur.whisker.model.Resource; -import junit.framework.TestCase; import org.jdom2.Element; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** * */ -public class JDomBuilderResourceTest extends TestCase { +class JDomBuilderResourceTest { private JDomBuilder subject; - - @Override - protected void setUp() throws Exception { - super.setUp(); + + @BeforeEach + void setUp() throws Exception { subject = new JDomBuilder(); } - @Override - protected void tearDown() throws Exception { - super.tearDown(); + @AfterEach + void tearDown() throws Exception { } - public void testBuildResourceWithNameNoticeAndSourceTrimsSpacesBeforeValue() throws Exception { + @Test + void buildResourceWithNameNoticeAndSourceTrimsSpacesBeforeValue() throws Exception { checkResourceBuild(" name", "name", " notice", "notice", " source", "source"); } - public void testBuildResourceWithNameNoticeAndSourceTrimsSpaces() throws Exception { + @Test + void buildResourceWithNameNoticeAndSourceTrimsSpaces() throws Exception { checkResourceBuild(" name ", "name", " notice ", "notice", " " + " source ", "source"); @@ -56,32 +60,38 @@ public class JDomBuilderResourceTest extends TestCase { } - public void testBuildResourceWithNameNoticeAndSourceTrimsSpacesAfterValue() throws Exception { + @Test + void buildResourceWithNameNoticeAndSourceTrimsSpacesAfterValue() throws Exception { checkResourceBuild("name ", "name", "notice ", "notice", " " + "source ", "source"); } - public void testBuildResourceWithNameNoticeAndSourceTrimsWithSpacesInValue() throws Exception { + @Test + void buildResourceWithNameNoticeAndSourceTrimsWithSpacesInValue() throws Exception { checkResourceBuild(" n ame ", "n ame", " not ic e ", "not ic e", " " + "sour ce ", "sour ce"); } - public void testBuildResourceWithNameNoticeAndSourceSpacesInVaule() throws Exception { + @Test + void buildResourceWithNameNoticeAndSourceSpacesInVaule() throws Exception { checkResourceBuildWithoutSurroundingSpace("a name", "a notice", "some source"); } - - public void testBuildResourceWithNameNoticeAndSourceLowers() throws Exception { + + @Test + void buildResourceWithNameNoticeAndSourceLowers() throws Exception { checkResourceBuildWithoutSurroundingSpace("name", "notice", "source"); } - public void testBuildResourceWithNameNoticeAndSourceCaps() throws Exception { + @Test + void buildResourceWithNameNoticeAndSourceCaps() throws Exception { checkResourceBuildWithoutSurroundingSpace("NOTICE", "NOTICE", "SOURCE"); } - public void testThrowsIllegalArgumentWhenElementIsNotResource() throws Exception { + @Test + void throwsIllegalArgumentWhenElementIsNotResource() throws Exception { try { subject.resource( new Element("bogus") @@ -129,9 +139,9 @@ public class JDomBuilderResourceTest extends TestCase { .setAttribute("name", nameValue) .setAttribute("notice", noticeValue) .setAttribute("source", sourceValue)); - assertNotNull("Expected builder to build", result); - assertEquals("Name value set from xml attribute", expectedNameValue, result.getName()); - assertEquals("Notice value set from xml attribute", expectedNoticeValue, result.getNoticeId()); - assertEquals("Source value set from xml attribute", expectedSourceValue, result.getSource()); + assertNotNull(result, "Expected builder to build"); + assertEquals(expectedNameValue, result.getName(), "Name value set from xml attribute"); + assertEquals(expectedNoticeValue, result.getNoticeId(), "Notice value set from xml attribute"); + assertEquals(expectedSourceValue, result.getSource(), "Source value set from xml attribute"); } } diff --git a/apache-whisker-xml/src/test/java/org/apache/creadur/whisker/fromxml/JDomBuilderWithDirectoryTest.java b/apache-whisker-xml/src/test/java/org/apache/creadur/whisker/fromxml/JDomBuilderWithDirectoryTest.java index c63ca5c..4279629 100644 --- a/apache-whisker-xml/src/test/java/org/apache/creadur/whisker/fromxml/JDomBuilderWithDirectoryTest.java +++ b/apache-whisker-xml/src/test/java/org/apache/creadur/whisker/fromxml/JDomBuilderWithDirectoryTest.java @@ -18,6 +18,9 @@ */ package org.apache.creadur.whisker.fromxml; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + import java.util.Collection; import java.util.Collections; import java.util.HashMap; @@ -28,28 +31,29 @@ import org.apache.creadur.whisker.model.License; import org.apache.creadur.whisker.model.Organisation; import org.apache.creadur.whisker.model.WithinDirectory; -import junit.framework.TestCase; import org.jdom2.Element; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** * */ -public class JDomBuilderWithDirectoryTest extends TestCase { +class JDomBuilderWithDirectoryTest { private JDomBuilder subject; - - @Override - protected void setUp() throws Exception { - super.setUp(); + + @BeforeEach + void setUp() throws Exception { subject = new JDomBuilder(); } - @Override - protected void tearDown() throws Exception { - super.tearDown(); + @AfterEach + void tearDown() throws Exception { } - - public void testBuildWithinDirectorySetsLicenses() throws Exception { + + @Test + void buildWithinDirectorySetsLicenses() throws Exception { for(int i=0;i<101;i++) { checkWithinLicenses(i); } @@ -61,9 +65,9 @@ public class JDomBuilderWithDirectoryTest extends TestCase { final Element element = withLicense(numberOfOrgs, licenses); final WithinDirectory result = subject.withinDirectory( element.setAttribute("dir", "a name"), licenses, organisations); - assertNotNull("Builder should build", result); - assertNotNull("Builder should build licenses", result.getLicenses()); - assertEquals("Builder should set licenses", numberOfOrgs, result.getLicenses().size()); + assertNotNull(result, "Builder should build"); + assertNotNull(result.getLicenses(), "Builder should build licenses"); + assertEquals(numberOfOrgs, result.getLicenses().size(), "Builder should set licenses"); } @SuppressWarnings("unchecked") @@ -77,8 +81,9 @@ public class JDomBuilderWithDirectoryTest extends TestCase { } return element; } - - public void testBuildWithinDirectorySetsPublicDomain() throws Exception { + + @Test + void buildWithinDirectorySetsPublicDomain() throws Exception { for (int i=0;i<101;i++) { checkWithinPublicDomain(i); } @@ -90,22 +95,24 @@ public class JDomBuilderWithDirectoryTest extends TestCase { final Element element = withPublicDomain(numberOfOrgs, organisations); final WithinDirectory result = subject.withinDirectory( element.setAttribute("dir", "a name"), licenses, organisations); - assertNotNull("Builder should build", result); - assertNotNull("Builder should build public domain", result.getPublicDomain()); - assertEquals("Builder should set public domain", numberOfOrgs, result.getPublicDomain().size()); + assertNotNull(result, "Builder should build"); + assertNotNull(result.getPublicDomain(), "Builder should build public domain"); + assertEquals(numberOfOrgs, result.getPublicDomain().size(), "Builder should set public domain"); } - - public void testBuildWithinDirectorySetsDirectoryName() throws Exception { + + @Test + void buildWithinDirectorySetsDirectoryName() throws Exception { final Map<String, License> licenses = new HashMap<String, License>(); final Map<String, Organisation> organisations = new HashMap<String, Organisation> (); final String expected = "a name"; final WithinDirectory result = subject.withinDirectory( new Element("within").setAttribute("dir", expected), licenses, organisations); - assertNotNull("Builder should build", result); - assertEquals("Builder should set name from dir", expected, result.getName()); + assertNotNull(result, "Builder should build"); + assertEquals(expected, result.getName(), "Builder should set name from dir"); } - - public void testCollectPublicDomainOrgs() throws Exception { + + @Test + void collectPublicDomainOrgs() throws Exception { for (int i=0;i<256;i++) { checkPublicDomainOrg(i); } @@ -117,8 +124,8 @@ public class JDomBuilderWithDirectoryTest extends TestCase { final Collection<ByOrganisation> results = subject.publicDomain( organisations, element); - assertNotNull("Expected builder to build", results); - assertEquals("Expected one organisation per child of public domain",numberOfOrgs, results.size()); + assertNotNull(results, "Expected builder to build"); + assertEquals(numberOfOrgs, results.size(), "Expected one organisation per child of public domain"); } private Element withPublicDomain(int numberOfOrgs, diff --git a/apache-whisker-xml/src/test/java/org/apache/creadur/whisker/fromxml/JDomBuilderWithLicenseTest.java b/apache-whisker-xml/src/test/java/org/apache/creadur/whisker/fromxml/JDomBuilderWithLicenseTest.java index 78ccb1e..175b9f6 100644 --- a/apache-whisker-xml/src/test/java/org/apache/creadur/whisker/fromxml/JDomBuilderWithLicenseTest.java +++ b/apache-whisker-xml/src/test/java/org/apache/creadur/whisker/fromxml/JDomBuilderWithLicenseTest.java @@ -18,39 +18,41 @@ */ package org.apache.creadur.whisker.fromxml; +import static org.junit.jupiter.api.Assertions.*; + import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.Map; -import junit.framework.TestCase; - import org.apache.creadur.whisker.model.License; import org.apache.creadur.whisker.model.Organisation; import org.apache.creadur.whisker.model.WithLicense; import org.jdom2.CDATA; import org.jdom2.Element; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** * */ -public class JDomBuilderWithLicenseTest extends TestCase { +class JDomBuilderWithLicenseTest { private JDomBuilder subject; - - @Override - protected void setUp() throws Exception { - super.setUp(); + + @BeforeEach + void setUp() throws Exception { subject = new JDomBuilder(); } - @Override - protected void tearDown() throws Exception { - super.tearDown(); + @AfterEach + void tearDown() throws Exception { } - public void testLicenseFromListThrowsMissingIDWhenEmpty() throws Exception { + @Test + void licenseFromListThrowsMissingIDWhenEmpty() throws Exception { final Map<String, License> licenses = new HashMap<String, License>(); try { subject.license(new Element("with-license").setAttribute("id", "id"), licenses); @@ -59,8 +61,9 @@ public class JDomBuilderWithLicenseTest extends TestCase { // expected } } - - public void testLicenseFromListThrowsMissingIDWhenIDsAreMismatched() throws Exception { + + @Test + void licenseFromListThrowsMissingIDWhenIDsAreMismatched() throws Exception { final Map<String, License> licenses = new HashMap<String, License>(); addLicenseTo(licenses, "noise"); try { @@ -70,8 +73,9 @@ public class JDomBuilderWithLicenseTest extends TestCase { // expected } } - - public void testLicenseFromListFindsLicense() throws Exception { + + @Test + void licenseFromListFindsLicense() throws Exception { final String id = "id"; final Map<String, License> licenses = new HashMap<String, License>(); @@ -81,8 +85,8 @@ public class JDomBuilderWithLicenseTest extends TestCase { addLicenseTo(licenses, "noise"); final License output = subject.license(new Element("with-license").setAttribute("id", id), licenses); - assertNotNull("Expected builder to build", output); - assertEquals("Expected license to be found", expected, output); + assertNotNull(output, "Expected builder to build"); + assertEquals(expected, output, "Expected license to be found"); } /** @@ -96,11 +100,13 @@ public class JDomBuilderWithLicenseTest extends TestCase { return new License(false, "", Collections.EMPTY_LIST, id, "noise url", "name").storeIn(licenses); } - public void testBuildLicenseFromElementWithCopyrightNotice() throws Exception { + @Test + void buildLicenseFromElementWithCopyrightNotice() throws Exception { checkSetCopyrightNotice("Some Copyright Text", "Some Copyright Text"); } - public void testBuildLicenseFromElementWithCopyrightNoticeTrimSpaces() throws Exception { + @Test + void buildLicenseFromElementWithCopyrightNoticeTrimSpaces() throws Exception { checkSetCopyrightNotice(" Some Copyright Text ", "Some Copyright Text"); } @@ -119,11 +125,12 @@ public class JDomBuilderWithLicenseTest extends TestCase { .setAttribute("id", id) .addContent(new Element("copyright-notice").setContent(new CDATA(copyrightNotice))) , licenses, organisations); - assertNotNull("Expected builder to build", output); - assertEquals("Builder should set copyright notice from xml", expectCopyrightNotice, output.getCopyrightNotice()); + assertNotNull(output, "Expected builder to build"); + assertEquals(expectCopyrightNotice, output.getCopyrightNotice(), "Builder should set copyright notice from xml"); } - - public void testBuildLicenseFromElementNoCopyrightNoticeNoParameters() throws Exception { + + @Test + void buildLicenseFromElementNoCopyrightNoticeNoParameters() throws Exception { checkWithElementJustId("some id"); checkWithElementJustId("id"); checkWithElementJustId(" some id "); @@ -138,46 +145,54 @@ public class JDomBuilderWithLicenseTest extends TestCase { final Map<String, Organisation> organisations = new HashMap<String, Organisation>(); final License expected = addLicenseTo(licenses, id); final WithLicense output = subject.withLicense(new Element("with-license").setAttribute("id", id), licenses, organisations); - assertNotNull("Expected builder to build", output); - assertEquals("Expected builder to find license and set it", expected, output.getLicense()); + assertNotNull(output, "Expected builder to build"); + assertEquals(expected, output.getLicense(), "Expected builder to find license and set it"); } - - public void testBuildLicenseWithParametersIsEmptyWhenNoParameters() throws Exception { + + @Test + void buildLicenseWithParametersIsEmptyWhenNoParameters() throws Exception { final Map<String, String> results = subject.parameters( new Element("with-license") .addContent(new Element("license-parameters"))); - assertNotNull("Expected builder to build parameters", results); - assertTrue("When there are no parameters, map should be empty", results.isEmpty()); + assertNotNull(results, "Expected builder to build parameters"); + assertTrue(results.isEmpty(), "When there are no parameters, map should be empty"); } - - - public void testBuildLicenseWithOneParameter() throws Exception { + + + @Test + void buildLicenseWithOneParameter() throws Exception { checkBuildLicenseWithParameters(1); } - public void testBuildLicenseWithTwoParameters() throws Exception { + @Test + void buildLicenseWithTwoParameters() throws Exception { checkBuildLicenseWithParameters(2); } - public void testBuildLicenseWith3Parameters() throws Exception { + @Test + void buildLicenseWith3Parameters() throws Exception { checkBuildLicenseWithParameters(3); } - - public void testBuildLicenseWith4Parameters() throws Exception { + + @Test + void buildLicenseWith4Parameters() throws Exception { checkBuildLicenseWithParameters(4); } - - public void testBuildLicenseWith7Parameters() throws Exception { + + @Test + void buildLicenseWith7Parameters() throws Exception { checkBuildLicenseWithParameters(7); } - - public void testBuildLicenseWith11Parameters() throws Exception { + + @Test + void buildLicenseWith11Parameters() throws Exception { checkBuildLicenseWithParameters(11); } - public void testBuildLicenseWith101Parameters() throws Exception { + @Test + void buildLicenseWith101Parameters() throws Exception { checkBuildLicenseWithParameters(101); } @@ -196,14 +211,15 @@ public class JDomBuilderWithLicenseTest extends TestCase { .addContent(licenseParametersElement); final Map<String, String> results = subject.parameters(input); - assertNotNull("Expected builder to build parameters", results); - assertEquals("Expected builder to add one name, value pair per parameter", numberOfParameters, results.size()); + assertNotNull(results, "Expected builder to build parameters"); + assertEquals(numberOfParameters, results.size(), "Expected builder to add one name, value pair per parameter"); for (int i=0;i<numberOfParameters;i++) { - assertEquals("Value indexed by name", results.get(name(i)), value(i)); + assertEquals(results.get(name(i)), value(i), "Value indexed by name"); } } - public void testWithLicenseBuildWithParameters() throws Exception { + @Test + void withLicenseBuildWithParameters() throws Exception { for (int i=0;i<128;i++) { checkBuildWithLicenseWithParameters(i); } @@ -229,10 +245,10 @@ public class JDomBuilderWithLicenseTest extends TestCase { .addContent(licenseParametersElement); final Map<String, String> results = subject.withLicense(input, licenses, organisations).getParameters(); - assertNotNull("Expected builder to build parameters", results); - assertEquals("Expected builder to add one name, value pair per parameter", numberOfParameters, results.size()); + assertNotNull(results, "Expected builder to build parameters"); + assertEquals(numberOfParameters, results.size(), "Expected builder to add one name, value pair per parameter"); for (int i=0;i<numberOfParameters;i++) { - assertEquals("Value indexed by name", results.get(name(i)), value(i)); + assertEquals(results.get(name(i)), value(i), "Value indexed by name"); } } @@ -252,8 +268,9 @@ public class JDomBuilderWithLicenseTest extends TestCase { private String value(int i) { return "value" + i; } - - public void testBuildLicenseWithParametersThrowsExceptionWhenParameterIsDuplicated() throws Exception { + + @Test + void buildLicenseWithParametersThrowsExceptionWhenParameterIsDuplicated() throws Exception { try { subject.parameters( new Element("with-license") @@ -269,8 +286,9 @@ public class JDomBuilderWithLicenseTest extends TestCase { // expected } } - - public void testBuildCollectWithLicenses() throws Exception { + + @Test + void buildCollectWithLicenses() throws Exception { for (int i=0; i<256; i++) { checkCollectWithLicenses(i); } @@ -290,8 +308,8 @@ public class JDomBuilderWithLicenseTest extends TestCase { } final Collection<WithLicense> results = subject.withLicenses(licenses, organisations, parent); - assertNotNull("Builder should build", results); - assertEquals("Builder should build one with-license for each child", numberOfWithLicenses, results.size()); + assertNotNull(results, "Builder should build"); + assertEquals(numberOfWithLicenses, results.size(), "Builder should build one with-license for each child"); } /** diff --git a/apache-whisker-xml/src/test/java/org/apache/creadur/whisker/fromxml/JDomBuilderWorkTest.java b/apache-whisker-xml/src/test/java/org/apache/creadur/whisker/fromxml/JDomBuilderWorkTest.java index 2c0bab9..acc325e 100644 --- a/apache-whisker-xml/src/test/java/org/apache/creadur/whisker/fromxml/JDomBuilderWorkTest.java +++ b/apache-whisker-xml/src/test/java/org/apache/creadur/whisker/fromxml/JDomBuilderWorkTest.java @@ -18,6 +18,8 @@ */ package org.apache.creadur.whisker.fromxml; +import static org.junit.jupiter.api.Assertions.*; + import java.util.ArrayList; import java.util.Calendar; import java.util.Collection; @@ -26,44 +28,45 @@ import java.util.HashMap; import java.util.HashSet; import java.util.Map; -import junit.framework.TestCase; - import org.apache.creadur.whisker.model.License; import org.apache.creadur.whisker.model.Organisation; import org.apache.creadur.whisker.model.WithinDirectory; import org.jdom2.CDATA; import org.jdom2.Document; import org.jdom2.Element; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** * */ -public class JDomBuilderWorkTest extends TestCase { +class JDomBuilderWorkTest { private JDomBuilder subject; - - @Override - protected void setUp() throws Exception { - super.setUp(); + + @BeforeEach + void setUp() throws Exception { subject = new JDomBuilder(); } - @Override - protected void tearDown() throws Exception { - super.tearDown(); + @AfterEach + void tearDown() throws Exception { } - public void testMapNoticesIsEmptyWhenDocumentHasNoNotices() throws Exception { + @Test + void mapNoticesIsEmptyWhenDocumentHasNoNotices() throws Exception { final Map<String, String> results = subject.mapNotices(new Document().setRootElement(new Element("manifest"))); - assertNotNull("Builder should build something", results); - assertTrue("Should be empty when no licenses present", results.isEmpty()); + assertNotNull(results, "Builder should build something"); + assertTrue(results.isEmpty(), "Should be empty when no licenses present"); } - - public void testMapNoticesExpectedToBeImmutable() throws Exception { + + @Test + void mapNoticesExpectedToBeImmutable() throws Exception { final Map<String, String> results = subject.mapNotices(new Document().setRootElement(new Element("manifest"))); - assertNotNull("Expected builder to build something", results); + assertNotNull(results, "Expected builder to build something"); try { results.put("whatever", "next"); fail("Expected map to be immutable"); @@ -72,8 +75,9 @@ public class JDomBuilderWorkTest extends TestCase { } } - - public void testMapNoticesFindsNoticesDefinedInDocument() throws Exception { + + @Test + void mapNoticesFindsNoticesDefinedInDocument() throws Exception { for (int i=0; i<256; i++) { checkMapNoticesWith(i); } @@ -93,25 +97,27 @@ public class JDomBuilderWorkTest extends TestCase { new Element("notice").setAttribute("id", combine(baseId, i)).addContent(new CDATA(combine(baseText, i)))); } final Map<String, String> results = subject.mapNotices(in); - assertEquals("One license in map for each in the document", numberOfLicenses, results.size()); + assertEquals(numberOfLicenses, results.size(), "One license in map for each in the document"); for (int i=0;i<numberOfLicenses;i++) { final String next = results.get(combine(baseId, i)); - assertNotNull("Expected organisation to be stored", next); - assertEquals("Expected correct organisation to be stored", next, combine(baseText, i)); + assertNotNull(next, "Expected organisation to be stored"); + assertEquals(next, combine(baseText, i), "Expected correct organisation to be stored"); } } - - public void testMapLicensesIsEmptyWhenDocumentHasNoLicenses() throws Exception { + + @Test + void mapLicensesIsEmptyWhenDocumentHasNoLicenses() throws Exception { final Map<String, License> results = subject.mapLicenses(new Document().setRootElement(new Element("manifest"))); - assertNotNull("Builder should build something", results); - assertTrue("Should be empty when no licenses present", results.isEmpty()); + assertNotNull(results, "Builder should build something"); + assertTrue(results.isEmpty(), "Should be empty when no licenses present"); } - - public void testMapLicensesExpectedToBeImmutable() throws Exception { + + @Test + void mapLicensesExpectedToBeImmutable() throws Exception { final Map<String, License> results = subject.mapLicenses(new Document().setRootElement(new Element("manifest"))); - assertNotNull("Expected builder to build something", results); + assertNotNull(results, "Expected builder to build something"); try { results.put("whatever", new License(true, "", new ArrayList<String>(), "", "", "")); fail("Expected map to be immutable"); @@ -119,8 +125,9 @@ public class JDomBuilderWorkTest extends TestCase { // Expected } } - - public void testMapLicensesFindsLicensesDefinedInDocument() throws Exception { + + @Test + void mapLicensesFindsLicensesDefinedInDocument() throws Exception { for (int i=0; i<256; i++) { checkMapLicensesWith(i); } @@ -140,26 +147,28 @@ public class JDomBuilderWorkTest extends TestCase { new Element("license").setAttribute("id", combine(baseId, i)).setAttribute("name", combine(baseName, i))); } final Map<String, License> results = subject.mapLicenses(in); - assertEquals("One license in map for each in the document", numberOfLicenses, results.size()); + assertEquals(numberOfLicenses, results.size(), "One license in map for each in the document"); for (int i=0;i<numberOfLicenses;i++) { final License next = results.get(combine(baseId, i)); - assertNotNull("Expected organisation to be stored", next); - assertEquals("Expected correct organisation to be stored", next.getName(), combine(baseName, i)); + assertNotNull(next, "Expected organisation to be stored"); + assertEquals(next.getName(), combine(baseName, i), "Expected correct organisation to be stored"); } } - - public void testMapOrganisationsIsEmptyWhenDocumentHasNoOrganisations() throws Exception { + + @Test + void mapOrganisationsIsEmptyWhenDocumentHasNoOrganisations() throws Exception { final Map<String, Organisation> results = subject.mapOrganisations(new Document().setRootElement(new Element("manifest"))); - assertNotNull("Expected builder to build something", results); - assertTrue("Expected builder to build empty map when document has no documents", results.isEmpty()); + assertNotNull(results, "Expected builder to build something"); + assertTrue(results.isEmpty(), "Expected builder to build empty map when document has no documents"); } - - public void testMapOrganisationsExpectedToBeImmutable() throws Exception { + + @Test + void mapOrganisationsExpectedToBeImmutable() throws Exception { final Map<String, Organisation> results = subject.mapOrganisations(new Document().setRootElement(new Element("manifest"))); - assertNotNull("Expected builder to build something", results); + assertNotNull(results, "Expected builder to build something"); try { results.put("whatever", new Organisation("", "", "")); fail("Expected map to be immutable"); @@ -167,8 +176,9 @@ public class JDomBuilderWorkTest extends TestCase { // Expected } } - - public void testMapOrganisationsFindOrganisationDefinedInDocument() throws Exception { + + @Test + void mapOrganisationsFindOrganisationDefinedInDocument() throws Exception { for (int i=1;i<256;i++) { checkMapOrganisationsWith(i); } @@ -188,11 +198,11 @@ public class JDomBuilderWorkTest extends TestCase { new Element("organisation").setAttribute("id", combine(baseId, i)).setAttribute("name", combine(baseName, i))); } final Map<String, Organisation> results = subject.mapOrganisations(in); - assertEquals("One organisation in map for each in the document", numberOfOrganisations, results.size()); + assertEquals(numberOfOrganisations, results.size(), "One organisation in map for each in the document"); for (int i=0;i<numberOfOrganisations;i++) { final Organisation next = results.get(combine(baseId, i)); - assertNotNull("Expected organisation to be stored", next); - assertEquals("Expected correct organisation to be stored", next.getName(), combine(baseName, i)); + assertNotNull(next, "Expected organisation to be stored"); + assertEquals(next.getName(), combine(baseName, i), "Expected correct organisation to be stored"); } } @@ -215,8 +225,9 @@ public class JDomBuilderWorkTest extends TestCase { final String id) { return new License(false, "", Collections.EMPTY_LIST, id, "noise url", "name").storeIn(licenses); } - - public void testPrimaryLicense() throws Exception { + + @Test + void primaryLicense() throws Exception { final String id = "The primary ID"; final Map<String, License> licenses = new HashMap<String, License> (); @SuppressWarnings("unchecked") @@ -225,27 +236,30 @@ public class JDomBuilderWorkTest extends TestCase { addLicenseTo(licenses, "noise"); final License result = subject.primaryLicense(new Document().setRootElement(new Element("manifest"). addContent(new Element("primary-license").setAttribute("id", id))), licenses); - assertNotNull("Builder should find primary license", result); - assertEquals("Builder should find primary licenser", expected, result); + assertNotNull(result, "Builder should find primary license"); + assertEquals(expected, result, "Builder should find primary licenser"); } - public void testNoPrimaryCopyright() throws Exception { + @Test + void noPrimaryCopyright() throws Exception { final String primaryCopyrightNotice = subject.primaryCopyrightNotice(new Document().setRootElement(new Element("manifest"). addContent(new Element("primary-license").setAttribute("id", "The primary ID")))); - assertNull("Builder should only set primary copyright when present", primaryCopyrightNotice); + assertNull(primaryCopyrightNotice, "Builder should only set primary copyright when present"); } - public void testPrimaryCopyright() throws Exception { + @Test + void primaryCopyright() throws Exception { final String copyrightNoticeSet = "Some Copyright Claim"; final String result = subject.primaryCopyrightNotice(new Document().setRootElement(new Element("manifest"). addContent( new Element("primary-license").setAttribute("id", "The primary ID") .addContent( new Element("copyright-notice").addContent(copyrightNoticeSet))))); - assertEquals("Builder should set primary copyright notice", copyrightNoticeSet, result); + assertEquals(copyrightNoticeSet, result, "Builder should set primary copyright notice"); } - public void testBuildPrimaryCopyright() throws Exception { + @Test + void buildPrimaryCopyright() throws Exception { final String copyrightNoticeSet = "Some Copyright Claim"; final String result = subject.build(new Document().setRootElement( new Element("manifest") @@ -257,10 +271,11 @@ public class JDomBuilderWorkTest extends TestCase { .addContent( new Element("copyright-notice").addContent(copyrightNoticeSet)))) ).getPrimaryCopyrightNotice(); - assertEquals("Builder should set primary copyright notice", copyrightNoticeSet, result); + assertEquals(copyrightNoticeSet, result, "Builder should set primary copyright notice"); } - - public void testThrowsMissingIDExceptionWhenPrimaryLicenseMissing() throws Exception { + + @Test + void throwsMissingIDExceptionWhenPrimaryLicenseMissing() throws Exception { final String id = "The primary ID"; final Map<String, License> licenses = new HashMap<String, License> (); addLicenseTo(licenses, "noise"); @@ -272,54 +287,60 @@ public class JDomBuilderWorkTest extends TestCase { // expected } } - - public void testPrimaryNoticeFindsNoticeText() throws Exception { + + @Test + void primaryNoticeFindsNoticeText() throws Exception { final String noticeText = "Some sort of notice"; final String result = subject.primaryNotice(new Document().setRootElement( new Element("manifest").addContent( new Element("primary-notice").addContent(new CDATA(noticeText))))); - assertEquals("Expected builder to find the text of the primary notice element", noticeText, result); + assertEquals(noticeText, result, "Expected builder to find the text of the primary notice element"); } - - public void testPrimaryNoticeIsNullWhenThereIsNoNoticeText() throws Exception { + + @Test + void primaryNoticeIsNullWhenThereIsNoNoticeText() throws Exception { final String result = subject.primaryNotice(new Document().setRootElement( new Element("manifest"))); - assertNull("When there is no primary notice, expect null", result); + assertNull(result, "When there is no primary notice, expect null"); } - public void testPrimaryNoticeSubstitutesYearInNoticeText() throws Exception { + @Test + void primaryNoticeSubstitutesYearInNoticeText() throws Exception { final String noticeBaseText = "Some sort of notice"; final String result = subject.primaryNotice(new Document().setRootElement( new Element("manifest").addContent( new Element("primary-notice").addContent(new CDATA(noticeBaseText + "${year}"))))); - assertEquals("Expected builder to find the text of the primary notice element", - noticeBaseText + Calendar.getInstance().get(Calendar.YEAR), result); + assertEquals(noticeBaseText + Calendar.getInstance().get(Calendar.YEAR), result, "Expected builder to find the text of the primary notice element"); } - public void testFindPrimaryOrganisationIdReturnsNullWhenOrganisationUnset() throws Exception { + @Test + void findPrimaryOrganisationIdReturnsNullWhenOrganisationUnset() throws Exception { final String result = subject.primaryOrganisationId(new Document().setRootElement(new Element("manifest"))); - assertNull("Primary organisation is optional, and null should be returned when unset", result); + assertNull(result, "Primary organisation is optional, and null should be returned when unset"); } - - public void testFindPrimaryOrganisationIdWhenSet() throws Exception { + + @Test + void findPrimaryOrganisationIdWhenSet() throws Exception { final String idValue = "An ID value"; final String result = subject.primaryOrganisationId( new Document().setRootElement( new Element("manifest").addContent( new Element("primary-organisation").setAttribute("id", idValue)))); - assertEquals("When set, builder should find value", idValue, result); + assertEquals(idValue, result, "When set, builder should find value"); } - - public void testCollectContentsReturneEmptyWhenDocumentHasNoContents() throws Exception { + + @Test + void collectContentsReturneEmptyWhenDocumentHasNoContents() throws Exception { final Collection<WithinDirectory> results = subject.collectContents( new Document().setRootElement(new Element("manifest")), new HashMap<String, License>(), new HashMap<String, Organisation>()); - assertNotNull("Builder should build something", results); - assertTrue("Collection should be empty when there are no contents", results.isEmpty()); + assertNotNull(results, "Builder should build something"); + assertTrue(results.isEmpty(), "Collection should be empty when there are no contents"); } - - - public void testCollectDirectoriesDefinedInDocument() throws Exception { + + + @Test + void collectDirectoriesDefinedInDocument() throws Exception { for (int i=1;i<256;i++) { checkCollectDirectoriesWith(i); } @@ -339,17 +360,18 @@ public class JDomBuilderWorkTest extends TestCase { } final Collection<WithinDirectory> results = subject.collectContents(in, new HashMap<String, License>(), new HashMap<String, Organisation>()); - assertEquals("One organisation in map for each in the document", numberOfDirectories, results.size()); + assertEquals(numberOfDirectories, results.size(), "One organisation in map for each in the document"); final Collection<String> dirNames = new HashSet<String>(); for (final WithinDirectory within:results) { dirNames.add(within.getName()); } for (int i=0;i<numberOfDirectories;i++) { - assertTrue("", dirNames.contains(combine(baseDir,i))); + assertTrue(dirNames.contains(combine(baseDir,i)), ""); } } - - public void testCollectDirectoriesThrowsDuplicateElementExceptionWhenDirAttributeDuplicated() throws Exception { + + @Test + void collectDirectoriesThrowsDuplicateElementExceptionWhenDirAttributeDuplicated() throws Exception { final String dir = "duplicate/path"; try { subject.collectContents( diff --git a/pom.xml b/pom.xml index ea0daf9..e81ae1a 100644 --- a/pom.xml +++ b/pom.xml @@ -30,6 +30,13 @@ </parent> <dependencyManagement> <dependencies> + <dependency> + <groupId>org.junit</groupId> + <artifactId>junit-bom</artifactId> + <version>5.12.2</version> + <type>pom</type> + <scope>import</scope> + </dependency> <dependency> <groupId>${project.groupId}</groupId> <artifactId>apache-whisker-scan</artifactId> @@ -276,6 +283,11 @@ <artifactId>log4j-core</artifactId> <scope>runtime</scope> </dependency> + <dependency> + <groupId>org.junit.jupiter</groupId> + <artifactId>junit-jupiter</artifactId> + <scope>test</scope> + </dependency> </dependencies> <build> <defaultGoal>clean install</defaultGoal> @@ -342,6 +354,24 @@ </plugins> </pluginManagement> <plugins> + <!-- WHISKER-30: jUnit5 migration --> + <plugin> + <groupId>org.openrewrite.maven</groupId> + <artifactId>rewrite-maven-plugin</artifactId> + <version>6.7.0</version> + <configuration> + <activeRecipes> + <recipe>org.openrewrite.java.testing.junit5.JUnit5BestPractices</recipe> + </activeRecipes> + </configuration> + <dependencies> + <dependency> + <groupId>org.openrewrite.recipe</groupId> + <artifactId>rewrite-testing-frameworks</artifactId> + <version>3.7.0</version> + </dependency> + </dependencies> + </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-enforcer-plugin</artifactId>
