Skip to content

Commit c4a77f1

Browse files
committed
Fixed QA issue while reading data
1 parent 774786f commit c4a77f1

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed

src/test/java/com/igot/cb/service/ContentStateServiceImplTest.java

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
import org.mockito.Mock;
1313
import org.mockito.junit.jupiter.MockitoExtension;
1414
import org.springframework.http.HttpStatus;
15+
import org.springframework.test.util.ReflectionTestUtils;
1516

17+
import java.time.Instant;
1618
import java.util.*;
1719

1820
import static org.junit.jupiter.api.Assertions.*;
@@ -255,4 +257,68 @@ void testMapPayloadToCassandraColumns() {
255257
Map<String, Object> result = ContentStateServiceImpl.mapPayloadToCassandraColumns(payload, mapping);
256258
assertEquals("bar", result.get("baz"));
257259
}
260+
261+
@Test
262+
void testConvertInstantsToString_singleInstant() {
263+
Instant now = Instant.now();
264+
Object result = invokeConvert(now);
265+
266+
assertTrue(result instanceof String);
267+
assertEquals(now.toString(), result);
268+
}
269+
270+
@Test
271+
void testConvertInstantsToString_mapWithInstant() {
272+
Instant now = Instant.now();
273+
Map<String, Object> input = Map.of("time", now);
274+
275+
Object result = invokeConvert(input);
276+
277+
assertTrue(result instanceof Map);
278+
assertEquals(now.toString(), ((Map<?, ?>) result).get("time"));
279+
}
280+
281+
@Test
282+
void testConvertInstantsToString_listWithInstant() {
283+
Instant now = Instant.now();
284+
List<Object> input = List.of(now, "test");
285+
286+
Object result = invokeConvert(input);
287+
288+
assertTrue(result instanceof List);
289+
assertEquals(now.toString(), ((List<?>) result).get(0));
290+
assertEquals("test", ((List<?>) result).get(1));
291+
}
292+
293+
@Test
294+
void testConvertInstantsToString_nestedMapAndList() {
295+
Instant now = Instant.now();
296+
Map<String, Object> input = Map.of(
297+
"list", List.of(Map.of("time", now))
298+
);
299+
300+
Object result = invokeConvert(input);
301+
302+
assertEquals(
303+
now.toString(),
304+
((Map<?, ?>) ((List<?>) ((Map<?, ?>) result).get("list")).get(0)).get("time")
305+
);
306+
}
307+
308+
@Test
309+
void testConvertInstantsToString_nonInstantValue() {
310+
String value = "not a time";
311+
Object result = invokeConvert(value);
312+
313+
assertSame(value, result);
314+
}
315+
316+
private Object invokeConvert(Object value) {
317+
// Call the private static method using ReflectionTestUtils
318+
return ReflectionTestUtils.invokeMethod(
319+
ContentStateServiceImpl.class,
320+
"convertInstantsToString",
321+
value
322+
);
323+
}
258324
}

0 commit comments

Comments
 (0)