JsonValueToDbEntityMapper { public static Function<JsonObject, BsonDocument> forJsonObject(final Function<String, String> jsonKeyNameReviser) { final JsonValueToDbEntityMapper mapper = new JsonValueToDbEntityMapper(jsonKeyNameReviser); return mapper::mapJsonObjectToBsonDocument; } private  JsonValueToDbEntityMapper(final Function<String, String> theJsonKeyNameReviser); static Function<JsonObject, BsonDocument> forJsonObject(final Function<String, String> jsonKeyNameReviser); static Function<JsonArray, BsonArray> forJsonArray(final Function<String, String> jsonKeyNameReviser);  }
@Test public void tryToGetMapperForJsonObjectWithNullKeyNameReviser() { assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> forJsonObject(null)) .withMessage("The %s must not be null!", "JSON key name reviser") .withNoCause(); }
@Test public void tryToTestNullJsonObject() { final Function<String, String> jsonKeyNameReviser = Mockito.mock(Function.class); final Function<JsonObject, BsonDocument> underTest = JsonValueToDbEntityMapper.forJsonObject(jsonKeyNameReviser); assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> underTest.apply(null)) .withMessage("The %s must not be null!", "JSON object to be mapped") .withNoCause(); }
@Test public void mapJsonObjectReturnsExpectedBsonDocument() { final JsonObject jsonObject = JsonFactory.newObjectBuilder() .set("foo", JsonFactory.newObjectBuilder() .set("org.eclipse.ditto", 42) .build()) .set("something$", JsonFactory.newArrayBuilder() .add(23.42) .add(true) .add("bar") .build()) .set(JsonFactory.newKey("/with/slash"), 12345491014314L) .set("nada", JsonFactory.nullObject()) .build(); final BsonDocument expectedBsonDocument = BsonDocument.parse(jsonObject.toString()); final Function<String, String> jsonKeyNameReviser = s -> s; final Function<JsonObject, BsonDocument> underTest = JsonValueToDbEntityMapper.forJsonObject(jsonKeyNameReviser); final BsonDocument actualBasicDocument = underTest.apply(jsonObject); assertThat(actualBasicDocument).isEqualTo(expectedBsonDocument); }