创建 WeChatMsgTest.java

pull/1/head
wangsiyuan 2023-12-12 18:28:31 +08:00
parent 4b7b719563
commit e1db480067
1 changed files with 55 additions and 0 deletions

View 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\".");
}
}