Skip to content

Commit bfe3348

Browse files
committed
Add JUnit 4 tests for search element model and style classes
Added 100% test coverage for * `ContentSearchElement` * `MetaDataSearchElement` * `MessageFilterToStringStyle` * `SearchElementToStringStyle` * `ContentSearchElementToStringStyle` Signed-off-by: Tony Germano <tony@germano.name>
1 parent 7311e1b commit bfe3348

5 files changed

Lines changed: 309 additions & 0 deletions

File tree

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
// SPDX-License-Identifier: MPL-2.0
2+
// SPDX-FileCopyrightText: 2026 Tony Germano <tony@germano.name>
3+
4+
packagecom.mirth.connect.model;
5+
6+
importstaticorg.junit.Assert.assertEquals;
7+
8+
importjava.util.List;
9+
10+
importorg.apache.commons.lang3.builder.ToStringBuilder;
11+
importorg.junit.Test;
12+
13+
importcom.mirth.connect.donkey.model.message.ContentType;
14+
15+
publicclassContentSearchElementToStringStyleTest {
16+
17+
@Test
18+
publicvoidtestContentCodeFormatting() {
19+
// Test standard known codes
20+
assertContentCodeFormat(ContentType.RAW.getContentTypeCode(), "1(Raw)");
21+
assertContentCodeFormat(ContentType.PROCESSED_RAW.getContentTypeCode(), "2(Processed Raw)");
22+
assertContentCodeFormat(ContentType.TRANSFORMED.getContentTypeCode(), "3(Transformed)");
23+
assertContentCodeFormat(ContentType.PROCESSING_ERROR.getContentTypeCode(), "12(Processing Error)");
24+
}
25+
26+
@Test
27+
publicvoidtestUnknownContentCode() {
28+
// Test an integer that doesn't map to a ContentType
29+
varunknownCode = 999;
30+
31+
// Cast to Object to ensure we hit the appendDetail(StringBuffer, String, Object) method
32+
varresult = newToStringBuilder(newObject(), ContentSearchElementToStringStyle.instance())
33+
.append("contentCode", (Object) unknownCode)
34+
.toString();
35+
36+
assertEquals("Object[contentCode=999(UNKNOWN)]", result);
37+
}
38+
39+
@Test
40+
publicvoidtestOtherIntegerFields() {
41+
// Ensure that integer fields NOT named "contentCode" are treated normally
42+
varresult = newToStringBuilder(newObject(), ContentSearchElementToStringStyle.instance())
43+
.append("someOtherId", (Object) 1)
44+
.toString();
45+
46+
assertEquals("Object[someOtherId=1]", result);
47+
}
48+
49+
@Test
50+
publicvoidtestContentCodeNonInteger() {
51+
// Covers the "else" branch in appendDetail where fieldname is "contentCode"
52+
// but value is NOT an instanceof Integer.
53+
varresult = newToStringBuilder(newObject(), ContentSearchElementToStringStyle.instance())
54+
.append("contentCode", "NotAnInteger")
55+
.toString();
56+
57+
assertEquals("Object[contentCode=NotAnInteger]", result);
58+
}
59+
60+
@Test
61+
publicvoidtestCollectionFormatting() {
62+
varlist = List.of("A", "B");
63+
64+
varresult = newToStringBuilder(newObject(), ContentSearchElementToStringStyle.instance())
65+
.append("list", list)
66+
.toString();
67+
68+
assertEquals("Object[list=[A, B]]", result);
69+
}
70+
71+
privatevoidassertContentCodeFormat(intcode, StringexpectedValue) {
72+
// Cast to Object to ensure we hit the appendDetail(StringBuffer, String, Object) method
73+
varresult = newToStringBuilder(newObject(), ContentSearchElementToStringStyle.instance())
74+
.append("contentCode", (Object) code)
75+
.toString();
76+
77+
assertEquals("Object[contentCode=" + expectedValue + "]", result);
78+
}
79+
}
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
// SPDX-License-Identifier: MPL-2.0
2+
// SPDX-FileCopyrightText: 2026 Tony Germano <tony@germano.name>
3+
4+
packagecom.mirth.connect.model;
5+
6+
importstaticorg.junit.Assert.assertEquals;
7+
8+
importjava.time.ZoneId;
9+
importjava.time.ZonedDateTime;
10+
importjava.util.GregorianCalendar;
11+
importjava.util.List;
12+
13+
importorg.apache.commons.lang3.builder.ToStringBuilder;
14+
importorg.junit.Test;
15+
16+
publicclassMessageFilterToStringStyleTest {
17+
18+
@Test
19+
publicvoidtestDateFormatting() {
20+
varcal = GregorianCalendar.from(ZonedDateTime.of(2023, 10, 25, 14, 30, 0, 0, ZoneId.of("America/New_York")));
21+
22+
varresult = newToStringBuilder(newObject(), MessageFilterToStringStyle.instance())
23+
.append("date", cal)
24+
.toString();
25+
26+
// Format: uuuu-MM-dd HH:mmXXX'['VV']'
27+
varexpected = "Object[" + System.lineSeparator() +
28+
" date=2023-10-25 14:30-04:00[America/New_York]" + System.lineSeparator() +
29+
"]";
30+
assertEquals(expected, result);
31+
}
32+
33+
@Test
34+
publicvoidtestRegularObjectField() {
35+
varresult = newToStringBuilder(newObject(), MessageFilterToStringStyle.instance())
36+
.append("myField", "myValue")
37+
.toString();
38+
39+
varexpected = "Object[" + System.lineSeparator() +
40+
" myField=myValue" + System.lineSeparator() +
41+
"]";
42+
assertEquals(expected, result);
43+
}
44+
45+
@Test
46+
publicvoidtestFlattenedFields() {
47+
// "excludedMetaDataIds" is in the flatten set
48+
varids = List.of("ID1", "ID2");
49+
50+
varresult = newToStringBuilder(newObject(), MessageFilterToStringStyle.instance())
51+
.append("excludedMetaDataIds", ids)
52+
.toString();
53+
54+
varexpected = "Object[" + System.lineSeparator() +
55+
" excludedMetaDataIds=[ID1, ID2]" + System.lineSeparator() +
56+
"]";
57+
assertEquals(expected, result);
58+
}
59+
60+
@Test
61+
publicvoidtestNonFlattenedCollectionIndentation() {
62+
varlist = List.of("Item1", "Item2");
63+
64+
varresult = newToStringBuilder(newObject(), MessageFilterToStringStyle.instance())
65+
.append("regularList", list)
66+
.toString();
67+
68+
varexpected = """
69+
Object[
70+
regularList=[
71+
Item1,
72+
Item2
73+
]
74+
]""";
75+
76+
// Normalize line endings for comparison
77+
assertEquals(expected.replace("\n", System.lineSeparator()), result);
78+
}
79+
80+
@Test
81+
publicvoidtestNestedArrayIndentation() {
82+
varnested = newObject[] { "Inner" };
83+
varouter = newObject[] { nested };
84+
85+
varresult = newToStringBuilder(newObject(), MessageFilterToStringStyle.instance())
86+
.append("nested", outer)
87+
.toString();
88+
89+
varexpected = """
90+
Object[
91+
nested=[
92+
[
93+
Inner
94+
]
95+
]
96+
]""";
97+
98+
assertEquals(expected.replace("\n", System.lineSeparator()), result);
99+
}
100+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// SPDX-License-Identifier: MPL-2.0
2+
// SPDX-FileCopyrightText: 2026 Tony Germano <tony@germano.name>
3+
4+
packagecom.mirth.connect.model;
5+
6+
importstaticorg.junit.Assert.assertEquals;
7+
8+
importorg.apache.commons.lang3.builder.ToStringBuilder;
9+
importorg.junit.Test;
10+
11+
publicclassSearchElementToStringStyleTest {
12+
13+
@Test
14+
publicvoidtestStringQuoting() {
15+
varresult = newToStringBuilder(newObject(), SearchElementToStringStyle.instance())
16+
.append("field", "value")
17+
.toString();
18+
19+
assertEquals("Object[field=value]", result);
20+
}
21+
22+
@Test
23+
publicvoidtestNonStringNoQuotes() {
24+
varval = 123;
25+
varresult = newToStringBuilder(newObject(), SearchElementToStringStyle.instance())
26+
.append("number", val)
27+
.toString();
28+
29+
assertEquals("Object[number=123]", result);
30+
}
31+
32+
@Test
33+
publicvoidtestNullValue() {
34+
varresult = newToStringBuilder(newObject(), SearchElementToStringStyle.instance())
35+
.append("nullField", (Object) null)
36+
.toString();
37+
38+
assertEquals("Object[nullField=<null>]", result);
39+
}
40+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// SPDX-License-Identifier: MPL-2.0
2+
// SPDX-FileCopyrightText: 2026 Tony Germano <tony@germano.name>
3+
4+
packagecom.mirth.connect.model.filters.elements;
5+
6+
importstaticorg.junit.Assert.assertEquals;
7+
8+
importjava.util.List;
9+
10+
importorg.junit.Test;
11+
12+
importcom.mirth.connect.donkey.model.message.ContentType;
13+
14+
publicclassContentSearchElementTest {
15+
16+
@Test
17+
publicvoidtestAccessors() {
18+
varcode = 1;
19+
varsearches = List.of("search1", "search2");
20+
21+
varelement = newContentSearchElement(code, searches);
22+
23+
assertEquals(code, element.getContentCode());
24+
assertEquals(searches, element.getSearches());
25+
26+
element.setContentCode(2);
27+
assertEquals(2, element.getContentCode());
28+
29+
varnewSearches = List.of("new1");
30+
element.setSearches(newSearches);
31+
assertEquals(newSearches, element.getSearches());
32+
}
33+
34+
@Test
35+
publicvoidtestToStringIntegration() {
36+
// contentCode 1 = RAW
37+
varelement = newContentSearchElement(ContentType.RAW.getContentTypeCode(), List.of("foo", "bar"));
38+
39+
varstringVal = element.toString();
40+
41+
varexpected = "ContentSearchElement[contentCode=1(Raw), searches=[foo, bar]]";
42+
43+
assertEquals(expected, stringVal);
44+
}
45+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// SPDX-License-Identifier: MPL-2.0
2+
// SPDX-FileCopyrightText: 2026 Tony Germano <tony@germano.name>
3+
4+
packagecom.mirth.connect.model.filters.elements;
5+
6+
importstaticorg.junit.Assert.assertEquals;
7+
8+
importorg.junit.Test;
9+
10+
publicclassMetaDataSearchElementTest {
11+
12+
@Test
13+
publicvoidtestAccessors() {
14+
varelement = newMetaDataSearchElement("col", "=", "val", true);
15+
16+
assertEquals("col", element.getColumnName());
17+
assertEquals("=", element.getOperator());
18+
assertEquals("val", element.getValue());
19+
assertEquals(true, element.getIgnoreCase());
20+
21+
element.setColumnName("col2");
22+
assertEquals("col2", element.getColumnName());
23+
24+
element.setOperator("!=");
25+
assertEquals("!=", element.getOperator());
26+
27+
element.setValue(100);
28+
assertEquals(100, element.getValue());
29+
30+
element.setIgnoreCase(false);
31+
assertEquals(false, element.getIgnoreCase());
32+
}
33+
34+
@Test
35+
publicvoidtestToStringIntegration() {
36+
varelement = newMetaDataSearchElement("MyCol", "EQUALS", "MyVal", true);
37+
38+
varstringVal = element.toString();
39+
40+
// ReflectionToStringBuilder sorts fields by name
41+
varexpected = "MetaDataSearchElement[columnName=MyCol, ignoreCase=true, operator=EQUALS, value=MyVal]";
42+
43+
assertEquals(expected, stringVal);
44+
}
45+
}

0 commit comments

Comments
 (0)