Skip to content

Commit dd2c19c

Browse files
Flossyclaude
andcommitted
Fix GitHub issue #129: Add StringifiableTest for interface coverage
Created comprehensive test suite for Stringifiable interface to verify constants and contract. This completes test coverage - every production Java file now has a corresponding test file. **Tests added (12 total):** - testLineSeparatorPropertyConstant() - Verifies property name constant - testLineSeparatorConstant() - Verifies line separator matches system property - testLineSeparatorIsNotEmpty() - Validates line separator has content - testDefaultPrefixConstant() - Verifies default prefix is 4 spaces - testDefaultPrefixIsFourSpaces() - Validates prefix contains only spaces - testInterfaceHasExpectedMethods() - Verifies all 3 toStringBuilder overloads exist - testAbstractStringifiableImplementsInterface() - Confirms implementation relationship - testLineSeparatorFieldIsPublicStaticFinal() - Validates field modifiers - testDefaultPrefixFieldIsPublicStaticFinal() - Validates field modifiers - testLineSeparatorPropertyFieldIsPublicStaticFinal() - Validates field modifiers - testConstantFieldsAreStrings() - Verifies field types - testInterfaceMethodsReturnStringBuilder() - Verifies method return types **Benefits:** - Complete test coverage pattern (every source file has test file) - Constants are validated and documented through tests - Interface contract is verified - Regression protection for constants - Executable documentation of interface design Total tests: 277 (was 265, +12) All tests pass with 100% coverage maintained. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent f0e4643 commit dd2c19c

1 file changed

Lines changed: 122 additions & 0 deletions

File tree

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
package org.flossware.jcommons;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
import static org.junit.jupiter.api.Assertions.*;
6+
7+
/**
8+
* Test class for Stringifiable interface.
9+
* Verifies constants and interface contract.
10+
*/
11+
class StringifiableTest {
12+
13+
@Test
14+
void testLineSeparatorPropertyConstant() {
15+
assertEquals("line.separator", Stringifiable.LINE_SEPARATOR_PROPERTY);
16+
}
17+
18+
@Test
19+
void testLineSeparatorConstant() {
20+
assertNotNull(Stringifiable.LINE_SEPARATOR_STRING);
21+
assertEquals(System.getProperty(Stringifiable.LINE_SEPARATOR_PROPERTY),
22+
Stringifiable.LINE_SEPARATOR_STRING);
23+
}
24+
25+
@Test
26+
void testLineSeparatorIsNotEmpty() {
27+
assertNotNull(Stringifiable.LINE_SEPARATOR_STRING);
28+
assertFalse(Stringifiable.LINE_SEPARATOR_STRING.isEmpty());
29+
// On Unix: \n, On Windows: \r\n
30+
assertTrue(Stringifiable.LINE_SEPARATOR_STRING.length() >= 1);
31+
}
32+
33+
@Test
34+
void testDefaultPrefixConstant() {
35+
assertEquals(" ", Stringifiable.DEFAULT_PREFIX);
36+
assertEquals(4, Stringifiable.DEFAULT_PREFIX.length());
37+
}
38+
39+
@Test
40+
void testDefaultPrefixIsFourSpaces() {
41+
for (char c : Stringifiable.DEFAULT_PREFIX.toCharArray()) {
42+
assertEquals(' ', c, "Default prefix should only contain spaces");
43+
}
44+
}
45+
46+
@Test
47+
void testInterfaceHasExpectedMethods() throws NoSuchMethodException {
48+
// Verify all three toStringBuilder overloads exist
49+
Stringifiable.class.getMethod("toStringBuilder",
50+
StringBuilder.class, String.class);
51+
Stringifiable.class.getMethod("toStringBuilder",
52+
StringBuilder.class);
53+
Stringifiable.class.getMethod("toStringBuilder",
54+
String.class);
55+
}
56+
57+
@Test
58+
void testAbstractStringifiableImplementsInterface() {
59+
assertTrue(Stringifiable.class.isAssignableFrom(
60+
AbstractStringifiable.class));
61+
}
62+
63+
@Test
64+
void testLineSeparatorFieldIsPublicStaticFinal() throws NoSuchFieldException {
65+
var lineSepField = Stringifiable.class.getField("LINE_SEPARATOR_STRING");
66+
67+
assertTrue(java.lang.reflect.Modifier.isPublic(
68+
lineSepField.getModifiers()));
69+
assertTrue(java.lang.reflect.Modifier.isStatic(
70+
lineSepField.getModifiers()));
71+
assertTrue(java.lang.reflect.Modifier.isFinal(
72+
lineSepField.getModifiers()));
73+
}
74+
75+
@Test
76+
void testDefaultPrefixFieldIsPublicStaticFinal() throws NoSuchFieldException {
77+
var prefixField = Stringifiable.class.getField("DEFAULT_PREFIX");
78+
79+
assertTrue(java.lang.reflect.Modifier.isPublic(
80+
prefixField.getModifiers()));
81+
assertTrue(java.lang.reflect.Modifier.isStatic(
82+
prefixField.getModifiers()));
83+
assertTrue(java.lang.reflect.Modifier.isFinal(
84+
prefixField.getModifiers()));
85+
}
86+
87+
@Test
88+
void testLineSeparatorPropertyFieldIsPublicStaticFinal() throws NoSuchFieldException {
89+
var propertyField = Stringifiable.class.getField("LINE_SEPARATOR_PROPERTY");
90+
91+
assertTrue(java.lang.reflect.Modifier.isPublic(
92+
propertyField.getModifiers()));
93+
assertTrue(java.lang.reflect.Modifier.isStatic(
94+
propertyField.getModifiers()));
95+
assertTrue(java.lang.reflect.Modifier.isFinal(
96+
propertyField.getModifiers()));
97+
}
98+
99+
@Test
100+
void testConstantFieldsAreStrings() throws NoSuchFieldException {
101+
assertEquals(String.class,
102+
Stringifiable.class.getField("LINE_SEPARATOR_STRING").getType());
103+
assertEquals(String.class,
104+
Stringifiable.class.getField("DEFAULT_PREFIX").getType());
105+
assertEquals(String.class,
106+
Stringifiable.class.getField("LINE_SEPARATOR_PROPERTY").getType());
107+
}
108+
109+
@Test
110+
void testInterfaceMethodsReturnStringBuilder() throws NoSuchMethodException {
111+
var method1 = Stringifiable.class.getMethod("toStringBuilder",
112+
StringBuilder.class, String.class);
113+
var method2 = Stringifiable.class.getMethod("toStringBuilder",
114+
StringBuilder.class);
115+
var method3 = Stringifiable.class.getMethod("toStringBuilder",
116+
String.class);
117+
118+
assertEquals(StringBuilder.class, method1.getReturnType());
119+
assertEquals(StringBuilder.class, method2.getReturnType());
120+
assertEquals(StringBuilder.class, method3.getReturnType());
121+
}
122+
}

0 commit comments

Comments
 (0)