diff --git a/mocks/jmockit/README.md b/mocks/jmockit/README.md new file mode 100644 index 0000000000..f5b0f5ae2b --- /dev/null +++ b/mocks/jmockit/README.md @@ -0,0 +1,7 @@ +========= + +## JMockit realated tutorials + + +### Relevant Articles: +- [JMockit 101](http://www.baeldung.com/jmockit-101) diff --git a/mocks/jmockit/pom.xml b/mocks/jmockit/pom.xml new file mode 100644 index 0000000000..8b03313a51 --- /dev/null +++ b/mocks/jmockit/pom.xml @@ -0,0 +1,68 @@ + + 4.0.0 + + + com.baeldung + mocks + 1.0.0-SNAPSHOT + ../pom.xml + + + jmockit + jmockit + + + 4.12 + 1.24 + + + 3.3 + 2.18.1 + + + + + junit + junit + ${junit.version} + test + + + + org.jmockit + jmockit + ${jmockit.version} + test + + + + + jmockit + + + src/main/resources + true + + + + + + org.apache.maven.plugins + maven-compiler-plugin + ${maven-compiler-plugin.version} + + 1.8 + 1.8 + + + + + org.apache.maven.plugins + maven-surefire-plugin + ${maven-surefire-plugin.version} + + + + + \ No newline at end of file diff --git a/mocks/jmockit/src/main/java/org/baeldung/mocks/jmockit/Collaborator.java b/mocks/jmockit/src/main/java/org/baeldung/mocks/jmockit/Collaborator.java new file mode 100644 index 0000000000..ef271b9aff --- /dev/null +++ b/mocks/jmockit/src/main/java/org/baeldung/mocks/jmockit/Collaborator.java @@ -0,0 +1,10 @@ +package org.baeldung.mocks.jmockit; + +public class Collaborator { + public boolean collaborate(String string){ + return false; + } + public void receive(boolean bool){ + //NOOP + } +} diff --git a/mocks/jmockit/src/main/java/org/baeldung/mocks/jmockit/Model.java b/mocks/jmockit/src/main/java/org/baeldung/mocks/jmockit/Model.java new file mode 100644 index 0000000000..54249dcd1d --- /dev/null +++ b/mocks/jmockit/src/main/java/org/baeldung/mocks/jmockit/Model.java @@ -0,0 +1,7 @@ +package org.baeldung.mocks.jmockit; + +public class Model { + public String getInfo(){ + return "info"; + } +} diff --git a/mocks/jmockit/src/main/java/org/baeldung/mocks/jmockit/Performer.java b/mocks/jmockit/src/main/java/org/baeldung/mocks/jmockit/Performer.java new file mode 100644 index 0000000000..4f8e8adb24 --- /dev/null +++ b/mocks/jmockit/src/main/java/org/baeldung/mocks/jmockit/Performer.java @@ -0,0 +1,10 @@ +package org.baeldung.mocks.jmockit; + +public class Performer { + private Collaborator collaborator; + + public void perform(Model model){ + boolean value = collaborator.collaborate(model.getInfo()); + collaborator.receive(value); + } +} diff --git a/mocks/jmockit/src/test/java/org/baeldung/mocks/jmockit/PerformerTest.java b/mocks/jmockit/src/test/java/org/baeldung/mocks/jmockit/PerformerTest.java new file mode 100644 index 0000000000..c99ae844c3 --- /dev/null +++ b/mocks/jmockit/src/test/java/org/baeldung/mocks/jmockit/PerformerTest.java @@ -0,0 +1,30 @@ +package org.baeldung.mocks.jmockit; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import mockit.*; +import mockit.integration.junit4.JMockit; + +@RunWith(JMockit.class) +public class PerformerTest { + + @Injectable + private Collaborator collaborator; + + @Tested + private Performer performer; + + @Test + public void testThePerformMethod(@Mocked Model model) { + new Expectations() {{ + model.getInfo();result = "bar"; + collaborator.collaborate("bar"); result = true; + }}; + performer.perform(model); + new Verifications() {{ + collaborator.receive(true); + }}; + } + +} diff --git a/mock-comparisons/README.md b/mocks/mock-comparisons/README.md similarity index 100% rename from mock-comparisons/README.md rename to mocks/mock-comparisons/README.md diff --git a/mock-comparisons/pom.xml b/mocks/mock-comparisons/pom.xml similarity index 90% rename from mock-comparisons/pom.xml rename to mocks/mock-comparisons/pom.xml index c5424d262d..692bfffd53 100644 --- a/mock-comparisons/pom.xml +++ b/mocks/mock-comparisons/pom.xml @@ -1,11 +1,16 @@ 4.0.0 - org.baeldung - mock-comparisons - 0.1-SNAPSHOT - mockito + + com.baeldung + mocks + 1.0.0-SNAPSHOT + ../pom.xml + + + mock-comparisons + mock-comparisons 4.12 diff --git a/mock-comparisons/src/main/java/org/baeldung/mocks/testCase/LoginController.java b/mocks/mock-comparisons/src/main/java/org/baeldung/mocks/testCase/LoginController.java similarity index 100% rename from mock-comparisons/src/main/java/org/baeldung/mocks/testCase/LoginController.java rename to mocks/mock-comparisons/src/main/java/org/baeldung/mocks/testCase/LoginController.java diff --git a/mock-comparisons/src/main/java/org/baeldung/mocks/testCase/LoginDao.java b/mocks/mock-comparisons/src/main/java/org/baeldung/mocks/testCase/LoginDao.java similarity index 100% rename from mock-comparisons/src/main/java/org/baeldung/mocks/testCase/LoginDao.java rename to mocks/mock-comparisons/src/main/java/org/baeldung/mocks/testCase/LoginDao.java diff --git a/mock-comparisons/src/main/java/org/baeldung/mocks/testCase/LoginService.java b/mocks/mock-comparisons/src/main/java/org/baeldung/mocks/testCase/LoginService.java similarity index 100% rename from mock-comparisons/src/main/java/org/baeldung/mocks/testCase/LoginService.java rename to mocks/mock-comparisons/src/main/java/org/baeldung/mocks/testCase/LoginService.java diff --git a/mock-comparisons/src/main/java/org/baeldung/mocks/testCase/UserForm.java b/mocks/mock-comparisons/src/main/java/org/baeldung/mocks/testCase/UserForm.java similarity index 100% rename from mock-comparisons/src/main/java/org/baeldung/mocks/testCase/UserForm.java rename to mocks/mock-comparisons/src/main/java/org/baeldung/mocks/testCase/UserForm.java diff --git a/mock-comparisons/src/test/java/org/baeldung/mocks/easymock/LoginControllerTest.java b/mocks/mock-comparisons/src/test/java/org/baeldung/mocks/easymock/LoginControllerTest.java similarity index 100% rename from mock-comparisons/src/test/java/org/baeldung/mocks/easymock/LoginControllerTest.java rename to mocks/mock-comparisons/src/test/java/org/baeldung/mocks/easymock/LoginControllerTest.java diff --git a/mock-comparisons/src/test/java/org/baeldung/mocks/jmockit/LoginControllerTest.java b/mocks/mock-comparisons/src/test/java/org/baeldung/mocks/jmockit/LoginControllerTest.java similarity index 100% rename from mock-comparisons/src/test/java/org/baeldung/mocks/jmockit/LoginControllerTest.java rename to mocks/mock-comparisons/src/test/java/org/baeldung/mocks/jmockit/LoginControllerTest.java diff --git a/mock-comparisons/src/test/java/org/baeldung/mocks/mockito/LoginControllerTest.java b/mocks/mock-comparisons/src/test/java/org/baeldung/mocks/mockito/LoginControllerTest.java similarity index 100% rename from mock-comparisons/src/test/java/org/baeldung/mocks/mockito/LoginControllerTest.java rename to mocks/mock-comparisons/src/test/java/org/baeldung/mocks/mockito/LoginControllerTest.java diff --git a/mocks/pom.xml b/mocks/pom.xml new file mode 100644 index 0000000000..ec02c255ef --- /dev/null +++ b/mocks/pom.xml @@ -0,0 +1,20 @@ + + 4.0.0 + + + com.baeldung + parent-modules + 1.0.0-SNAPSHOT + ../pom.xml + + + mocks + mocks + pom + + + mock-comparisons + jmockit + + + diff --git a/pom.xml b/pom.xml index 75281ce80d..f6dda4efd1 100644 --- a/pom.xml +++ b/pom.xml @@ -7,8 +7,12 @@ parent-modules pom + + + UTF-8 + + - apache-fop assertj core-java @@ -25,7 +29,7 @@ jooq-spring json-path mockito - mock-comparisons + mocks jee7schedule querydsl