*/
package org.opendaylight.yangtools.concepts;
+import static org.junit.Assert.assertThrows;
+
import org.junit.Test;
public class AbstractIllegalArgumentCodecTest {
private final TestCodec codec = new TestCodec();
- @Test(expected = NullPointerException.class)
+ @Test
public void testNullDeserialize() {
- codec.deserialize(null);
+ assertThrows(NullPointerException.class, () -> codec.deserialize(null));
}
- @Test(expected = NullPointerException.class)
+ @Test
public void testNullSerialize() {
- codec.serialize(null);
+ assertThrows(NullPointerException.class, () -> codec.serialize(null));
}
}
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doNothing;
import org.junit.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
.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