Skip to content

Instantly share code, notes, and snippets.

@bmchild
Last active December 28, 2015 10:29
Show Gist options
  • Save bmchild/7486252 to your computer and use it in GitHub Desktop.
Save bmchild/7486252 to your computer and use it in GitHub Desktop.
/*
* 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