Last active
December 28, 2015 10:29
-
-
Save bmchild/7486252 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Business Logic Test | |
*/ | |
@RunWith(MockitoJUnitRunner.class) | |
public class MyBusinessServiceTest { | |
@Mock | |
private AnotherService anotherService; | |
@Mock | |
private SomeService someService; | |
@InjectMocks | |
private MyBusinessService myBusinessService; | |
@Captor | |
private ArgumentCaptor<Something> somethingCaptor; | |
@Test | |
public void testExecuteSomeLogic_SCenario1() { | |
when(anotherService.makeSomething("A")).thenReturn(new Something()); | |
when(anotherService.makeSomeField(any(Something.class)).thenReturn("something"); | |
String input = "A"; | |
myBusinessService.executeSomeLogic(input); | |
verify(someService).doSomething(somethingCaptor.capture()); | |
// ...assert captured values here | |
} | |
@Test | |
public void testExecuteSomeLogic_SCenario2() { | |
when(anotherService.makeSomething("B")).thenReturn(new Something()); | |
when(anotherService.makeSomeField(any(Something.class)).thenReturn("something"); | |
String input = "B"; | |
myBusinessService.executeSomeLogic(input); | |
verify(someService).doSomething(somethingCaptor.capture()); | |
// ...assert captured values here | |
} | |
@Test | |
public void testExecuteSomeMoreLogic() { | |
when(anotherService.makeSomething("A")).thenReturn(new Something()); | |
String input = "A"; | |
myBusinessService.executeSomeMoreLogic(input); | |
verify(someService).doSomething(somethingCaptor.capture()); | |
// ...assert captured values here | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment