### Question:
AttemptAuditEventResultToGrpcAttemptAuditEventResultConverter { public AuditProto.AttemptAuditEventResult convert(AttemptAuditEventResult source) { AuditProto.AttemptAuditEventResult.Builder builder = builderProvider.getNewAttemptAuditEventResultBuilder() .setId(source.getId()) .setResultCode(source.getResultCode()); doIfTrue(source.getResultMessage(), StringUtils::isNotEmpty, builder::setResultMessage); updateResultEventData(builder, source.getResultEventData()); return builder.build(); } AttemptAuditEventResultToGrpcAttemptAuditEventResultConverter(Map<Class, AttemptAuditEventResultBuilderUpdater> builderUpdaters,
                    AttemptAuditEventResultBuilderProvider builderProvider); AuditProto.AttemptAuditEventResult convert(AttemptAuditEventResult source);  }### Answer:
@Test void testPreventPossibleNullValuesNoResult() { AttemptAuditEventResult source = makeMinimalAttemptAuditEventResult(null); underTest.convert(source); }
@Test void testPreventPossibleNullValuesServiceApiRequestResult() { ResultEventData resultServiceEventData = ResultServiceEventData.builder() .withResourceCrns(CRNS) .build(); AttemptAuditEventResult source = makeMinimalAttemptAuditEventResult(resultServiceEventData); underTest = new AttemptAuditEventResultToGrpcAttemptAuditEventResultConverter(createMockUtilizer(ResultServiceEventData.class), builderProvider); underTest.convert(source); verify(mockAttemptAuditEventResultBuilderUpdater, times(1)).update(any(), any()); }
@Test void testWhenResultEventDataIsNullThenNoUtilizerCallHappens() { AttemptAuditEventResult source = makeMinimalAttemptAuditEventResult(null); underTest.convert(source); verify(mockAttemptAuditEventResultBuilderUpdater, never()).update(any(), any()); }
@Test void convertWithoutResultEventData() { AttemptAuditEventResult source = makeAttemptAuditEventResult(null); AuditProto.AttemptAuditEventResult target = underTest.convert(source); assertEquals(target, result); verify(mockBuilder, times(1)).build(); verify(builderProvider, times(1)).getNewAttemptAuditEventResultBuilder(); verify(mockAttemptAuditEventResultBuilderUpdater, never()).update(any(), any()); }
@Test void convertWithResultServiceEventData() { ResultServiceEventData rsed = ResultServiceEventData.builder() .withResourceCrns(CRNS) .withResultDetails(RESULT_DETAILS) .build(); AttemptAuditEventResult source = makeAttemptAuditEventResult(rsed); underTest = new AttemptAuditEventResultToGrpcAttemptAuditEventResultConverter(createMockUtilizer(ResultServiceEventData.class), builderProvider); AuditProto.AttemptAuditEventResult target = underTest.convert(source); assertEquals(target, result); verify(mockBuilder, times(1)).build(); verify(builderProvider, times(1)).getNewAttemptAuditEventResultBuilder(); verify(mockAttemptAuditEventResultBuilderUpdater, times(1)).update(any(), any()); }
@Test void convertWithResultApiRequestData() { ResultApiRequestData rsed = ResultApiRequestData.builder().withResponseParameters(RESPONSE_PARAMETERS).build(); AttemptAuditEventResult source = makeAttemptAuditEventResult(rsed); underTest = new AttemptAuditEventResultToGrpcAttemptAuditEventResultConverter(createMockUtilizer(ResultApiRequestData.class), builderProvider); AuditProto.AttemptAuditEventResult target = underTest.convert(source); assertEquals(target, result); verify(mockBuilder, times(1)).build(); verify(builderProvider, times(1)).getNewAttemptAuditEventResultBuilder(); verify(mockAttemptAuditEventResultBuilderUpdater, times(1)).update(any(), any()); }
@Test void convertWithUnknownResultEventDataThrows() { class Unknown extends ResultEventData { } AttemptAuditEventResult source = makeAttemptAuditEventResult(new Unknown()); assertThatThrownBy(() -> underTest.convert(source)).isInstanceOf(IllegalArgumentException.class); }