import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
-import static org.junit.Assert.fail;
+import static org.junit.Assert.assertThrows;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doReturn;
// NOT when(s.foobar(any())).thenReturn(123) BUT must be like this:
doReturn(123).when(service).foobar(any());
assertEquals(123, service.foobar(new File("hello.txt")));
- try {
- service.foo();
- fail("expected NotImplementedException");
- } catch (UnstubbedMethodException e) {
- // OK
- }
+ assertThrows(UnstubbedMethodException.class, service::foo);
}
@Test
assertEquals(123, service.foobar(new File("hello.txt")));
assertEquals(0, service.foobar(new File("belo.txt")));
}
-
}