Add test case for MessageWrapper

pull/1346/head
时间邮递员 2 years ago committed by GitHub
parent 55007f9c9d
commit 9737d437c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,76 @@
/*
* 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.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import java.util.*;
import static org.junit.jupiter.api.Assertions.*;
public class MessageWrapperTest {
private static List<Map<String, Object>> contentParams;
private static Class responseClass;
private static MessageTypeEnum messageType;
private static MessageWrapper messageWrapper;
@BeforeAll
static void setUp() {
// init data
Map<String, Object> data1 = new HashMap<>();
data1.put("key1", "value1");
data1.put("key2", 123);
Map<String, Object> 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() {
assertEquals(contentParams, messageWrapper.getContentParams());
}
@Test
void testGetResponseClass() {
assertEquals(responseClass, messageWrapper.getResponseClass());
}
@Test
void testGetMessageType() {
assertEquals(messageType, messageWrapper.getMessageType());
}
@Test
void testSettersAndGetters() {
List<Map<String, Object>> newContentParams = Collections.singletonList(Collections.emptyMap());
Class newResponseClass = Integer.class;
MessageTypeEnum newMessageType = MessageTypeEnum.DEFAULT;
messageWrapper.setContentParams(newContentParams);
messageWrapper.setResponseClass(newResponseClass);
messageWrapper.setMessageType(newMessageType);
assertEquals(newContentParams, messageWrapper.getContentParams());
assertEquals(newResponseClass, messageWrapper.getResponseClass());
assertEquals(newMessageType, messageWrapper.getMessageType());
}
}
Loading…
Cancel
Save