Migrate concepts to Jupiter API
[yangtools.git] / common / concepts / src / test / java / org / opendaylight / yangtools / concepts / CheckedValueTest.java
index 382c8cb321833c71ef0565abc447a465ee6489c1..9ebaee5ef5afc61b3abc4e1c6672312089b961e1 100644 (file)
@@ -7,36 +7,38 @@
  */
 package org.opendaylight.yangtools.concepts;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.Matchers.any;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.doNothing;
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.verifyZeroInteractions;
+import static org.mockito.Mockito.verifyNoInteractions;
 
 import java.util.function.Consumer;
 import java.util.function.Function;
 import java.util.function.Supplier;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
 
 public class CheckedValueTest {
-    @Test(expected = NullPointerException.class)
+    @Test
     public void testNullValue() {
-        CheckedValue.ofValue(null);
+        assertThrows(NullPointerException.class, () -> CheckedValue.ofValue(null));
     }
 
-    @Test(expected = IllegalStateException.class)
     public void testExceptionGet() {
-        CheckedValue.ofException(new Exception()).get();
+        final CheckedValue<?, ?> value = CheckedValue.ofException(new Exception());
+        assertThrows(IllegalStateException.class, () -> value.get());
     }
 
-    @Test(expected = IllegalStateException.class)
+    @Test
     public void testValueException() {
-        CheckedValue.ofValue("foo").getException();
+        final CheckedValue<?, ?> value = CheckedValue.ofValue("foo");
+        assertThrows(IllegalStateException.class, () -> value.getException());
     }
 
     @Test
@@ -88,6 +90,7 @@ public class CheckedValueTest {
     @Test
     public void testIfPresent() {
         final String foo = "foo";
+        @SuppressWarnings("unchecked")
         final Consumer<Object> consumer = mock(Consumer.class);
         doNothing().when(consumer).accept(any(Object.class));
         CheckedValue.ofValue(foo).ifPresent(consumer);
@@ -96,10 +99,11 @@ public class CheckedValueTest {
 
     @Test
     public void testThrowableIfPresent() {
+        @SuppressWarnings("unchecked")
         final Consumer<Object> consumer = mock(Consumer.class);
         doNothing().when(consumer).accept(any(Object.class));
         CheckedValue.ofException(new NullPointerException()).ifPresent(consumer);
-        verifyZeroInteractions(consumer);
+        verifyNoInteractions(consumer);
     }
 
     @Test
@@ -115,6 +119,7 @@ public class CheckedValueTest {
         final String foo = "foo";
         final String bar = "bar";
         final CheckedValue<Object, ?> errVal = CheckedValue.ofValue(foo);
+        @SuppressWarnings("unchecked")
         final Function<Object, Object> mapper = mock(Function.class);
         doReturn(bar).when(mapper).apply(any(Object.class));
         assertSame(bar, errVal.map(mapper).get());
@@ -124,10 +129,11 @@ public class CheckedValueTest {
     @Test
     public void testExceptionMap() {
         final CheckedValue<Object, ?> errVal = CheckedValue.ofException(new NullPointerException());
+        @SuppressWarnings("unchecked")
         final Function<Object, Object> mapper = mock(Function.class);
         doReturn(null).when(mapper).apply(any(Object.class));
         assertSame(errVal, errVal.map(mapper));
-        verifyZeroInteractions(mapper);
+        verifyNoInteractions(mapper);
     }
 
     @Test
@@ -137,25 +143,27 @@ public class CheckedValueTest {
             .orElseThrow((Supplier<NullPointerException>)NullPointerException::new));
     }
 
-    @Test(expected = InterruptedException.class)
-    public void testThrowableOrElseThrow() throws InterruptedException {
-        final String foo = "foo";
-        final Exception cause = new NullPointerException(foo);
-        CheckedValue.ofException(cause).orElseThrow((Supplier<InterruptedException>)InterruptedException::new);
+    @Test
+    public void testThrowableOrElseThrow() {
+        final CheckedValue<?, ?> value = CheckedValue.ofException(new NullPointerException("foo"));
+        final Exception mock = mock(Exception.class);
+        assertThrows(mock.getClass(), () -> value.orElseThrow(() -> mock));
     }
 
     @Test
     public void testOrElseGet() {
         final String foo = "foo";
+        @SuppressWarnings("unchecked")
         final Supplier<String> supplier = mock(Supplier.class);
         doReturn(null).when(supplier).get();
         assertSame(foo, CheckedValue.ofValue(foo).orElseGet(supplier));
-        verifyZeroInteractions(supplier);
+        verifyNoInteractions(supplier);
     }
 
     @Test
     public void testExceptionOrElseGet() {
         final String bar = "bar";
+        @SuppressWarnings("unchecked")
         final Supplier<Object> supplier = mock(Supplier.class);
         doReturn(bar).when(supplier).get();