GroupDelegator extends BaseDelegator implements IGroupDelegator { @Override public IUserGroup getUserGroup(@Nonnull final String name) throws ConnectionException, RequestException, AccessException { Validate.notBlank(name, "Group name shouldn't use null or empty"); List<Map<String, Object>> resultMaps = execMapCmdList(GROUP, new String[] { "-o", name }, null); UserGroup ugImpl = null; if (nonNull(resultMaps)) { Map<String, Object> firstResultMap = resultMaps.get(0); if (nonNull(firstResultMap)) { ResultMapParser.handleErrorStr(firstResultMap); ugImpl = new UserGroup(firstResultMap); } } return ugImpl; } GroupDelegator(IOptionsServer server); @Override IUserGroup getUserGroup(@Nonnull final String name); @Override String deleteUserGroup(@Nonnull IUserGroup group, @Nullable UpdateUserGroupOptions opts); @Override String createUserGroup(@Nonnull final IUserGroup group,
            @Nullable final UpdateUserGroupOptions opts); @Override String updateUserGroup(@Nonnull final IUserGroup group,
            @Nullable final UpdateUserGroupOptions opts); String createUserGroup(@Nonnull final IUserGroup group); String updateUserGroup(@Nonnull final IUserGroup group, final boolean updateIfOwner); String deleteUserGroup(@Nonnull final IUserGroup group);  }
@Test public void testNullServerResponse() throws P4JavaException { when(server.execMapCmdList(eq(CmdSpec.GROUP.toString()), argThat(new CommandLineArgumentMatcher(new String[] { "-o", groupName })), eq((Map<String, Object>) null))).thenReturn(null); IUserGroup userGroup = groupDelegator.getUserGroup(groupName); assertNull(userGroup); }
@Test public void testGetUserGroup() throws P4JavaException { when(server.execMapCmdList(eq(CmdSpec.GROUP.toString()), argThat(new CommandLineArgumentMatcher(new String[] { "-o", groupName })), eq((Map<String, Object>) null))).thenReturn(resultMaps); when(resultMap.get(MapKeys.GROUP_KEY)).thenReturn(groupName); IUserGroup userGroup = groupDelegator.getUserGroup(groupName); assertNotNull(userGroup); assertEquals(groupName, userGroup.getName()); }
@Test public void testNullServerResponse() throws P4JavaException { when(server.execMapCmdList(eq(CmdSpec.GROUP.toString()), argThat(new CommandLineArgumentMatcher(new String[] { "-o", groupName })), eq(null))).thenReturn(null); IUserGroup userGroup = groupDelegator.getUserGroup(groupName); assertNull(userGroup); }
@Test public void testGetUserGroup() throws P4JavaException { when(server.execMapCmdList(eq(CmdSpec.GROUP.toString()), argThat(new CommandLineArgumentMatcher(new String[] { "-o", groupName })), eq(null))).thenReturn(resultMaps); when(resultMap.get(MapKeys.GROUP_KEY)).thenReturn(groupName); IUserGroup userGroup = groupDelegator.getUserGroup(groupName); assertNotNull(userGroup); assertEquals(groupName, userGroup.getName()); }