### Question:
SubjectUtil { public static List<String> getGroupnamesFromSubject(Subject subject) { List<String> groupList = new ArrayList<String>(); Set<Group> princSet = null; if (subject != null) { princSet = subject.getPrincipals(Group.class); for (PrincipalImpl g : princSet) { String gName = g.getName(); groupList.add(gName); } } return groupList; }  static List<String> getUsernamesFromSubject(Subject subject); static List<String> getGroupnamesFromSubject(Subject subject);  }### Answer:
@Test public void testGroupNameUtil() { Subject sub = createSub(USERNAME, GROUPS); List<String> groupnames = SubjectUtil.getGroupnamesFromSubject(sub); if (debug) System.out.println("group list =" + groupnames); Assert.assertEquals(2, groupnames.size()); }
@Test public void testGroupNameUtil_empty() { Subject sub = createSub(USERNAME, null); List<String> groupnames = SubjectUtil.getGroupnamesFromSubject(sub); Assert.assertEquals(0, groupnames.size()); }