### Question:
VariableValueJsonConverter implements AttributeConverter<VariableValue<?>, String> { @Override public String convertToDatabaseColumn(VariableValue<?> variableValue) { try { return objectMapper.writeValueAsString(variableValue); } catch (JsonProcessingException e) { throw new QueryException("Unable to serialize variable.", e); } } VariableValueJsonConverter();  VariableValueJsonConverter(ObjectMapper objectMapper); @Override String convertToDatabaseColumn(VariableValue<?> variableValue); @Override VariableValue<?> convertToEntityAttribute(String dbData);  }### Answer:
@Test public void convertToDatabaseColumnShouldConvertToJson() throws Exception { given(objectMapper.writeValueAsString(ENTITY_REPRESENTATION)).willReturn(JSON_REPRESENTATION); String convertedValue = converter.convertToDatabaseColumn(ENTITY_REPRESENTATION); assertThat(convertedValue).isEqualTo(JSON_REPRESENTATION); }
@Test public void convertToDatabaseColumnShouldThrowQueryExceptionWhenAnExceptionOccursWhileProcessing() throws Exception { MockJsonProcessingException exception = new MockJsonProcessingException("any"); given(objectMapper.writeValueAsString(ENTITY_REPRESENTATION)).willThrow(exception); Throwable thrown = catchThrowable(() -> converter.convertToDatabaseColumn(ENTITY_REPRESENTATION)); assertThat(thrown) .isInstanceOf(QueryException.class) .hasMessage("Unable to serialize variable.") .hasCause(exception); }