CitizenId implements Identity { protected int calculateCheckDigit() { int sum = 0; for (int position = 0; position < CitizenId.LENGTH - 1; position++) { sum += Character.digit(id.charAt(position), 10) * MULTIPLIER_TABLE[position]; } int x = sum % 11; return (11 - x) % 10; } CitizenId(String id); static boolean isValid(String id); @Override boolean validate(); @Override boolean isValidFormat(); @Override int hashCode(); @Override boolean equals(Object o); @Override String toString(); @Override String prettyPrint(); @Override String getId();  }
@Test public void calculateCheckDigit() { CitizenId cid; cid = new CitizenId("161025581111"); assertEquals("calculate check digit result should be 2", 2, cid.calculateCheckDigit()); cid = new CitizenId("161025580000"); assertEquals("calculate check digit result should be 5", 5, cid.calculateCheckDigit()); }