DuplicateMatchedOrgStrengthRecalculator implements Serializable { public MatchedOrganization recalculateStrength(MatchedOrganization match1, MatchedOrganization match2) { Preconditions.checkNotNull(match1); Preconditions.checkNotNull(match2); Preconditions.checkArgument(match1.getDocumentId().equals(match2.getDocumentId())); Preconditions.checkArgument(match1.getOrganizationId().equals(match2.getOrganizationId())); float remainingMatchStrength = 1 - match1.getMatchStrength(); float newMatchStrength = match1.getMatchStrength() + (remainingMatchStrength * match2.getMatchStrength()); return new MatchedOrganization(match1.getDocumentId(), match1.getOrganizationId(), newMatchStrength); }  MatchedOrganization recalculateStrength(MatchedOrganization match1, MatchedOrganization match2);  }
@Test(expected = NullPointerException.class) public void recalculateStrength_NULL_FIRST_MATCHED_ORG() { strengthRecalculator.recalculateStrength(null, matchedOrganization2); }
@Test(expected = NullPointerException.class) public void recalculateStrength_NULL_SECOND_MATCHED_ORG() { strengthRecalculator.recalculateStrength(matchedOrganization1, null); }
@Test(expected = IllegalArgumentException.class) public void recalculateStrength_DIFFERENT_DOC_ID() { matchedOrganization2.setDocumentId("OTHER_DOC_ID"); strengthRecalculator.recalculateStrength(matchedOrganization1, matchedOrganization2); }
@Test(expected = IllegalArgumentException.class) public void recalculateStrength_DIFFERENT_ORG_ID() { matchedOrganization2.setOrganizationId("OTHER_ORG_ID"); strengthRecalculator.recalculateStrength(matchedOrganization1, matchedOrganization2); }
@Test public void recalculateStrength() { MatchedOrganization retMatchedOrganization = strengthRecalculator.recalculateStrength(matchedOrganization1, matchedOrganization2); assertEquals("DOC_ID", retMatchedOrganization.getDocumentId()); assertEquals("ORG_ID", retMatchedOrganization.getOrganizationId()); assertEquals(0.72f, retMatchedOrganization.getMatchStrength(), FLOAT_COMPARE_EPSILON); }