diff --git a/src/integrationTest/java/com/weirddev/testme/intellij/generator/TestMeGeneratorGroovyJunit4Test.java b/src/integrationTest/java/com/weirddev/testme/intellij/generator/TestMeGeneratorGroovyJunit4Test.java index 4874ac46..3c67ca1d 100644 --- a/src/integrationTest/java/com/weirddev/testme/intellij/generator/TestMeGeneratorGroovyJunit4Test.java +++ b/src/integrationTest/java/com/weirddev/testme/intellij/generator/TestMeGeneratorGroovyJunit4Test.java @@ -1,5 +1,7 @@ package com.weirddev.testme.intellij.generator; +import com.weirddev.testme.intellij.configuration.TestMeConfigPersistent; +import com.weirddev.testme.intellij.template.FileTemplateConfig; import com.weirddev.testme.intellij.template.TemplateRegistry; import com.weirddev.testme.intellij.template.context.Language; @@ -47,4 +49,7 @@ public void testUtilWithoutAccessableCtor() { doTest(true, true, true); } + public void testVerifyMethodCall() { + doTest(new FileTemplateConfig(TestMeConfigPersistent.getInstance().getState())); + } } diff --git a/src/integrationTest/java/com/weirddev/testme/intellij/generator/TestMeGeneratorJunit4Test.java b/src/integrationTest/java/com/weirddev/testme/intellij/generator/TestMeGeneratorJunit4Test.java index 349a2c06..f896d575 100644 --- a/src/integrationTest/java/com/weirddev/testme/intellij/generator/TestMeGeneratorJunit4Test.java +++ b/src/integrationTest/java/com/weirddev/testme/intellij/generator/TestMeGeneratorJunit4Test.java @@ -176,6 +176,10 @@ public void testUtilWithoutAccessableCtor() { doTest(true, true, true); } + public void testVerifyMethodCall() { + doTest(new FileTemplateConfig(TestMeConfigPersistent.getInstance().getState())); + } + //todo TC - use static init method when constructor not available // TODO TC different test target dir diff --git a/src/integrationTest/java/com/weirddev/testme/intellij/generator/TestMeGeneratorJunit5Test.java b/src/integrationTest/java/com/weirddev/testme/intellij/generator/TestMeGeneratorJunit5Test.java index 5fbf7593..77807cd6 100644 --- a/src/integrationTest/java/com/weirddev/testme/intellij/generator/TestMeGeneratorJunit5Test.java +++ b/src/integrationTest/java/com/weirddev/testme/intellij/generator/TestMeGeneratorJunit5Test.java @@ -33,4 +33,7 @@ public void testUtilWithoutAccessableCtor() { doTest(true, true, true); } + public void testVerifyMethodCall() { + doTest(new FileTemplateConfig(TestMeConfigPersistent.getInstance().getState())); + } } diff --git a/src/integrationTest/java/com/weirddev/testme/intellij/generator/TestMeGeneratorTestNgTest.java b/src/integrationTest/java/com/weirddev/testme/intellij/generator/TestMeGeneratorTestNgTest.java index 2f81e537..4c3b2d23 100644 --- a/src/integrationTest/java/com/weirddev/testme/intellij/generator/TestMeGeneratorTestNgTest.java +++ b/src/integrationTest/java/com/weirddev/testme/intellij/generator/TestMeGeneratorTestNgTest.java @@ -33,4 +33,8 @@ public void testUtilWithoutAccessableCtor() { doTest(true, true, true); } + public void testVerifyMethodCall() { + doTest(new FileTemplateConfig(TestMeConfigPersistent.getInstance().getState())); + } + } \ No newline at end of file diff --git a/src/main/java/com/weirddev/testme/intellij/template/context/Method.java b/src/main/java/com/weirddev/testme/intellij/template/context/Method.java index 4508efbe..111d8288 100644 --- a/src/main/java/com/weirddev/testme/intellij/template/context/Method.java +++ b/src/main/java/com/weirddev/testme/intellij/template/context/Method.java @@ -138,7 +138,7 @@ public class Method { /** * - * true - if method has a return type + * true - if method has a return type and not void */ public boolean hasReturn(){ return returnType != null && !"void".equals(returnType.getName()); diff --git a/src/main/java/com/weirddev/testme/intellij/template/context/MockitoMockBuilder.java b/src/main/java/com/weirddev/testme/intellij/template/context/MockitoMockBuilder.java index c4da47c3..177bc2b2 100644 --- a/src/main/java/com/weirddev/testme/intellij/template/context/MockitoMockBuilder.java +++ b/src/main/java/com/weirddev/testme/intellij/template/context/MockitoMockBuilder.java @@ -6,6 +6,7 @@ import org.jetbrains.annotations.Nullable; import java.util.*; +import java.util.function.Predicate; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -245,22 +246,41 @@ private String deductMatcherTypeMethod(Param param, Language language) { */ @SuppressWarnings("unused") public boolean shouldStub(Method testMethod, List testedClassFields) { - boolean shouldStub = false; - if (stubMockMethodCallsReturnValues) { - for (Field testedClassField : testedClassFields) { - if (isMockable(testedClassField)) { - LOG.debug("field "+testedClassField.getName()+" type "+testedClassField.getType().getCanonicalName()+" type methods:"+testedClassField.getType().getMethods().size()); - for (Method fieldMethod : testedClassField.getType().getMethods()) { - if (fieldMethod.getReturnType() != null && !"void".equals(fieldMethod.getReturnType().getCanonicalName()) && testSubjectInspector.isMethodCalled(fieldMethod, testMethod)) { - shouldStub = true; - break; - } - } + return callsMockMethod(testMethod, testedClassFields, Method::hasReturn); + } + + /** + * true - if should verify tested method + * @param testMethod method being tested + * @param testedClassFields fields of owner type being tested + */ + @SuppressWarnings("unused") + public boolean shouldVerify(Method testMethod, List testedClassFields) { + return callsMockMethod(testMethod, testedClassFields, method -> !method.hasReturn()); + } + + private boolean callsMockMethod(Method testMethod, List testedClassFields, + Predicate mockMethodRelevant) { + boolean callsMockMethod = false; + if (!stubMockMethodCallsReturnValues) { + LOG.debug("method " + testMethod.getMethodId() + " is calling a mock method:" + callsMockMethod); + return callsMockMethod; + } + for (Field testedClassField : testedClassFields) { + if (!isMockable(testedClassField)) { + continue; + } + LOG.debug("field " + testedClassField.getName() + " type " + testedClassField.getType().getCanonicalName() + + " type methods:" + testedClassField.getType().getMethods().size()); + for (Method fieldMethod : testedClassField.getType().getMethods()) { + if (mockMethodRelevant.test(fieldMethod) + && testSubjectInspector.isMethodCalled(fieldMethod, testMethod)) { + return true; } } } - LOG.debug("method "+testMethod.getMethodId()+" should be stabbed:"+shouldStub); - return shouldStub; + LOG.debug("method " + testMethod.getMethodId() + " is calling a mock method:" + callsMockMethod); + return callsMockMethod; } /** diff --git a/src/main/resources/fileTemplates/testMeIncludes/TestMe macros.groovy.ft b/src/main/resources/fileTemplates/testMeIncludes/TestMe macros.groovy.ft index ed34032a..975c4604 100644 --- a/src/main/resources/fileTemplates/testMeIncludes/TestMe macros.groovy.ft +++ b/src/main/resources/fileTemplates/testMeIncludes/TestMe macros.groovy.ft @@ -96,10 +96,22 @@ result#if($TestSubjectUtils.isJavaFuture($method.returnType)).get()#end == $Test #foreach($field in $testedClassFields) #if($MockitoMockBuilder.isMockable($field)) #foreach($fieldMethod in $field.type.methods) -#if($fieldMethod.returnType && $fieldMethod.returnType.name !="void" && $TestSubjectUtils.isMethodCalled($fieldMethod,$method)) +#if($fieldMethod.hasReturn() && $TestSubjectUtils.isMethodCalled($fieldMethod,$method)) when($field.name.${fieldMethod.name}($MockitoMockBuilder.buildMockArgsMatchers(${fieldMethod.methodParams},"Java"))).thenReturn($TestBuilder.renderReturnParam($method,$fieldMethod.returnType,"${fieldMethod.name}Response",$grReplacementTypes,$grDefaultTypeValues)) #end #end #end #end +#end +## +#macro(grRenderMockVerifies $method $testedClassFields) +#foreach($field in $testedClassFields) +#if($MockitoMockBuilder.isMockable($field)) +#foreach($fieldMethod in $field.type.methods) +#if(!$fieldMethod.hasReturn() && $TestSubjectUtils.isMethodCalled($fieldMethod,$method)) + verify($field.name).${fieldMethod.name}($MockitoMockBuilder.buildMockArgsMatchers(${fieldMethod.methodParams},"Java")) +#end +#end +#end +#end #end \ No newline at end of file diff --git a/src/main/resources/fileTemplates/testMeIncludes/TestMe macros.java.ft b/src/main/resources/fileTemplates/testMeIncludes/TestMe macros.java.ft index 4cd735d5..044f6393 100644 --- a/src/main/resources/fileTemplates/testMeIncludes/TestMe macros.java.ft +++ b/src/main/resources/fileTemplates/testMeIncludes/TestMe macros.java.ft @@ -88,10 +88,22 @@ assertEquals(result#{if}($TestSubjectUtils.isJavaFuture($method.returnType)).get #foreach($field in $testedClassFields) #if($MockitoMockBuilder.isMockable($field)) #foreach($fieldMethod in $field.type.methods) -#if($fieldMethod.returnType && $fieldMethod.returnType.name !="void" && $TestSubjectUtils.isMethodCalled($fieldMethod,$method)) +#if($fieldMethod.hasReturn() && $TestSubjectUtils.isMethodCalled($fieldMethod,$method)) when($field.name.${fieldMethod.name}($MockitoMockBuilder.buildMockArgsMatchers(${fieldMethod.methodParams},"Java"))).thenReturn($TestBuilder.renderReturnParam($method,$fieldMethod.returnType,"${fieldMethod.name}Response",$replacementTypes,$defaultTypeValues)); #end #end #end #end +#end +## +#macro(renderMockVerifies $method $testedClassFields) +#foreach($field in $testedClassFields) +#if($MockitoMockBuilder.isMockable($field)) +#foreach($fieldMethod in $field.type.methods) +#if(!$fieldMethod.hasReturn() && $TestSubjectUtils.isMethodCalled($fieldMethod,$method)) + verify($field.name).${fieldMethod.name}($MockitoMockBuilder.buildMockArgsMatchers(${fieldMethod.methodParams},"Java")); +#end +#end +#end +#end #end \ No newline at end of file diff --git a/src/main/resources/fileTemplates/testMeTests/Groovy, JUnit4 & Mockito.groovy.ft b/src/main/resources/fileTemplates/testMeTests/Groovy, JUnit4 & Mockito.groovy.ft index 3a51809d..e9f966f5 100644 --- a/src/main/resources/fileTemplates/testMeTests/Groovy, JUnit4 & Mockito.groovy.ft +++ b/src/main/resources/fileTemplates/testMeTests/Groovy, JUnit4 & Mockito.groovy.ft @@ -34,6 +34,9 @@ class ${CLASS_NAME} { #end $TAB$TAB#grRenderMethodCall($method,$TESTED_CLASS.name) +#if($hasMocks && $MockitoMockBuilder.shouldVerify($method,$TESTED_CLASS.fields)) +#grRenderMockVerifies($method,$TESTED_CLASS.fields) +#end #if($method.hasReturn()) assert #grRenderAssert($method) #end diff --git a/src/main/resources/fileTemplates/testMeTests/JUnit4 & Mockito.java.ft b/src/main/resources/fileTemplates/testMeTests/JUnit4 & Mockito.java.ft index a3f7e33d..4b72fb4f 100644 --- a/src/main/resources/fileTemplates/testMeTests/JUnit4 & Mockito.java.ft +++ b/src/main/resources/fileTemplates/testMeTests/JUnit4 & Mockito.java.ft @@ -35,6 +35,9 @@ public class ${CLASS_NAME} { #end $TAB$TAB#renderMethodCall($method,$TESTED_CLASS.name) +#if($hasMocks && $MockitoMockBuilder.shouldVerify($method,$TESTED_CLASS.fields)) +#renderMockVerifies($method,$TESTED_CLASS.fields) +#end #if($method.hasReturn()) Assert.#renderJUnitAssert($method)#end } diff --git a/src/main/resources/fileTemplates/testMeTests/JUnit5 & Mockito.java.ft b/src/main/resources/fileTemplates/testMeTests/JUnit5 & Mockito.java.ft index 7e2a872b..4913b3ff 100644 --- a/src/main/resources/fileTemplates/testMeTests/JUnit5 & Mockito.java.ft +++ b/src/main/resources/fileTemplates/testMeTests/JUnit5 & Mockito.java.ft @@ -34,6 +34,9 @@ class ${CLASS_NAME} { #end $TAB$TAB#renderMethodCall($method,$TESTED_CLASS.name) +#if($hasMocks && $MockitoMockBuilder.shouldVerify($method,$TESTED_CLASS.fields)) +#renderMockVerifies($method,$TESTED_CLASS.fields) +#end #if($method.hasReturn()) Assertions.#renderJUnitAssert($method)#end } #end diff --git a/src/main/resources/fileTemplates/testMeTests/TestNG & Mockito.java.ft b/src/main/resources/fileTemplates/testMeTests/TestNG & Mockito.java.ft index 4fc70d4f..e5adcbbb 100644 --- a/src/main/resources/fileTemplates/testMeTests/TestNG & Mockito.java.ft +++ b/src/main/resources/fileTemplates/testMeTests/TestNG & Mockito.java.ft @@ -34,6 +34,9 @@ public class ${CLASS_NAME} { #end $TAB$TAB#renderMethodCall($method,$TESTED_CLASS.name) +#if($hasMocks && $MockitoMockBuilder.shouldVerify($method,$TESTED_CLASS.fields)) +#renderMockVerifies($method,$TESTED_CLASS.fields) +#end #if($method.hasReturn()) Assert.#renderTestNgAssert($method)#end } #end diff --git a/testData/commonSrc/com/example/warriers/TechFighter.java b/testData/commonSrc/com/example/warriers/TechFighter.java new file mode 100644 index 00000000..d4e1ac8f --- /dev/null +++ b/testData/commonSrc/com/example/warriers/TechFighter.java @@ -0,0 +1,13 @@ +package com.example.warriers; + +import com.example.beans.ConvertedBean; +import com.example.foes.Fear; +import com.example.foes.Fire; +import com.example.foes.Ice; + +/** Test input class*/ +public interface TechFighter { + void initSelfArming(String weapon) + String fight(Fire withFire); + ConvertedBean surrender(Fear fear, Ice ice,int times); +} \ No newline at end of file diff --git a/testData/commonSrc/com/example/warriers/impl/TechFighterImpl.java b/testData/commonSrc/com/example/warriers/impl/TechFighterImpl.java new file mode 100644 index 00000000..787ee6c2 --- /dev/null +++ b/testData/commonSrc/com/example/warriers/impl/TechFighterImpl.java @@ -0,0 +1,31 @@ +package com.example.warriers.impl; + +import com.example.beans.ConvertedBean; +import com.example.foes.Fear; +import com.example.foes.Fire; +import com.example.foes.Ice; +import com.example.warriers.TechFighter; + +/** Test input class*/ +public class TechFighterImpl implements TechFighter { + + private String weapon; + + @Override + public String fight(Fire withFire) { + return "flames"; + } + + @Override + public ConvertedBean surrender(Fear fear, Ice ice,int times) { + System.out.println("times:" + times); + System.out.println("fear:" + fear.toString()); + return new ConvertedBean(); + } + + @Override + public void initSelfArming(String weapon) { + this.weapon = weapon; + } + +} diff --git a/testData/testMeGenerator/mockReturned/test/com/example/services/impl/FooTest.java b/testData/testMeGenerator/mockReturned/test/com/example/services/impl/FooTest.java index c473da7b..5cddbb56 100644 --- a/testData/testMeGenerator/mockReturned/test/com/example/services/impl/FooTest.java +++ b/testData/testMeGenerator/mockReturned/test/com/example/services/impl/FooTest.java @@ -39,6 +39,7 @@ public void testFight() throws Exception { when(result.get()).thenReturn(Integer.valueOf(0)); String result = foo.fight(new Fire(), "foeName"); + verify(logger).trace(anyString()); Assert.assertEquals("replaceMeWithExpectedResult", result); } } diff --git a/testData/testMeGenerator/mockReturned/testGroovy/com/example/services/impl/FooTest.groovy b/testData/testMeGenerator/mockReturned/testGroovy/com/example/services/impl/FooTest.groovy index 64bdbfe9..6fd7bf1c 100644 --- a/testData/testMeGenerator/mockReturned/testGroovy/com/example/services/impl/FooTest.groovy +++ b/testData/testMeGenerator/mockReturned/testGroovy/com/example/services/impl/FooTest.groovy @@ -37,6 +37,7 @@ class FooTest { when(result.get()).thenReturn(0) String result = foo.fight(new Fire(), "foeName") + verify(logger).trace(anyString()) assert result == "replaceMeWithExpectedResult" } } diff --git a/testData/testMeGenerator/mockReturned/testJunit5/com/example/services/impl/FooTest.java b/testData/testMeGenerator/mockReturned/testJunit5/com/example/services/impl/FooTest.java index 72b80c5e..1f917260 100644 --- a/testData/testMeGenerator/mockReturned/testJunit5/com/example/services/impl/FooTest.java +++ b/testData/testMeGenerator/mockReturned/testJunit5/com/example/services/impl/FooTest.java @@ -39,6 +39,7 @@ void testFight() { when(result.get()).thenReturn(Integer.valueOf(0)); String result = foo.fight(new Fire(), "foeName"); + verify(logger).trace(anyString()); Assertions.assertEquals("replaceMeWithExpectedResult", result); } } diff --git a/testData/testMeGenerator/mockReturned/testTestNg/com/example/services/impl/FooTest.java b/testData/testMeGenerator/mockReturned/testTestNg/com/example/services/impl/FooTest.java index ceeeea8a..0e389647 100644 --- a/testData/testMeGenerator/mockReturned/testTestNg/com/example/services/impl/FooTest.java +++ b/testData/testMeGenerator/mockReturned/testTestNg/com/example/services/impl/FooTest.java @@ -39,6 +39,7 @@ public void testFight() { when(result.get()).thenReturn(Integer.valueOf(0)); String result = foo.fight(new Fire(), "foeName"); + verify(logger).trace(anyString()); Assert.assertEquals(result, "replaceMeWithExpectedResult"); } } diff --git a/testData/testMeGenerator/variousFieldTypes/test/com/example/services/impl/FooTest.java b/testData/testMeGenerator/variousFieldTypes/test/com/example/services/impl/FooTest.java index 78c43207..a8c9c531 100644 --- a/testData/testMeGenerator/variousFieldTypes/test/com/example/services/impl/FooTest.java +++ b/testData/testMeGenerator/variousFieldTypes/test/com/example/services/impl/FooTest.java @@ -54,6 +54,10 @@ public void testFight() throws Exception { when(innerOfPublicInnerClass.methodOfInnerClass()).thenReturn(new Foo().new PublicInnerClass().new InnerOfPublicInnerClass()); String result = foo.fight(new com.example.foes.Fire(), "foeName"); + verify(publicInnerClass).methodOfInnerClass(); + verify(innerStaticClass).methodOfInnerClass(); + verify(innerClass).methodOfInnerClass(); + verify(anonymousPublicInnerClass).methodOfInnerClass(); Assert.assertEquals("replaceMeWithExpectedResult", result); } } diff --git a/testData/testMeGenerator/variousFieldTypes/testGroovy/com/example/services/impl/FooTest.groovy b/testData/testMeGenerator/variousFieldTypes/testGroovy/com/example/services/impl/FooTest.groovy index 9c670296..96e848e4 100644 --- a/testData/testMeGenerator/variousFieldTypes/testGroovy/com/example/services/impl/FooTest.groovy +++ b/testData/testMeGenerator/variousFieldTypes/testGroovy/com/example/services/impl/FooTest.groovy @@ -50,6 +50,10 @@ class FooTest { when(innerOfPublicInnerClass.methodOfInnerClass()).thenReturn(new com.example.services.impl.Foo.PublicInnerClass.InnerOfPublicInnerClass(new com.example.services.impl.Foo.PublicInnerClass(new com.example.services.impl.Foo()))) java.lang.String result = foo.fight(new com.example.foes.Fire(), "foeName") + verify(publicInnerClass).methodOfInnerClass() + verify(innerStaticClass).methodOfInnerClass() + verify(innerClass).methodOfInnerClass() + verify(anonymousPublicInnerClass).methodOfInnerClass() assert result == "replaceMeWithExpectedResult" } } diff --git a/testData/testMeGenerator/verifyMethodCall/src/com/example/services/impl/Foo.java b/testData/testMeGenerator/verifyMethodCall/src/com/example/services/impl/Foo.java new file mode 100644 index 00000000..d1577282 --- /dev/null +++ b/testData/testMeGenerator/verifyMethodCall/src/com/example/services/impl/Foo.java @@ -0,0 +1,23 @@ +package com.example.services.impl; + +import com.example.beans.ConvertedBean; +import java.util.function.Supplier; +import com.example.dependencies.Logger; +import com.example.foes.Fear; +import com.example.foes.Fire; +import com.example.foes.Ice; +import com.example.warriers.TechFighter; + +public class Foo{ + + private TechFighter techFighter; + private Supplier result; + + public String fight(Fire withFire,String foeName) { + techFighter.initSelfArming("gun"); + String fail = techFighter.fight(withFire); + ConvertedBean convertedBean = techFighter.surrender(new Fear(), new Ice(), 666); + convertedBean.setSomeNum(result.get()); + return "returning response from dependency "+ fail + " " + convertedBean.getMyString(); + } +} diff --git a/testData/testMeGenerator/verifyMethodCall/test/com/example/services/impl/FooTest.java b/testData/testMeGenerator/verifyMethodCall/test/com/example/services/impl/FooTest.java new file mode 100644 index 00000000..a3db85f5 --- /dev/null +++ b/testData/testMeGenerator/verifyMethodCall/test/com/example/services/impl/FooTest.java @@ -0,0 +1,45 @@ +package com.example.services.impl; + +import com.example.beans.ConvertedBean; +import com.example.foes.Fire; +import com.example.warriers.TechFighter; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; + +import java.util.function.Supplier; + +import static org.mockito.Mockito.*; + +/** + * created by TestMe integration test on MMXVI + */ +public class FooTest { + @Mock + TechFighter techFighter; + @Mock + Supplier result; + @InjectMocks + Foo foo; + + @Before + public void setUp() { + MockitoAnnotations.initMocks(this); + } + + @Test + public void testFight() throws Exception { + when(techFighter.fight(any())).thenReturn("fightResponse"); + when(techFighter.surrender(any(), any(), anyInt())).thenReturn(new ConvertedBean()); + when(result.get()).thenReturn(Integer.valueOf(0)); + + String result = foo.fight(new Fire(), "foeName"); + verify(techFighter).initSelfArming(anyString()); + Assert.assertEquals("replaceMeWithExpectedResult", result); + } +} + +//Generated with love by TestMe :) Please raise issues & feature requests at: https://weirddev.com/forum#!/testme \ No newline at end of file diff --git a/testData/testMeGenerator/verifyMethodCall/testGroovy/com/example/services/impl/FooTest.groovy b/testData/testMeGenerator/verifyMethodCall/testGroovy/com/example/services/impl/FooTest.groovy new file mode 100644 index 00000000..cd787760 --- /dev/null +++ b/testData/testMeGenerator/verifyMethodCall/testGroovy/com/example/services/impl/FooTest.groovy @@ -0,0 +1,41 @@ +package com.example.services.impl + +import com.example.beans.ConvertedBean +import com.example.foes.Fire +import com.example.warriers.TechFighter +import org.junit.Test +import org.junit.Before +import org.mockito.InjectMocks +import org.mockito.Mock +import org.mockito.MockitoAnnotations + +import java.util.function.Supplier +import static org.mockito.Mockito.* + +/** created by TestMe integration test on MMXVI */ +class FooTest { + @Mock + TechFighter techFighter + @Mock + Supplier result + @InjectMocks + Foo foo + + @Before + void setUp() { + MockitoAnnotations.initMocks(this) + } + + @Test + void testFight() { + when(techFighter.fight(any())).thenReturn("fightResponse") + when(techFighter.surrender(any(), any(), anyInt())).thenReturn(new ConvertedBean(myString: "myString", someNum: 0)) + when(result.get()).thenReturn(0) + + String result = foo.fight(new Fire(), "foeName") + verify(techFighter).initSelfArming(anyString()) + assert result == "replaceMeWithExpectedResult" + } +} + +//Generated with love by TestMe :) Please raise issues & feature requests at: https://weirddev.com/forum#!/testme \ No newline at end of file diff --git a/testData/testMeGenerator/verifyMethodCall/testJunit5/com/example/services/impl/FooTest.java b/testData/testMeGenerator/verifyMethodCall/testJunit5/com/example/services/impl/FooTest.java new file mode 100644 index 00000000..8d0c0725 --- /dev/null +++ b/testData/testMeGenerator/verifyMethodCall/testJunit5/com/example/services/impl/FooTest.java @@ -0,0 +1,45 @@ +package com.example.services.impl; + +import com.example.beans.ConvertedBean; +import com.example.foes.Fire; +import com.example.warriers.TechFighter; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; + +import java.util.function.Supplier; + +import static org.mockito.Mockito.*; + +/** + * created by TestMe integration test on MMXVI + */ +class FooTest { + @Mock + TechFighter techFighter; + @Mock + Supplier result; + @InjectMocks + Foo foo; + + @BeforeEach + void setUp() { + MockitoAnnotations.initMocks(this); + } + + @Test + void testFight() { + when(techFighter.fight(any())).thenReturn("fightResponse"); + when(techFighter.surrender(any(), any(), anyInt())).thenReturn(new ConvertedBean()); + when(result.get()).thenReturn(Integer.valueOf(0)); + + String result = foo.fight(new Fire(), "foeName"); + verify(techFighter).initSelfArming(anyString()); + Assertions.assertEquals("replaceMeWithExpectedResult", result); + } +} + +//Generated with love by TestMe :) Please raise issues & feature requests at: https://weirddev.com/forum#!/testme \ No newline at end of file diff --git a/testData/testMeGenerator/verifyMethodCall/testTestNg/com/example/services/impl/FooTest.java b/testData/testMeGenerator/verifyMethodCall/testTestNg/com/example/services/impl/FooTest.java new file mode 100644 index 00000000..25c95234 --- /dev/null +++ b/testData/testMeGenerator/verifyMethodCall/testTestNg/com/example/services/impl/FooTest.java @@ -0,0 +1,45 @@ +package com.example.services.impl; + +import com.example.beans.ConvertedBean; +import com.example.foes.Fire; +import com.example.warriers.TechFighter; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.testng.Assert; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +import java.util.function.Supplier; + +import static org.mockito.Mockito.*; + +/** + * created by TestMe integration test on MMXVI + */ +public class FooTest { + @Mock + TechFighter techFighter; + @Mock + Supplier result; + @InjectMocks + Foo foo; + + @BeforeMethod + public void setUp() { + MockitoAnnotations.initMocks(this); + } + + @Test + public void testFight() { + when(techFighter.fight(any())).thenReturn("fightResponse"); + when(techFighter.surrender(any(), any(), anyInt())).thenReturn(new ConvertedBean()); + when(result.get()).thenReturn(Integer.valueOf(0)); + + String result = foo.fight(new Fire(), "foeName"); + verify(techFighter).initSelfArming(anyString()); + Assert.assertEquals(result, "replaceMeWithExpectedResult"); + } +} + +//Generated with love by TestMe :) Please raise issues & feature requests at: https://weirddev.com/forum#!/testme \ No newline at end of file