WorldpayRiskGuardianFraudSymptom extends AbstractWorldpayOrderFraudSymptomDetection { @Override public FraudServiceResponse recognizeSymptom(final FraudServiceResponse fraudServiceResponse, final AbstractOrderModel abstractOrderModel) { final List<PaymentTransactionModel> paymentTransactions = abstractOrderModel.getPaymentTransactions(); final double scoreLimit = getScoreLimit(); paymentTransactions.stream().filter(Objects::nonNull).forEach(paymentTransaction -> { final WorldpayRiskScoreModel riskScore = paymentTransaction.getRiskScore(); if (riskScore == null) { LOG.warn(MessageFormat.format("We did not get a risk score back, skipping risk check for: {0}", paymentTransaction)); return; } final Double finalScore = riskScore.getFinalScore(); if (finalScore != null && Double.compare(finalScore, scoreLimit) > 0) { setIncrement(finalScore); fraudServiceResponse.addSymptom(createSymptom(riskScore.getMessage(), true)); } }); return fraudServiceResponse; }  @Override FraudServiceResponse recognizeSymptom(final FraudServiceResponse fraudServiceResponse, final AbstractOrderModel abstractOrderModel);  }
@Test public void recognizeSymptomShouldReturnAPositiveFraudServiceResponseWhenRiskGuardianInPaymentTransactionHasScoreHigherThanConfiguredLimit() { when(orderModelMock.getPaymentTransactions()).thenReturn(singletonList(worldpayPaymentAuthoriseTransactionModelMock)); when(worldpayPaymentAuthoriseTransactionModelMock.getRiskScore()).thenReturn(worldpayRiskScoreModelMock); final double positiveFinalScore = configuredLimitValue + 10; when(worldpayRiskScoreModelMock.getFinalScore()).thenReturn(positiveFinalScore); final FraudServiceResponse fraudServiceResponse = new FraudServiceResponse(StringUtils.EMPTY); testObj.recognizeSymptom(fraudServiceResponse, orderModelMock); assertEquals(positiveFinalScore, fraudServiceResponse.getScore(), 0.0); assertEquals(positiveFinalScore, fraudServiceResponse.getSymptoms().get(0).getScore(), 0.0); assertEquals(positiveFinalScore, testObj.getIncrement(), 0.0); verify(worldpayRiskScoreModelMock).getFinalScore(); }
@Test public void recognizeSymptomShouldReturnTheSameFraudServiceResponseWhenRiskScoreIsRiskGuardianAndScoreIsLowerThanConfiguredLimit() { when(orderModelMock.getPaymentTransactions()).thenReturn(singletonList(worldpayPaymentAuthoriseTransactionModelMock)); when(worldpayPaymentAuthoriseTransactionModelMock.getRiskScore()).thenReturn(worldpayRiskScoreModelMock); final double negativeFinalScore = configuredLimitValue - 10; when(worldpayRiskScoreModelMock.getFinalScore()).thenReturn(negativeFinalScore); final FraudServiceResponse fraudServiceResponse = new FraudServiceResponse(StringUtils.EMPTY); testObj.recognizeSymptom(fraudServiceResponse, orderModelMock); assertEquals(0D, fraudServiceResponse.getScore(), 0.0); assertEquals(Collections.emptyList(), fraudServiceResponse.getSymptoms()); verify(worldpayRiskScoreModelMock).getFinalScore(); }
@Test public void recognizeSymptomShouldReturnTheSameFraudServiceResponseWhenFinalScoreIsNull() { when(orderModelMock.getPaymentTransactions()).thenReturn(singletonList(worldpayPaymentAuthoriseTransactionModelMock)); when(worldpayPaymentAuthoriseTransactionModelMock.getRiskScore()).thenReturn(worldpayRiskScoreModelMock); when(worldpayRiskScoreModelMock.getFinalScore()).thenReturn(null); final FraudServiceResponse fraudServiceResponse = new FraudServiceResponse(StringUtils.EMPTY); testObj.recognizeSymptom(fraudServiceResponse, orderModelMock); assertEquals(0D, fraudServiceResponse.getScore(), 0.0); assertEquals(Collections.emptyList(), fraudServiceResponse.getSymptoms()); verify(worldpayRiskScoreModelMock).getFinalScore(); }
@Test public void recognizeSymptomWithNullRiskScore() { final FraudServiceResponse fraudServiceResponse = new FraudServiceResponse(StringUtils.EMPTY); when(orderModelMock.getPaymentTransactions()).thenReturn(singletonList(worldpayPaymentAuthoriseTransactionModelMock)); when(worldpayPaymentAuthoriseTransactionModelMock.getRiskScore()).thenReturn(null); testObj.recognizeSymptom(fraudServiceResponse, orderModelMock); assertEquals(0d, fraudServiceResponse.getScore(), 0.0); }