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"); weChatMsg.setCurrentTime("2023-12-12 18:43:04"); 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\"."); } }