创建 WeChatMsgTest.java
This commit is contained in:
55
src/test/java/com/kimgo/wepush/model/WeChatMsgTest.java
Normal file
55
src/test/java/com/kimgo/wepush/model/WeChatMsgTest.java
Normal file
@@ -0,0 +1,55 @@
|
||||
package com.kimgo.wepush.model;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class WeChatMsgTest {
|
||||
|
||||
@Test
|
||||
void isInvalid_AllFieldsValid() {
|
||||
WeChatMsg weChatMsg = new WeChatMsg();
|
||||
weChatMsg.setPackageName("com.example.package");
|
||||
weChatMsg.setAppName("Example App");
|
||||
weChatMsg.setTitle("Example Title");
|
||||
weChatMsg.setSender("Example Sender");
|
||||
weChatMsg.setMessage("Example Message");
|
||||
|
||||
assertFalse(weChatMsg.isInvalid(), "WeChatMsg should be valid when all fields are valid.");
|
||||
}
|
||||
|
||||
@Test
|
||||
void isInvalid_OneFieldIsNull() {
|
||||
WeChatMsg weChatMsg = new WeChatMsg();
|
||||
weChatMsg.setPackageName(null); // 设置一个字段为 null
|
||||
weChatMsg.setAppName("Example App");
|
||||
weChatMsg.setTitle("Example Title");
|
||||
weChatMsg.setSender("Example Sender");
|
||||
weChatMsg.setMessage("Example Message");
|
||||
|
||||
assertTrue(weChatMsg.isInvalid(), "WeChatMsg should be invalid if any field is null.");
|
||||
}
|
||||
|
||||
@Test
|
||||
void isInvalid_OneFieldIsEmpty() {
|
||||
WeChatMsg weChatMsg = new WeChatMsg();
|
||||
weChatMsg.setPackageName(""); // 设置一个字段为空字符串
|
||||
weChatMsg.setAppName("Example App");
|
||||
weChatMsg.setTitle("Example Title");
|
||||
weChatMsg.setSender("Example Sender");
|
||||
weChatMsg.setMessage("Example Message");
|
||||
|
||||
assertTrue(weChatMsg.isInvalid(), "WeChatMsg should be invalid if any field is an empty string.");
|
||||
}
|
||||
|
||||
@Test
|
||||
void isInvalid_OneFieldIsStringNull() {
|
||||
WeChatMsg weChatMsg = new WeChatMsg();
|
||||
weChatMsg.setPackageName("null"); // 设置一个字段为字面字符串 "null"
|
||||
weChatMsg.setAppName("Example App");
|
||||
weChatMsg.setTitle("Example Title");
|
||||
weChatMsg.setSender("Example Sender");
|
||||
weChatMsg.setMessage("Example Message");
|
||||
|
||||
assertTrue(weChatMsg.isInvalid(), "WeChatMsg should be invalid if any field is the literal string \"null\".");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user