Skip to content

Commit

Permalink
[unit test] Add unit test cases for AlertTemplateUtil (#639)
Browse files Browse the repository at this point in the history
  • Loading branch information
Daydreamer-ia authored Feb 13, 2023
1 parent aafdbef commit 1348238
Showing 1 changed file with 45 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,21 +1,65 @@
package com.usthe.alert.util;

import com.usthe.alert.service.AlertService;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.util.HashMap;
import java.util.Map;

import static org.junit.jupiter.api.Assertions.*;

/**
* Test case for {@link AlertTemplateUtil}
*/
class AlertTemplateUtilTest {

class TemplateValue {

}

@BeforeEach
void setUp() {
}

@Test
void render() {
// test null template case
Map<String, Object> param = new HashMap<>();
String template = null;
assertNull(AlertTemplateUtil.render(null, param));
// test null map case
template = "${key} for testing";
assertEquals(AlertTemplateUtil.render(template, null), template);
// test null template and null map case
assertNull(AlertTemplateUtil.render(null, null));
// test illegal template case
template = "";
param.put("key", "Just");
assertEquals(AlertTemplateUtil.render(template, param), template);
template = "key for testing!";
assertEquals(AlertTemplateUtil.render(template, param), template);
// test empty map case
param.clear();
template = "${key} for testing";
assertEquals(AlertTemplateUtil.render(template, param), "NullValue for testing");
// test illegal template and empty map case
param.clear();
template = "key for testing";
assertEquals(AlertTemplateUtil.render(template, param), template);
// test one param
param.put("key", "Just");
template = "${key} for testing";
assertEquals(AlertTemplateUtil.render(template, param), "Just for testing");
// test two param
param.put("key1", "Just");
param.put("key2", "testing");
template = "${key1} for ${key2}";
assertEquals(AlertTemplateUtil.render(template, param), "Just for testing");
// test all param
param.put("key1", "Just");
param.put("key2", "for");
param.put("key3", "testing");
template = "${key1} ${key2} ${key3}";
assertEquals(AlertTemplateUtil.render(template, param), "Just for testing");
}
}

0 comments on commit 1348238

Please sign in to comment.