diff --git a/infra/common/src/test/java/cn/hippo4j/common/toolkit/MessageWrapperTest b/infra/common/src/test/java/cn/hippo4j/common/toolkit/MessageWrapperTest new file mode 100644 index 00000000..7a18ea75 --- /dev/null +++ b/infra/common/src/test/java/cn/hippo4j/common/toolkit/MessageWrapperTest @@ -0,0 +1,80 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package cn.hippo4j.common.monitor; + +import cn.hippo4j.common.monitor.MessageTypeEnum; +import cn.hippo4j.common.monitor.MessageWrapper; +import org.junit.Assert; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import java.util.HashMap; +import java.util.Map; +import java.util.Arrays; +import java.util.List; +import java.util.Collections; + +public class MessageWrapperTest { + + private static List> contentParams; + private static Class responseClass; + private static MessageTypeEnum messageType; + private static MessageWrapper messageWrapper; + + @BeforeAll + static void setUp() { + // init data + Map data1 = new HashMap<>(); + data1.put("key1", "value1"); + data1.put("key2", 123); + Map data2 = new HashMap<>(); + data2.put("key3", true); + data2.put("key4", 3.14); + contentParams = Arrays.asList(data1, data2); + responseClass = String.class; + messageType = MessageTypeEnum.DEFAULT; + messageWrapper = new MessageWrapper(contentParams, responseClass, messageType); + } + + @Test + void testGetContentParams() { + Assert.assertEquals(contentParams, messageWrapper.getContentParams()); + } + + @Test + void testGetResponseClass() { + Assert.assertEquals(responseClass, messageWrapper.getResponseClass()); + } + + @Test + void testGetMessageType() { + Assert.assertEquals(messageType, messageWrapper.getMessageType()); + } + + @Test + void testSettersAndGetters() { + List> newContentParams = Collections.singletonList(Collections.emptyMap()); + Class newResponseClass = Integer.class; + MessageTypeEnum newMessageType = MessageTypeEnum.DEFAULT; + messageWrapper.setContentParams(newContentParams); + messageWrapper.setResponseClass(newResponseClass); + messageWrapper.setMessageType(newMessageType); + Assert.assertEquals(newContentParams, messageWrapper.getContentParams()); + Assert.assertEquals(newResponseClass, messageWrapper.getResponseClass()); + Assert.assertEquals(newMessageType, messageWrapper.getMessageType()); + } +}