Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Simple_Mock{
- class Mission{
- public Mission(){
- }
- public void complete(int arg){
- // code
- }
- public boolean isComplete(){
- //code
- return false;
- }
- }
- //void answer
- @Test
- public void mock_Mission_test{
- Mission mission_mock = mock(Mission.class);
- doAnswer(new Answer<Void>() {
- public Void answer(InvocationOnMock invocation) {
- when(mission_mock.isCompleted()).thenReturn(true);
- // get arguments from the innvocation if the method is called with args.
- // The doAnswer is how to mock a method LOL
- Integer arg = invocation.getArguments()[0];
- System.out.println(arg);
- return null;
- }
- }).when(mission_mock).complete(0);
- task_mock.complete(0);
- assertTrue(mission_mock.isCompleted());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement