Skip to content

Commit 1706857

Browse files
Test unsupported map key type throws.
1 parent ed3607a commit 1706857

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

tests/objectbox-java-test/src/test/java/io/objectbox/converter/FlexMapConverterTest.java

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -211,12 +211,25 @@ public void nullKeyOrValue_throws() {
211211
Map<String, String> map = new HashMap<>();
212212

213213
map.put("Hello", null);
214-
convertThenAssertThrows(map, converter);
214+
convertThenAssertThrows(map, converter, "Map keys or values must not be null");
215215

216216
map.clear();
217217

218218
map.put(null, "Idea");
219-
convertThenAssertThrows(map, converter);
219+
convertThenAssertThrows(map, converter, "Map keys or values must not be null");
220+
}
221+
222+
@Test
223+
public void unsupportedKey_throws() {
224+
Map<Object, Object> map = new HashMap<>();
225+
map.put(false, "supported");
226+
227+
convertThenAssertThrows(map, new FlexObjectConverter(), "Map keys must be String");
228+
convertThenAssertThrows(map, new StringLongMapConverter(), "Map keys must be String");
229+
convertThenAssertThrows(map, new IntegerFlexMapConverter(), "Map keys must be Integer");
230+
convertThenAssertThrows(map, new IntegerLongMapConverter(), "Map keys must be Integer");
231+
convertThenAssertThrows(map, new LongFlexMapConverter(), "Map keys must be Long");
232+
convertThenAssertThrows(map, new LongLongMapConverter(), "Map keys must be Long");
220233
}
221234

222235
@Test
@@ -225,7 +238,7 @@ public void unsupportedValue_throws() {
225238
Map<String, Object> map = new HashMap<>();
226239

227240
map.put("Hello", Instant.now());
228-
convertThenAssertThrows(map, converter);
241+
convertThenAssertThrows(map, converter, "Map values of this type are not supported: Instant");
229242
}
230243

231244
@SuppressWarnings("unchecked")
@@ -240,10 +253,11 @@ private <K, V> void convertAndBackThenAssert(@Nullable Map<K, V> expected, FlexO
240253
}
241254

242255
@SuppressWarnings({"rawtypes"})
243-
private void convertThenAssertThrows(Map map, FlexObjectConverter converter) {
244-
assertThrows(
256+
private void convertThenAssertThrows(Map map, FlexObjectConverter converter, String expectedMessage) {
257+
IllegalArgumentException exception = assertThrows(
245258
IllegalArgumentException.class,
246259
() -> converter.convertToDatabaseValue(map)
247260
);
261+
assertEquals(expectedMessage, exception.getMessage());
248262
}
249263
}

0 commit comments

Comments
 (0)