diff --git a/ContentGrabbingJi-framework-api/src/main/java/net/lamgc/cgj/bot/framework/message/CharSequenceMessage.java b/ContentGrabbingJi-framework-api/src/main/java/net/lamgc/cgj/bot/framework/message/CharSequenceMessage.java index 8c770b7..94242c5 100644 --- a/ContentGrabbingJi-framework-api/src/main/java/net/lamgc/cgj/bot/framework/message/CharSequenceMessage.java +++ b/ContentGrabbingJi-framework-api/src/main/java/net/lamgc/cgj/bot/framework/message/CharSequenceMessage.java @@ -17,18 +17,28 @@ package net.lamgc.cgj.bot.framework.message; +import java.util.Objects; + /** * 字符序列消息对象. - *
仅包含了一段字符串. + *
仅包含了一段字符序列形式的内容.
* @author LamGC
*/
public final class CharSequenceMessage implements Message {
private final CharSequence content;
+ /**
+ * 构造一个 CharSequenceMessage.
+ * @param content 字符序列形式的内容.
+ * @throws NullPointerException 当 content 为 {@code null},
+ * 或 content 为 {@link Message} 且 {@link Message#contentToString()} 返回 {@code null} 时抛出.
+ */
public CharSequenceMessage(CharSequence content) {
+ Objects.requireNonNull(content);
+
if (content instanceof Message) {
- this.content = ((Message) content).contentToString();
+ this.content = Objects.requireNonNull(((Message) content).contentToString());
} else {
this.content = content;
}
diff --git a/ContentGrabbingJi-framework-api/src/test/java/net/lamgc/cgj/bot/framework/message/CharSequenceMessageTest.java b/ContentGrabbingJi-framework-api/src/test/java/net/lamgc/cgj/bot/framework/message/CharSequenceMessageTest.java
new file mode 100644
index 0000000..682bd67
--- /dev/null
+++ b/ContentGrabbingJi-framework-api/src/test/java/net/lamgc/cgj/bot/framework/message/CharSequenceMessageTest.java
@@ -0,0 +1,70 @@
+/*
+ * Copyright (C) 2020 LamGC
+ *
+ * ContentGrabbingJi is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * ContentGrabbingJi is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see