Skip to content

Commit 2fe8746

Browse files
Add unit tests for KnownProperties (#435)
* Add unit tests for KnownProperties Additive unit tests only - no existing test or production code changed. Signed-off-by: vasiliy-mikhailov <vasiliy-mikhailov@users.noreply.github.com> * Tighten JaCoCo coverage gate to match the added KnownProperties tests INSTRUCTION 45% to 53%, COMPLEXITY 0.33 to 0.42, LINE missed 1500 to 1490; verified green (605 tests). --------- Signed-off-by: vasiliy-mikhailov <vasiliy-mikhailov@users.noreply.github.com>
1 parent 1f282d6 commit 2fe8746

2 files changed

Lines changed: 50 additions & 3 deletions

File tree

pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -344,17 +344,17 @@
344344
<limit>
345345
<counter>COMPLEXITY</counter>
346346
<value>COVEREDRATIO</value>
347-
<minimum>0.33</minimum>
347+
<minimum>0.42</minimum>
348348
</limit>
349349
<limit>
350350
<counter>INSTRUCTION</counter>
351351
<value>COVEREDRATIO</value>
352-
<minimum>45%</minimum>
352+
<minimum>53%</minimum>
353353
</limit>
354354
<limit>
355355
<counter>LINE</counter>
356356
<value>MISSEDCOUNT</value>
357-
<maximum>1500</maximum>
357+
<maximum>1490</maximum>
358358
</limit>
359359
</limits>
360360
</rule>

src/test/java/com/datastax/cdm/properties/KnownPropertiesTest.java

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,4 +212,51 @@ public void validateType_Boolean() {
212212
KnownProperties.asType(KnownProperties.PropertyType.BOOLEAN, "false")));
213213
}
214214

215+
// ---- Tests to improve mutation coverage ----
216+
217+
@Test
218+
public void getDefault_unknownKey() {
219+
assertNull(KnownProperties.getDefault("nonexistent.key"));
220+
}
221+
222+
@Test
223+
public void getDefault_typeExistsButNoDefault() {
224+
assertNull(KnownProperties.getDefault(KnownProperties.TEST_STRING_NO_DEFAULT));
225+
}
226+
227+
@Test
228+
public void getDefault_stringListNoDefault() {
229+
// ORIGIN_TTL_NAMES has type STRING_LIST but no default value.
230+
// If the null-check on 'value' in getDefault is bypassed (mutant),
231+
// asType(STRING_LIST, null) would throw NPE via null.split(",").
232+
assertNull(KnownProperties.getDefault(KnownProperties.ORIGIN_TTL_NAMES));
233+
}
234+
235+
@Test
236+
public void getDefault_numberListNoDefault() {
237+
// TRANSFORM_CODECS has type STRING_LIST but no default value.
238+
// Similar to above: bypassing the null check would cause NPE.
239+
assertNull(KnownProperties.getDefault(KnownProperties.TRANSFORM_CODECS));
240+
}
241+
242+
@Test
243+
public void validateType_StringList_notAList() {
244+
assertFalse(KnownProperties.validateType(KnownProperties.PropertyType.STRING_LIST, "not a list"));
245+
}
246+
247+
@Test
248+
public void validateType_Number_notANumber() {
249+
assertFalse(KnownProperties.validateType(KnownProperties.PropertyType.NUMBER, "not a number"));
250+
}
251+
252+
@Test
253+
public void validateType_NumberList_notAList() {
254+
assertFalse(KnownProperties.validateType(KnownProperties.PropertyType.NUMBER_LIST, "not a list"));
255+
}
256+
257+
@Test
258+
public void validateType_Boolean_notABoolean() {
259+
assertFalse(KnownProperties.validateType(KnownProperties.PropertyType.BOOLEAN, "not a boolean"));
260+
}
261+
215262
}

0 commit comments

Comments
 (0)