Created
November 15, 2013 15:56
-
-
Save bmchild/7486650 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(MyLogicOperator input) { | |
Something thing = new Something(); | |
input.doLogic(); | |
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() { | |
MyLogicOperator input = mock(MyLogicOperator.class); | |
myBusinessService.executeSomeLogic(input); | |
verify(someService).doSomething(somethingCaptor.capture()); | |
// ...assert captured values here | |
} | |
} | |
/* Interface code omitted for brevity */ | |
/* | |
* Concrete Impl of MyLogicOperator for A | |
*/ | |
public class ALogicOperator implements MyLogicOperator { | |
@Override | |
public void doLogic() { | |
// ...do some logic here | |
} | |
} | |
/* | |
* ALogicOperator Test | |
*/ | |
public class ALogicOperatorTest { | |
@Test | |
public void testdoLogic() { | |
ALogicOperator operator = new ALogicOperator(); | |
operator.doLogic(); | |
// assert as needed | |
} | |
} | |
/* other concrete impls omitted for brevity */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment