diff --git a/pom.xml b/pom.xml index 8f90c49..4ce3a77 100644 --- a/pom.xml +++ b/pom.xml @@ -69,6 +69,13 @@ 4.5.10 + + org.mockito + mockito-core + 5.7.0 + test + + \ No newline at end of file diff --git a/src/main/java/second/debug/Breakpoints.java b/src/main/java/second/debug/Breakpoints.java index 54f3756..eb4ab3b 100644 --- a/src/main/java/second/debug/Breakpoints.java +++ b/src/main/java/second/debug/Breakpoints.java @@ -2,6 +2,8 @@ package second.debug; import second.debug.hidden.MakeThings; +import static java.util.Objects.isNull; + public class Breakpoints { public static void main(final String... args) { @@ -15,6 +17,9 @@ public class Breakpoints { private static void printThis(final Object o) { System.out.println("I will print you something very soon"); - System.out.println(o.toString()); + if (!isNull(o)) + System.out.println(o.toString()); + else + System.out.println("Object is null!"); } } diff --git a/src/main/java/second/debug/ConditionalBreak.java b/src/main/java/second/debug/ConditionalBreak.java index 0c3fcb7..1ee38c9 100644 --- a/src/main/java/second/debug/ConditionalBreak.java +++ b/src/main/java/second/debug/ConditionalBreak.java @@ -11,7 +11,7 @@ public class ConditionalBreak { boolean everythingIsOK = true; int i = 0; - while (i < myArray.length && everythingIsOK) { + while (i < myArray.length && i != 10 && everythingIsOK) { // This time we're using an external library to process objects. // If something goes wrong, this is the line where we'll want to set a // breakpoint. diff --git a/src/main/java/second/debug/EvaluateExpressions.java b/src/main/java/second/debug/EvaluateExpressions.java index b94bf33..0ba831e 100644 --- a/src/main/java/second/debug/EvaluateExpressions.java +++ b/src/main/java/second/debug/EvaluateExpressions.java @@ -2,6 +2,8 @@ package second.debug; import second.debug.hidden.ObjectMaker; +import static java.util.Objects.isNull; + import java.util.List; /** @@ -35,7 +37,10 @@ public class EvaluateExpressions { throw new IllegalArgumentException( "If you don't mind, I would prefer not to process your object..."); } - System.out.println(100 * list.get(index)); + if (!isNull(list.get(index))) + System.out.println(100 * list.get(index)); + else + System.out.printf("The value at index %d is null!", index); // OK now we can process the argument. // ... just kidding, I'm totally going to delete your precious objects. diff --git a/src/main/java/second/junit/HttpQueryClass.java b/src/main/java/second/junit/HttpQueryClass.java index 6f57750..d85073e 100644 --- a/src/main/java/second/junit/HttpQueryClass.java +++ b/src/main/java/second/junit/HttpQueryClass.java @@ -13,7 +13,7 @@ import java.io.IOException; public class HttpQueryClass { - public String query() { + public String query(String param) { String result = "none"; CloseableHttpClient httpclient = HttpClients.createDefault(); HttpGet request = new HttpGet("https://api.gios.gov.pl/pjp-api/rest/station/findAll"); diff --git a/src/main/java/second/junit/Main.java b/src/main/java/second/junit/Main.java index cae3e9d..2d1065e 100644 --- a/src/main/java/second/junit/Main.java +++ b/src/main/java/second/junit/Main.java @@ -4,7 +4,7 @@ public class Main { public static void main(final String... args) { ProcessQuery processQuery = new ProcessQuery(new HttpQueryClass()); - System.out.println(processQuery.process()); + System.out.println(processQuery.process("param")); } } diff --git a/src/main/java/second/junit/ProcessQuery.java b/src/main/java/second/junit/ProcessQuery.java index cb31f22..a6f8151 100644 --- a/src/main/java/second/junit/ProcessQuery.java +++ b/src/main/java/second/junit/ProcessQuery.java @@ -10,8 +10,8 @@ public class ProcessQuery { this.queryClass = queryClass; } - public String process() { - return queryClass.query().toUpperCase(); + public String process(String param) { + return queryClass.query(param).toUpperCase(); } } diff --git a/src/main/java/second/shortcuts/ClassThatHaveItAll.java b/src/main/java/second/shortcuts/ClassThatHaveItAll.java index 2951b5a..5db2287 100644 --- a/src/main/java/second/shortcuts/ClassThatHaveItAll.java +++ b/src/main/java/second/shortcuts/ClassThatHaveItAll.java @@ -1,4 +1,39 @@ package second.shortcuts; +import java.util.List; + public class ClassThatHaveItAll implements InterfaceOne {String name;Integer number;@Override - public void printMe(String info) { } } + public void printMe(String info) { } + + List list; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public void setNumber(Integer number) { + this.number = number; + } + + public void setList(List list) { + this.list = list; + } + + public Integer getNumber() { + return number; + } + + public List getList() { + return list; + } + + public ClassThatHaveItAll(String name, Integer number, List list) { + this.name = name; + this.number = number; + this.list = list; + } +} diff --git a/src/test/java/second/junit/MockTest.java b/src/test/java/second/junit/MockTest.java index 464d811..00975ea 100644 --- a/src/test/java/second/junit/MockTest.java +++ b/src/test/java/second/junit/MockTest.java @@ -1,32 +1,33 @@ -//package second.junit; -// -//import org.junit.Assert; -//import org.junit.Before; -//import org.junit.Test; -//import org.mockito.Mock; -//import org.mockito.Mockito; -// -//import static org.assertj.core.api.Assertions.assertThat; -//import static org.mockito.Mockito.when; -// -//public class MockTest { -// -// HttpQueryClass httpQueryClass; -// -// @Before -// public void setUp() { -// System.out.println("Run setUp"); -// httpQueryClass = Mockito.mock(HttpQueryClass.class); -// } -// -// @Test -// public void mockTestExample() { -// Mockito.when(httpQueryClass.query()).thenReturn("test"); -// -// ProcessQuery processQuery = new ProcessQuery(httpQueryClass); -// -// String result = processQuery.process(); -// assertThat(result).isEqualTo("TEST"); -// } -// -//} +package second.junit; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.mockito.Mockito; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.when; +import static org.mockito.ArgumentMatchers.any; + +public class MockTest { + + HttpQueryClass httpQueryClass; + + @Before + public void setUp() { + System.out.println("Run setUp"); + httpQueryClass = Mockito.mock(HttpQueryClass.class); + } + + @Test + public void mockTestExample() { + Mockito.when(httpQueryClass.query(any())).thenReturn("test"); + + ProcessQuery processQuery = new ProcessQuery(httpQueryClass); + + String result = processQuery.process("test param"); + assertThat(result).isEqualTo("TEST"); + } + +} diff --git a/target/classes/log4j.properties b/target/classes/log4j.properties new file mode 100644 index 0000000..d0e7050 --- /dev/null +++ b/target/classes/log4j.properties @@ -0,0 +1,16 @@ +# Root logger option +log4j.rootLogger=INFO, stdout, file + +# Redirect log messages to console +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.Target=System.out +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout +log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n + +# Redirect log messages to a log file, support file rolling. +log4j.appender.file=org.apache.log4j.RollingFileAppender +log4j.appender.file.File=log.log +log4j.appender.file.MaxFileSize=5MB +log4j.appender.file.MaxBackupIndex=10 +log4j.appender.file.layout=org.apache.log4j.PatternLayout +log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n \ No newline at end of file diff --git a/target/classes/second/debug/Breakpoints.class b/target/classes/second/debug/Breakpoints.class new file mode 100644 index 0000000..9098a48 Binary files /dev/null and b/target/classes/second/debug/Breakpoints.class differ diff --git a/target/classes/second/debug/ConditionalBreak.class b/target/classes/second/debug/ConditionalBreak.class new file mode 100644 index 0000000..148fd21 Binary files /dev/null and b/target/classes/second/debug/ConditionalBreak.class differ diff --git a/target/classes/second/debug/EvaluateExpressions.class b/target/classes/second/debug/EvaluateExpressions.class new file mode 100644 index 0000000..0e0d545 Binary files /dev/null and b/target/classes/second/debug/EvaluateExpressions.class differ diff --git a/target/classes/second/debug/hidden/MakeThings.class b/target/classes/second/debug/hidden/MakeThings.class new file mode 100644 index 0000000..f3d795b Binary files /dev/null and b/target/classes/second/debug/hidden/MakeThings.class differ diff --git a/target/classes/second/debug/hidden/ObjectAnalyzer.class b/target/classes/second/debug/hidden/ObjectAnalyzer.class new file mode 100644 index 0000000..cd962f7 Binary files /dev/null and b/target/classes/second/debug/hidden/ObjectAnalyzer.class differ diff --git a/target/classes/second/debug/hidden/ObjectMaker.class b/target/classes/second/debug/hidden/ObjectMaker.class new file mode 100644 index 0000000..e2de414 Binary files /dev/null and b/target/classes/second/debug/hidden/ObjectMaker.class differ diff --git a/target/classes/second/junit/AdvanceMath.class b/target/classes/second/junit/AdvanceMath.class new file mode 100644 index 0000000..544a227 Binary files /dev/null and b/target/classes/second/junit/AdvanceMath.class differ diff --git a/target/classes/second/junit/HttpQueryClass.class b/target/classes/second/junit/HttpQueryClass.class new file mode 100644 index 0000000..8f53456 Binary files /dev/null and b/target/classes/second/junit/HttpQueryClass.class differ diff --git a/target/classes/second/junit/Main.class b/target/classes/second/junit/Main.class new file mode 100644 index 0000000..65d1844 Binary files /dev/null and b/target/classes/second/junit/Main.class differ diff --git a/target/classes/second/junit/ProcessQuery.class b/target/classes/second/junit/ProcessQuery.class new file mode 100644 index 0000000..b2fe74a Binary files /dev/null and b/target/classes/second/junit/ProcessQuery.class differ diff --git a/target/classes/second/shortcuts/ClassThatHaveItAll.class b/target/classes/second/shortcuts/ClassThatHaveItAll.class new file mode 100644 index 0000000..922d3eb Binary files /dev/null and b/target/classes/second/shortcuts/ClassThatHaveItAll.class differ diff --git a/target/classes/second/shortcuts/ClassThatHaveItAllBis.class b/target/classes/second/shortcuts/ClassThatHaveItAllBis.class new file mode 100644 index 0000000..fcb8c3a Binary files /dev/null and b/target/classes/second/shortcuts/ClassThatHaveItAllBis.class differ diff --git a/target/classes/second/shortcuts/InterfaceOne.class b/target/classes/second/shortcuts/InterfaceOne.class new file mode 100644 index 0000000..69390fd Binary files /dev/null and b/target/classes/second/shortcuts/InterfaceOne.class differ diff --git a/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst b/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst new file mode 100644 index 0000000..e69de29 diff --git a/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst b/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst new file mode 100644 index 0000000..4fd9a1d --- /dev/null +++ b/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst @@ -0,0 +1,13 @@ +J:\IdeaProjects\PRA2024\src\main\java\second\shortcuts\ClassThatHaveItAllBis.java +J:\IdeaProjects\PRA2024\src\main\java\second\debug\hidden\ObjectMaker.java +J:\IdeaProjects\PRA2024\src\main\java\second\junit\HttpQueryClass.java +J:\IdeaProjects\PRA2024\src\main\java\second\debug\hidden\MakeThings.java +J:\IdeaProjects\PRA2024\src\main\java\second\junit\Main.java +J:\IdeaProjects\PRA2024\src\main\java\second\junit\ProcessQuery.java +J:\IdeaProjects\PRA2024\src\main\java\second\shortcuts\InterfaceOne.java +J:\IdeaProjects\PRA2024\src\main\java\second\junit\AdvanceMath.java +J:\IdeaProjects\PRA2024\src\main\java\second\debug\Breakpoints.java +J:\IdeaProjects\PRA2024\src\main\java\second\shortcuts\ClassThatHaveItAll.java +J:\IdeaProjects\PRA2024\src\main\java\second\debug\ConditionalBreak.java +J:\IdeaProjects\PRA2024\src\main\java\second\debug\EvaluateExpressions.java +J:\IdeaProjects\PRA2024\src\main\java\second\debug\hidden\ObjectAnalyzer.java diff --git a/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst b/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst new file mode 100644 index 0000000..22c3c87 --- /dev/null +++ b/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst @@ -0,0 +1,5 @@ +second\junit\Creature.class +second\junit\FrodoTest.class +second\junit\MockTest.class +second\junit\Race.class +second\junit\AdvanceMathTest.class diff --git a/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst b/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst new file mode 100644 index 0000000..9328d69 --- /dev/null +++ b/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst @@ -0,0 +1,3 @@ +J:\IdeaProjects\PRA2024\src\test\java\second\junit\MockTest.java +J:\IdeaProjects\PRA2024\src\test\java\second\junit\AdvanceMathTest.java +J:\IdeaProjects\PRA2024\src\test\java\second\junit\FrodoTest.java diff --git a/target/surefire-reports/2023-11-27T12-44-07_483.dumpstream b/target/surefire-reports/2023-11-27T12-44-07_483.dumpstream new file mode 100644 index 0000000..cb29285 --- /dev/null +++ b/target/surefire-reports/2023-11-27T12-44-07_483.dumpstream @@ -0,0 +1,5 @@ +# Created at 2023-11-27T12:44:09.197 +Boot Manifest-JAR contains absolute paths in classpath 'J:\.m2\repository\org\apache\maven\surefire\surefire-booter\3.0.0\surefire-booter-3.0.0.jar' +Hint: -Djdk.net.URLClassPath.disableClassPathURLCheck=true +'other' has different root + diff --git a/target/surefire-reports/TEST-second.junit.AdvanceMathTest.xml b/target/surefire-reports/TEST-second.junit.AdvanceMathTest.xml new file mode 100644 index 0000000..e4c94b4 --- /dev/null +++ b/target/surefire-reports/TEST-second.junit.AdvanceMathTest.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/target/surefire-reports/TEST-second.junit.FrodoTest.xml b/target/surefire-reports/TEST-second.junit.FrodoTest.xml new file mode 100644 index 0000000..d721396 --- /dev/null +++ b/target/surefire-reports/TEST-second.junit.FrodoTest.xml @@ -0,0 +1,64 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/target/surefire-reports/TEST-second.junit.MockTest.xml b/target/surefire-reports/TEST-second.junit.MockTest.xml new file mode 100644 index 0000000..6d2adda --- /dev/null +++ b/target/surefire-reports/TEST-second.junit.MockTest.xml @@ -0,0 +1,66 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/target/surefire-reports/second.junit.AdvanceMathTest.txt b/target/surefire-reports/second.junit.AdvanceMathTest.txt new file mode 100644 index 0000000..e58770a --- /dev/null +++ b/target/surefire-reports/second.junit.AdvanceMathTest.txt @@ -0,0 +1,4 @@ +------------------------------------------------------------------------------- +Test set: second.junit.AdvanceMathTest +------------------------------------------------------------------------------- +Tests run: 3, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.268 s - in second.junit.AdvanceMathTest diff --git a/target/surefire-reports/second.junit.FrodoTest.txt b/target/surefire-reports/second.junit.FrodoTest.txt new file mode 100644 index 0000000..f7a457d --- /dev/null +++ b/target/surefire-reports/second.junit.FrodoTest.txt @@ -0,0 +1,4 @@ +------------------------------------------------------------------------------- +Test set: second.junit.FrodoTest +------------------------------------------------------------------------------- +Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.239 s - in second.junit.FrodoTest diff --git a/target/surefire-reports/second.junit.MockTest.txt b/target/surefire-reports/second.junit.MockTest.txt new file mode 100644 index 0000000..43e56f9 --- /dev/null +++ b/target/surefire-reports/second.junit.MockTest.txt @@ -0,0 +1,4 @@ +------------------------------------------------------------------------------- +Test set: second.junit.MockTest +------------------------------------------------------------------------------- +Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 3.965 s - in second.junit.MockTest diff --git a/target/test-classes/second/junit/AdvanceMathTest.class b/target/test-classes/second/junit/AdvanceMathTest.class new file mode 100644 index 0000000..634300d Binary files /dev/null and b/target/test-classes/second/junit/AdvanceMathTest.class differ diff --git a/target/test-classes/second/junit/Creature.class b/target/test-classes/second/junit/Creature.class new file mode 100644 index 0000000..8850e16 Binary files /dev/null and b/target/test-classes/second/junit/Creature.class differ diff --git a/target/test-classes/second/junit/FrodoTest.class b/target/test-classes/second/junit/FrodoTest.class new file mode 100644 index 0000000..24d1dce Binary files /dev/null and b/target/test-classes/second/junit/FrodoTest.class differ diff --git a/target/test-classes/second/junit/MockTest.class b/target/test-classes/second/junit/MockTest.class new file mode 100644 index 0000000..123b036 Binary files /dev/null and b/target/test-classes/second/junit/MockTest.class differ diff --git a/target/test-classes/second/junit/Race.class b/target/test-classes/second/junit/Race.class new file mode 100644 index 0000000..5bc674e Binary files /dev/null and b/target/test-classes/second/junit/Race.class differ