Skip to content

Instantly share code, notes, and snippets.

@bmchild
Created November 15, 2013 15:44
Show Gist options
  • Save bmchild/7486405 to your computer and use it in GitHub Desktop.
Save bmchild/7486405 to your computer and use it in GitHub Desktop.
/*
* Business logic service
*/
public class MyBusinessService {
private SomeService someService;
public void executeSomeLogic(String input) {
Something thing = new Something();
if(input.equals("A") {
// ...do some logic here
} if else (input.equals("B") {
// ...or something here
} if else (input.equals("C") {
// ....or something else here
}
someService.doSomething(thing);
}
}
/*
* Business Logic Test
*/
@RunWith(MockitoJUnitRunner.class)
public class MyBusinessServiceTest {
@Mock
private SomeService someService;
@InjectMocks
private MyBusinessService myBusinessService;
@Captor
private ArgumentCaptor<Something> somethingCaptor;
@Test
public void testExecuteSomeLogic_Scenario1() {
String input = "A";
myBusinessService.executeSomeLogic(input);
verify(someService).doSomething(somethingCaptor.capture());
// ...assert captured values here
}
@Test
public void testExecuteSomeLogic_SCenario2() {
String input = "B";
myBusinessService.executeSomeLogic(input);
verify(someService).doSomething(somethingCaptor.capture());
// ...assert captured values here
}
@Test
public void testExecuteSomeLogic_SCenario3() {
String input = "C";
myBusinessService.executeSomeLogic(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