From 3b64d8ef4ed0cb8201de94a75ba2675ecb93d9b1 Mon Sep 17 00:00:00 2001 From: Dhawal Kapil Date: Wed, 15 Aug 2018 14:14:50 +0530 Subject: [PATCH] BAEL-8219 Fix tests for core-java, maven and core-java-io projects -Test fixes --- .../file/FilenameFilterManualTest.java | 2 +- .../people.json | 0 .../students.json | 0 .../teachers.xml | 0 .../workers.xml | 0 .../exceptionhandling/Exceptions.java | 16 +- .../com/baeldung/binding/AnimalUnitTest.java | 17 +- maven/pom.xml | 266 ++++++++++-------- 8 files changed, 158 insertions(+), 143 deletions(-) rename core-java-io/src/test/resources/{testFolder => fileNameFilterManualTestFolder}/people.json (100%) rename core-java-io/src/test/resources/{testFolder => fileNameFilterManualTestFolder}/students.json (100%) rename core-java-io/src/test/resources/{testFolder => fileNameFilterManualTestFolder}/teachers.xml (100%) rename core-java-io/src/test/resources/{testFolder => fileNameFilterManualTestFolder}/workers.xml (100%) diff --git a/core-java-io/src/test/java/com/baeldung/file/FilenameFilterManualTest.java b/core-java-io/src/test/java/com/baeldung/file/FilenameFilterManualTest.java index 47a7973b34..f9a2ce972d 100644 --- a/core-java-io/src/test/java/com/baeldung/file/FilenameFilterManualTest.java +++ b/core-java-io/src/test/java/com/baeldung/file/FilenameFilterManualTest.java @@ -18,7 +18,7 @@ public class FilenameFilterManualTest { @BeforeClass public static void setupClass() { directory = new File(FilenameFilterManualTest.class.getClassLoader() - .getResource("testFolder") + .getResource("fileNameFilterManualTestFolder") .getFile()); } diff --git a/core-java-io/src/test/resources/testFolder/people.json b/core-java-io/src/test/resources/fileNameFilterManualTestFolder/people.json similarity index 100% rename from core-java-io/src/test/resources/testFolder/people.json rename to core-java-io/src/test/resources/fileNameFilterManualTestFolder/people.json diff --git a/core-java-io/src/test/resources/testFolder/students.json b/core-java-io/src/test/resources/fileNameFilterManualTestFolder/students.json similarity index 100% rename from core-java-io/src/test/resources/testFolder/students.json rename to core-java-io/src/test/resources/fileNameFilterManualTestFolder/students.json diff --git a/core-java-io/src/test/resources/testFolder/teachers.xml b/core-java-io/src/test/resources/fileNameFilterManualTestFolder/teachers.xml similarity index 100% rename from core-java-io/src/test/resources/testFolder/teachers.xml rename to core-java-io/src/test/resources/fileNameFilterManualTestFolder/teachers.xml diff --git a/core-java-io/src/test/resources/testFolder/workers.xml b/core-java-io/src/test/resources/fileNameFilterManualTestFolder/workers.xml similarity index 100% rename from core-java-io/src/test/resources/testFolder/workers.xml rename to core-java-io/src/test/resources/fileNameFilterManualTestFolder/workers.xml diff --git a/core-java/src/main/java/com/baeldung/exceptionhandling/Exceptions.java b/core-java/src/main/java/com/baeldung/exceptionhandling/Exceptions.java index eb8b733f82..48f4b5c02b 100644 --- a/core-java/src/main/java/com/baeldung/exceptionhandling/Exceptions.java +++ b/core-java/src/main/java/com/baeldung/exceptionhandling/Exceptions.java @@ -25,11 +25,7 @@ public class Exceptions { } public List loadAllPlayers(String playersFile) throws IOException{ - try { - throw new IOException(); - } catch(IOException ex) { - throw new IllegalStateException(); - } + throw new IOException(); } public int getPlayerScoreThrows(String playerFile) throws FileNotFoundException { @@ -163,14 +159,8 @@ public class Exceptions { } } - public void throwAsGotoAntiPattern() { - try { - // bunch of code - throw new MyException(); - // second bunch of code - } catch ( MyException e ) { - // third bunch of code - } + public void throwAsGotoAntiPattern() throws MyException { + throw new MyException(); } public int getPlayerScoreSwallowingExceptionAntiPattern(String playerFile) { diff --git a/core-java/src/test/java/com/baeldung/binding/AnimalUnitTest.java b/core-java/src/test/java/com/baeldung/binding/AnimalUnitTest.java index 238990f2b4..a34640b58a 100644 --- a/core-java/src/test/java/com/baeldung/binding/AnimalUnitTest.java +++ b/core-java/src/test/java/com/baeldung/binding/AnimalUnitTest.java @@ -16,8 +16,11 @@ import org.slf4j.LoggerFactory; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertThat; +import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; +import java.util.List; + /** * Created by madhumita.g on 01-08-2018. */ @@ -66,20 +69,18 @@ public class AnimalUnitTest { int testValue = 3; animal.makeNoise(testValue); - verify(mockAppender).doAppend(captorLoggingEvent.capture()); + verify(mockAppender,times(3)).doAppend(captorLoggingEvent.capture()); - final LoggingEvent loggingEvent = captorLoggingEvent.getValue(); + final List loggingEvents = captorLoggingEvent.getAllValues(); - while (testValue != 0) { + for(LoggingEvent loggingEvent : loggingEvents) + { assertThat(loggingEvent.getLevel(), is(Level.INFO)); assertThat(loggingEvent.getFormattedMessage(), - is("generic animal noise countdown 3\n" - + "generic animal noise countdown 2\n" - + "generic animal noise countdown 1\n")); - - testValue-=1; + is("generic animal noise countdown "+testValue)); + testValue--; } } diff --git a/maven/pom.xml b/maven/pom.xml index 4f91e8717c..a24b6b16bd 100644 --- a/maven/pom.xml +++ b/maven/pom.xml @@ -1,127 +1,151 @@ - 4.0.0 - com.baeldung - maven - 0.0.1-SNAPSHOT + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + 4.0.0 + com.baeldung + maven + 0.0.1-SNAPSHOT - - parent-modules - com.baeldung - 1.0.0-SNAPSHOT - + + parent-modules + com.baeldung + 1.0.0-SNAPSHOT + - - - - maven-resources-plugin - ${maven.resources.version} - - output-resources - - - input-resources - - *.png - - true - - - - - - maven-compiler-plugin - ${maven-compiler-plugin.version} - - ${java.version} - ${java.version} - - -Xlint:unchecked - - - - - maven-surefire-plugin - ${maven-surefire-plugin.version} - - - DataTest.java - - - TestFail.java - DataCheck.java - - true - - - - maven-failsafe-plugin - ${maven.failsafe.version} - - - - integration-test - verify - - - - - - - - - maven-verifier-plugin - ${maven.verifier.version} - - input-resources/verifications.xml - - - - - verify - - - - - - maven-clean-plugin - ${maven.clean.version} - - - - output-resources - - - - - - org.codehaus.mojo - build-helper-maven-plugin - ${maven.build.helper.version} - - - generate-sources - - add-source - - - - src/main/another-src - - - - - - - + + + + maven-resources-plugin + ${maven.resources.version} + + output-resources + + + input-resources + + *.png + + true + + + + + + maven-compiler-plugin + ${maven-compiler-plugin.version} + + ${java.version} + ${java.version} + + -Xlint:unchecked + + + + + maven-surefire-plugin + ${maven-surefire-plugin.version} + + + DataTest.java + + + TestFail.java + DataCheck.java + + true + + + + maven-failsafe-plugin + ${maven.failsafe.version} + + + + integration-test + verify + + + + + + + + + maven-verifier-plugin + ${maven.verifier.version} + + input-resources/verifications.xml + + + + + verify + + + + + + maven-clean-plugin + ${maven.clean.version} + + + + output-resources + + + + + + org.codehaus.mojo + build-helper-maven-plugin + ${maven.build.helper.version} + + + generate-sources + + add-source + + + + src/main/another-src + + + + + + + - - 3.0.2 - 2.21.0 - 1.1 - 3.0.0 - 3.0.0 - Baeldung - + + + default + + + + maven-surefire-plugin + ${maven-surefire-plugin.version} + + + DataTest.java + + + TestFail.java + DataCheck.java + + true + + + + + + + + + 3.0.2 + 2.21.0 + 1.1 + 3.0.0 + 3.0.0 + Baeldung + \ No newline at end of file