### Question:
KeyToGroupMap implements Cloneable, PublicCloneable, Serializable { public void mapKeyToGroup(Comparable key, Comparable group) { if (key == null) { throw new IllegalArgumentException("Null 'key' argument."); } Comparable currentGroup = getGroup(key); if (!currentGroup.equals(this.defaultGroup)) { if (!currentGroup.equals(group)) { int count = getKeyCount(currentGroup); if (count == 1) { this.groups.remove(currentGroup); } } } if (group == null) { this.keyToGroupMap.remove(key); } else { if (!this.groups.contains(group)) { if (!this.defaultGroup.equals(group)) { this.groups.add(group); } } this.keyToGroupMap.put(key, group); } } KeyToGroupMap();  KeyToGroupMap(Comparable defaultGroup); int getGroupCount(); List<Comparable> getGroups(); int getGroupIndex(Comparable group); Comparable getGroup(Comparable key); void mapKeyToGroup(Comparable key, Comparable group); int getKeyCount(Comparable group); @Override boolean equals(Object obj); @Override Object clone();  }### Answer:
@Test public void testMapKeyToGroup() { KeyToGroupMap m1 = new KeyToGroupMap("G1"); m1.mapKeyToGroup("K1", "G1"); assertEquals("G1", m1.getGroup("K1")); m1.mapKeyToGroup("K2", "G2"); assertEquals("G2", m1.getGroup("K2")); m1.mapKeyToGroup("K2", null); assertEquals("G1", m1.getGroup("K2")); try { m1.mapKeyToGroup(null, "G1"); fail("Should have thrown IllegalArgumentException on null key"); } catch (IllegalArgumentException e) { assertEquals("Null 'key' argument.", e.getMessage()); } }