<artifactId>mockito-core</artifactId>
<scope>compile</scope>
</dependency>
- <dependency>
- <groupId>com.google.truth</groupId>
- <artifactId>truth</artifactId>
- </dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
</dependencies>
-
</project>
*/
package org.opendaylight.yangtools.testutils.mockito.tests;
-import static com.google.common.truth.Truth.assertThat;
+import static org.junit.Assert.assertEquals;
import java.lang.reflect.Method;
import org.junit.Test;
import org.opendaylight.yangtools.testutils.mockito.MethodExtensions;
public class MethodExtensionsTest {
-
public <T> void fooBar(int index, T element) {
+ // No-op
}
@Test
public void betterToString() throws Exception {
Method method = MethodExtensionsTest.class.getMethod("fooBar", Integer.TYPE, Object.class);
- assertThat(MethodExtensions.toString(method)).isEqualTo("fooBar(int index, T element)");
+ assertEquals("fooBar(int index, T element)", MethodExtensions.toString(method));
}
-
}
*/
package org.opendaylight.yangtools.testutils.mockito.tests;
-import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
+import static org.junit.Assert.assertThrows;
import static org.mockito.Mockito.mock;
import static org.opendaylight.yangtools.testutils.mockito.MoreAnswers.realOrException;
@Test
public void usingMikitoToCallUnstubbedMethodAndExpectException() {
MockSomeService service = mock(MockSomeService.class, realOrException());
- try {
- service.foo();
- fail();
- } catch (UnstubbedMethodException e) {
- assertThat(e.getMessage()).isEqualTo("foo() is not implemented in mockSomeService");
- }
+ String message = assertThrows(UnstubbedMethodException.class, service::foo).getMessage();
+ assertEquals("foo() is not implemented in mockSomeService", message);
}
abstract static class MockSomeService implements SomeService {
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")));
}
-
}
*/
package org.opendaylight.yangtools.testutils.mockito.tests;
-import static com.google.common.truth.Truth.assertThat;
-import static org.junit.Assert.fail;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThrows;
import static org.opendaylight.yangtools.testutils.mockito.MoreAnswers.exception;
import java.io.Closeable;
import org.opendaylight.yangtools.testutils.mockito.UnstubbedMethodException;
public class MockitoUnstubbedMethodExceptionAnswerTest {
-
@Test
public void testAnswering() throws IOException {
Closeable mock = Mockito.mock(Closeable.class, exception());
- try {
- mock.close();
- fail();
- } catch (UnstubbedMethodException e) {
- assertThat(e.getMessage()).isEqualTo("close() is not stubbed in mock of java.io.Closeable");
- }
-
+ String message = assertThrows(UnstubbedMethodException.class, mock::close).getMessage();
+ assertEquals("close() is not stubbed in mock of java.io.Closeable", message);
}
-
}