ResponseStatusMapper extends AbstractParameterMapper<ResponseStatus> implements CustomConverter { @SuppressWarnings("unchecked") @Override public Object convert(Object destination, Object source, Class<?> destinationClass, Class<?> sourceClass) { if (source == null) { return null; } if (source instanceof Map<?, ?>) { ResponseStatus responseStatus = destination != null ? (ResponseStatus) destination : new ResponseStatus(); return fromParameters((Map<String, Object>) source, responseStatus); } if (source instanceof ResponseStatus) { ResponseStatus responseStatus = (ResponseStatus) source; Map<String, Object> map = destination != null ? (Map<String, Object>) destination : new HashMap<>(); return toParameters(responseStatus, map); } throw new IllegalArgumentException(buildIllegalArgumentExceptionMessage(source, destination)); } ResponseStatusMapper(); @Override ResponseStatus fromParameters(Map<String, Object> source, ResponseStatus responseStatus); @Override Map<String, Object> toParameters(ResponseStatus responseStatus, Map<String, Object> map); @SuppressWarnings("unchecked") @Override Object convert(Object destination, Object source, Class<?> destinationClass, Class<?> sourceClass);  }
@Test void testConvertMapToResponseStatus_SuccessWithWarning() { MapWrapper wrapMap = MapWrapper.successWithWarning(); Map<String, Object> map = wrapMap.getMap(); ResponseStatus responseStatus = new ResponseStatus(); this.mapper.convert(responseStatus, map, responseStatus.getClass(), map.getClass()); assertEquals(responseStatus.getGeosupportReturnCode().getReturnCode(), wrapMap.getReturnCode1()); assertEquals(responseStatus.getGeosupportReturnCode().getReasonCode(), wrapMap.getReasonCode1()); assertEquals(responseStatus.getGeosupportReturnCode().getMessage(), wrapMap.getMessage1()); assertEquals(responseStatus.getGeosupportReturnCode2().getReturnCode(), wrapMap.getReturnCode2()); assertEquals(responseStatus.getGeosupportReturnCode2().getReasonCode(), wrapMap.getReasonCode2()); assertEquals(responseStatus.getGeosupportReturnCode2().getMessage(), wrapMap.getMessage2()); assertTrue(responseStatus.getSimilarNames().isEmpty()); }
@Test void testConvertResponseStatusToMap_SuccessWithWarning() { ResponseStatus source = new ResponseStatus(); Map<String, Object> destination = new HashMap<>(); MapWrapper fixtureData = MapWrapper.successWithWarning(); GeosupportReturnCode expectedGrc1 = resetAndPopulate(source, fixtureData, true); GeosupportReturnCode expectedGrc2 = resetAndPopulate(source, fixtureData, false); this.mapper.convert(destination, source, destination.getClass(), source.getClass()); MapWrapper actualWrappedMap = new MapWrapper(destination); assertEquals(expectedGrc1.getReturnCode(), actualWrappedMap.getReturnCode1()); assertEquals(expectedGrc1.getReasonCode(), actualWrappedMap.getReasonCode1()); assertEquals(expectedGrc1.getMessage(), actualWrappedMap.getMessage1()); assertEquals(expectedGrc2.getReturnCode(), actualWrappedMap.getReturnCode2()); assertEquals(expectedGrc2.getReasonCode(), actualWrappedMap.getReasonCode2()); assertEquals(expectedGrc2.getMessage(), actualWrappedMap.getMessage2()); }