BranchDelegator extends BaseDelegator implements IBranchDelegator { @Override public IBranchSpec getBranchSpec(final String name) throws ConnectionException, RequestException, AccessException { return asRequestException(() -> getBranchSpec(name, new GetBranchSpecOptions()) ); } BranchDelegator(IOptionsServer server); @Override String createBranchSpec(@Nonnull final IBranchSpec branchSpec); @Override IBranchSpec getBranchSpec(final String name); @Override IBranchSpec getBranchSpec(final String name, final GetBranchSpecOptions opts); @Override String updateBranchSpec(@Nonnull final IBranchSpec branchSpec); @Override String deleteBranchSpec(final String branchSpecName, final boolean force); @Override String deleteBranchSpec(final String branchSpecName, final DeleteBranchSpecOptions opts);  }
@Test public void tetsGetBranchSpecByName() throws P4JavaException { when(server.execMapCmdList(eq(BRANCH.toString()), argThat(new CommandLineArgumentMatcher(new String[] { "-o", mockBranchSpecName })), eq(null))).thenReturn(resultMaps); when(resultMap.get("Branch")).thenReturn(mockBranchSpecName); IBranchSpec branchSpec = branchSpecDelegator.getBranchSpec(mockBranchSpecName); assertNotNull(branchSpec, "Get branch spec with -i name, returned null when the server returned a spec"); assertEquals(mockBranchSpecName, branchSpec.getName()); }
@Test(expected=NullPointerException.class) public void testGetNullBranchName() throws P4JavaException { branchSpecDelegator.getBranchSpec(null, mock(GetBranchSpecOptions.class)); }
@Test public void testEmptyResultMap() throws P4JavaException { when(server.execMapCmdList(eq(BRANCH.toString()), argThat(new CommandLineArgumentMatcher(new String[] { "-o", mockBranchSpecName })), eq(null))).thenReturn(new ArrayList<Map<String, Object>>()); IBranchSpec branchSpec = branchSpecDelegator.getBranchSpec(mockBranchSpecName, mock(GetBranchSpecOptions.class)); assertNull(branchSpec); }
@Test public void testNormalResultMap() throws P4JavaException { when(server.execMapCmdList(eq(BRANCH.toString()), argThat(new CommandLineArgumentMatcher(new String[] { "-o", mockBranchSpecName })), eq(null))).thenReturn(resultMaps); IBranchSpec branchSpec = branchSpecDelegator.getBranchSpec(mockBranchSpecName, mock(GetBranchSpecOptions.class)); assertNotNull(branchSpec); }