-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[unit test] Add unit test cases for AlertTemplateUtil (#639)
- Loading branch information
1 parent
a203ea4
commit f825612
Showing
1 changed file
with
45 additions
and
1 deletion.
There are no files selected for viewing
46 changes: 45 additions & 1 deletion
46
alerter/src/test/java/com/usthe/alert/util/AlertTemplateUtilTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} | ||
} |