@Test void convertJsonException() throws IOException { Json eventGenerationIds = mock(Json.class); IOException e = new IOException("test exception"); when(eventGenerationIds.get(any(Class.class))).thenThrow(e); UserSyncStatus status = new UserSyncStatus(); status.setStack(mock(Stack.class)); status.setUmsEventGenerationIds(eventGenerationIds); UserSyncStatusResponse response = underTest.convert(status); assertThat(response) .returns(null, UserSyncStatusResponse::getLastStartedUserSyncId) .returns(null, UserSyncStatusResponse::getLastSuccessfulUserSyncId) .returns(null, UserSyncStatusResponse::getEventGenerationIds); }
@Override public UserSyncStatusResponse convert(UserSyncStatus userSyncStatus) { UserSyncStatusResponse response = new UserSyncStatusResponse(); Optional.ofNullable(userSyncStatus.getLastStartedFullSync()).ifPresent(op -> response.setLastStartedUserSyncId(op.getOperationId())); Optional.ofNullable(userSyncStatus.getLastSuccessfulFullSync()).ifPresent(op -> response.setLastSuccessfulUserSyncId(op.getOperationId())); Optional.ofNullable(userSyncStatus.getUmsEventGenerationIds()).ifPresent(eids -> { try { response.setEventGenerationIds(eids.get(UmsEventGenerationIds.class).getEventGenerationIds()); } catch (IOException e) { LOGGER.warn("Failed to convert event generation ids [{}] for environment '{}'", userSyncStatus.getUmsEventGenerationIds(), userSyncStatus.getStack().getEnvironmentCrn()); } }); return response; }
UserSyncStatusToUserSyncStatusResponseConverter implements Converter<UserSyncStatus, UserSyncStatusResponse> { @Override public UserSyncStatusResponse convert(UserSyncStatus userSyncStatus) { UserSyncStatusResponse response = new UserSyncStatusResponse(); Optional.ofNullable(userSyncStatus.getLastStartedFullSync()).ifPresent(op -> response.setLastStartedUserSyncId(op.getOperationId())); Optional.ofNullable(userSyncStatus.getLastSuccessfulFullSync()).ifPresent(op -> response.setLastSuccessfulUserSyncId(op.getOperationId())); Optional.ofNullable(userSyncStatus.getUmsEventGenerationIds()).ifPresent(eids -> { try { response.setEventGenerationIds(eids.get(UmsEventGenerationIds.class).getEventGenerationIds()); } catch (IOException e) { LOGGER.warn("Failed to convert event generation ids [{}] for environment '{}'", userSyncStatus.getUmsEventGenerationIds(), userSyncStatus.getStack().getEnvironmentCrn()); } }); return response; } }
UserSyncStatusToUserSyncStatusResponseConverter implements Converter<UserSyncStatus, UserSyncStatusResponse> { @Override public UserSyncStatusResponse convert(UserSyncStatus userSyncStatus) { UserSyncStatusResponse response = new UserSyncStatusResponse(); Optional.ofNullable(userSyncStatus.getLastStartedFullSync()).ifPresent(op -> response.setLastStartedUserSyncId(op.getOperationId())); Optional.ofNullable(userSyncStatus.getLastSuccessfulFullSync()).ifPresent(op -> response.setLastSuccessfulUserSyncId(op.getOperationId())); Optional.ofNullable(userSyncStatus.getUmsEventGenerationIds()).ifPresent(eids -> { try { response.setEventGenerationIds(eids.get(UmsEventGenerationIds.class).getEventGenerationIds()); } catch (IOException e) { LOGGER.warn("Failed to convert event generation ids [{}] for environment '{}'", userSyncStatus.getUmsEventGenerationIds(), userSyncStatus.getStack().getEnvironmentCrn()); } }); return response; }  }
UserSyncStatusToUserSyncStatusResponseConverter implements Converter<UserSyncStatus, UserSyncStatusResponse> { @Override public UserSyncStatusResponse convert(UserSyncStatus userSyncStatus) { UserSyncStatusResponse response = new UserSyncStatusResponse(); Optional.ofNullable(userSyncStatus.getLastStartedFullSync()).ifPresent(op -> response.setLastStartedUserSyncId(op.getOperationId())); Optional.ofNullable(userSyncStatus.getLastSuccessfulFullSync()).ifPresent(op -> response.setLastSuccessfulUserSyncId(op.getOperationId())); Optional.ofNullable(userSyncStatus.getUmsEventGenerationIds()).ifPresent(eids -> { try { response.setEventGenerationIds(eids.get(UmsEventGenerationIds.class).getEventGenerationIds()); } catch (IOException e) { LOGGER.warn("Failed to convert event generation ids [{}] for environment '{}'", userSyncStatus.getUmsEventGenerationIds(), userSyncStatus.getStack().getEnvironmentCrn()); } }); return response; }  @Override UserSyncStatusResponse convert(UserSyncStatus userSyncStatus); }
UserSyncStatusToUserSyncStatusResponseConverter implements Converter<UserSyncStatus, UserSyncStatusResponse> { @Override public UserSyncStatusResponse convert(UserSyncStatus userSyncStatus) { UserSyncStatusResponse response = new UserSyncStatusResponse(); Optional.ofNullable(userSyncStatus.getLastStartedFullSync()).ifPresent(op -> response.setLastStartedUserSyncId(op.getOperationId())); Optional.ofNullable(userSyncStatus.getLastSuccessfulFullSync()).ifPresent(op -> response.setLastSuccessfulUserSyncId(op.getOperationId())); Optional.ofNullable(userSyncStatus.getUmsEventGenerationIds()).ifPresent(eids -> { try { response.setEventGenerationIds(eids.get(UmsEventGenerationIds.class).getEventGenerationIds()); } catch (IOException e) { LOGGER.warn("Failed to convert event generation ids [{}] for environment '{}'", userSyncStatus.getUmsEventGenerationIds(), userSyncStatus.getStack().getEnvironmentCrn()); } }); return response; }  @Override UserSyncStatusResponse convert(UserSyncStatus userSyncStatus);  }