使用 AssertTools 代替 PreconditionsExt。

This commit is contained in:
2024-10-11 17:11:06 +08:00
parent 304dccc658
commit b72fd59b46
4 changed files with 72 additions and 115 deletions

View File

@@ -1,59 +0,0 @@
package xyz.zhouxy.plusone.commons.util;
import org.junit.jupiter.api.Test;
import lombok.extern.slf4j.Slf4j;
import java.util.Arrays;
import java.util.List;
import static org.junit.jupiter.api.Assertions.*;
@Slf4j
class PreconditionsExtTests {
@Test
void testCheck() {
assertThrows(TestException.class, () -> {
PreconditionsExt.checkCondition(false, () -> new TestException("Test error message."));
});
}
@Test
void testCheckAllNotNull() {
assertThrows(NullPointerException.class, () -> {
Object[] array = null;
PreconditionsExt.checkAllNotNull(array);
});
Object obj = new Object();
assertNotNull(obj);
assertThrows(NullPointerException.class,
() -> PreconditionsExt.checkAllNotNull(new Object[] { obj, null }));
assertThrows(NullPointerException.class,
() -> PreconditionsExt.checkAllNotNull(obj, null));
List<Object> list = Arrays.asList(obj, null);
assertNotNull(list);
assertThrows(NullPointerException.class,
() -> PreconditionsExt.checkAllNotNull(list));
PreconditionsExt.checkAllNotNull(new Object[] { obj, "Test" });
PreconditionsExt.checkAllNotNull(obj, "Test");
PreconditionsExt.checkAllNotNull(Arrays.asList(obj, "Test"));
}
}
class TestException extends Exception {
private static final long serialVersionUID = -8808661764734834820L;
protected TestException(String msg) {
super(msg);
}
protected TestException(Throwable cause) {
super(cause);
}
protected TestException(String msg, Throwable cause) {
super(msg, cause);
}
}