CitizenId implements Identity { protected int getCheckDigit() { int lastIndex = CitizenId.LENGTH - 1; return Character.digit(id.charAt(lastIndex), 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 getCheckDigit() { CitizenId cid; cid = new CitizenId("0000000000003"); assertEquals("check digit should be 3", 3, cid.getCheckDigit()); cid = new CitizenId("0000000000005"); assertEquals("check digit should be 5", 5, cid.getCheckDigit()); cid = new CitizenId("000000000000x"); assertEquals("check digit should be -1", -1, cid.getCheckDigit()); }