Created
November 15, 2013 15:44
-
-
Save bmchild/7486405 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 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