UserKey implements Serializable { @Override public String toString() { StringBuilder sb = new StringBuilder(); for (UserSelection selection: this.selection) { sb.append(selection.name()).append(":"); switch (selection) { case LOGIN: case EMAIL: sb.append(pi.getUsername()); break; case IP: sb.append(pi.getRemoteAddress()); break; default: break; } sb.append(";"); } return sb.toString(); } UserKey(ProcessingInformation pi, UserSelection[] selection); ProcessingInformation getPi(); @Override boolean equals(Object o); @Override String toString();  }
@Test() public void toStringTest() { ProcessingInformation pi = new ProcessingInformation("Request"); pi.setRemoteAddress("123.12.122.33"); pi.setUsername("user1"); ProcessingInformation pi1 = new ProcessingInformation("Request"); UserKey uk = new UserKey(pi, new UserSelection[] { UserSelection.LOGIN, UserSelection.IP }); UserKey uk1 = new UserKey(pi1, new UserSelection[] { UserSelection.LOGIN, UserSelection.IP }); Assert.assertEquals(uk.toString(), "LOGIN:user1;IP:123.12.122.33;"); Assert.assertEquals(uk1.toString(), "LOGIN:null;IP:null;"); }