### Question:
AttributeQueryService { public void sendAttributeQueryRequest( final SessionId sessionId, final AbstractAttributeQueryRequestDto attributeQueryRequestDto) { AttributeQueryContainerDto attributeQueryContainerDto = attributeQueryRequestDto.sendToSamlEngine(samlEngineProxy); generateAndSendMatchingServiceRequest(sessionId, attributeQueryRequestDto.isOnboarding(), attributeQueryContainerDto); } @Inject  AttributeQueryService(SamlEngineProxy samlEngineProxy, SamlSoapProxyProxy samlSoapProxyProxy); void sendAttributeQueryRequest(
        final SessionId sessionId,
        final AbstractAttributeQueryRequestDto attributeQueryRequestDto);  }### Answer:
@Test public void shouldGenerateAttributeQueryAndSendRequestToMatchingService() { AttributeQueryRequestDto attributeQueryRequestDto = AttributeQueryRequestBuilder.anAttributeQueryRequest().build(); AttributeQueryContainerDto build = anAttributeQueryContainerDto().build(); when(samlEngineProxy.generateAttributeQuery(attributeQueryRequestDto)).thenReturn(build); service.sendAttributeQueryRequest(sessionId, attributeQueryRequestDto); verify(samlEngineProxy).generateAttributeQuery(attributeQueryRequestDto); verify(samlSoapProxyProxy).sendHubMatchingServiceRequest(eq(sessionId), any()); }
@Test(expected = ApplicationException.class) public void shouldPropagateExceptionThrownBySamlEngineAndNotSendAttributeQuery() { AttributeQueryRequestDto attributeQueryRequestDto = AttributeQueryRequestBuilder.anAttributeQueryRequest().build(); when(samlEngineProxy.generateAttributeQuery(attributeQueryRequestDto)) .thenThrow(ApplicationException.createAuditedException(INVALID_SAML, UUID.randomUUID())); service.sendAttributeQueryRequest(sessionId, attributeQueryRequestDto); verify(samlEngineProxy, times(1)).generateAttributeQuery(attributeQueryRequestDto); verify(samlSoapProxyProxy, times(0)).sendHubMatchingServiceRequest(eq(sessionId), any()); }
@Test public void shouldGenerateEidasAttributeQueryAndSendRequestToMatchingService() { final EidasAttributeQueryRequestDto eidasAttributeQueryRequestDto = anEidasAttributeQueryRequestDto().build(); final AttributeQueryContainerDto attributeQueryContainerDto = anAttributeQueryContainerDto().build(); final AttributeQueryRequest attributeQueryRequest = new AttributeQueryRequest( attributeQueryContainerDto.getId(), attributeQueryContainerDto.getIssuer(), attributeQueryContainerDto.getSamlRequest(), attributeQueryContainerDto.getMatchingServiceUri(), attributeQueryContainerDto.getAttributeQueryClientTimeOut(), eidasAttributeQueryRequestDto.isOnboarding() ); when(samlEngineProxy.generateEidasAttributeQuery(eidasAttributeQueryRequestDto)).thenReturn(attributeQueryContainerDto); service.sendAttributeQueryRequest(sessionId, eidasAttributeQueryRequestDto); verify(samlEngineProxy).generateEidasAttributeQuery(eidasAttributeQueryRequestDto); verify(samlSoapProxyProxy).sendHubMatchingServiceRequest(sessionId, attributeQueryRequest); }