BranchDelegator extends BaseDelegator implements IBranchDelegator { @Override public String deleteBranchSpec(final String branchSpecName, final boolean force) throws ConnectionException, RequestException, AccessException { try { return deleteBranchSpec(branchSpecName, new DeleteBranchSpecOptions(force)); } catch (final ConnectionException | AccessException | RequestException exc) { throw exc; } catch (P4JavaException exc) { throw new RequestException(exc.getMessage(), exc); } } 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);  }
@SuppressWarnings("unchecked") @Test public void testForceDeleteBranchSpec() throws P4JavaException { when(server.execMapCmdList(eq(BRANCH.toString()), argThat(new CommandLineArgumentMatcher(new String[] { "-f", "-d", mockBranchSpecName })), (Map<String,Object>)any())).thenReturn(resultMaps); when(resultMap.get(CODE0)).thenReturn("268435456"); when(resultMap.get(FMT0)).thenReturn("%branch%"); when(resultMap.get("branch")).thenReturn(mockBranchSpecName); @SuppressWarnings("deprecation") String deleteBranchSpec = branchSpecDelegator.deleteBranchSpec(mockBranchSpecName, true); assertEquals(mockBranchSpecName, deleteBranchSpec); }
@Test(expected=IllegalArgumentException.class) public void deleteBranchSpec_byBranchNameAndDeleteBranchSpecOptions_shouldThrownIllegalArgumentExceptionWhenBranchNameIsBlank() throws P4JavaException { branchSpecDelegator.deleteBranchSpec(EMPTY, mock(DeleteBranchSpecOptions.class)); }
@SuppressWarnings("unchecked") @Test public void testDeleteBranchSpecWithEmptyOptions() throws P4JavaException { when(server.execMapCmdList(eq(BRANCH.toString()), argThat(new CommandLineArgumentMatcher(new String[] { "-d", mockBranchSpecName })), (Map<String,Object>)any())).thenReturn(resultMaps); when(resultMap.get(CODE0)).thenReturn("268435456"); when(resultMap.get(FMT0)).thenReturn("%branch%"); when(resultMap.get("branch")).thenReturn(mockBranchSpecName); String deleteBranchSpec = branchSpecDelegator.deleteBranchSpec(mockBranchSpecName, mock(DeleteBranchSpecOptions.class)); Assert.assertEquals(mockBranchSpecName, deleteBranchSpec); verify(server).execMapCmdList(BRANCH.toString(), new String[] { "-d", mockBranchSpecName }, null); }
@Test public void testForceDeleteBranchSpec() throws P4JavaException { when(server.execMapCmdList(eq(BRANCH.toString()), argThat(new CommandLineArgumentMatcher(new String[] { "-f", "-d", mockBranchSpecName })), any(Map.class))).thenReturn(resultMaps); when(resultMap.get(CODE0)).thenReturn("268435456"); when(resultMap.get(FMT0)).thenReturn("%branch%"); when(resultMap.get("branch")).thenReturn(mockBranchSpecName); String deleteBranchSpec = branchSpecDelegator.deleteBranchSpec(mockBranchSpecName, true); assertThat(deleteBranchSpec, is(mockBranchSpecName)); }
@Test public void deleteBranchSpec_byBranchNameAndDeleteBranchSpecOptions_shouldThrownIllegalArgumentExceptionWhenBranchNameIsBlank() throws P4JavaException { expectThrows(IllegalArgumentException.class, () -> branchSpecDelegator .deleteBranchSpec(EMPTY, mock(DeleteBranchSpecOptions.class))); }
@Test public void testDeleteBranchSpecWithEmptyOptions() throws P4JavaException { when(server.execMapCmdList(eq(BRANCH.toString()), argThat(new CommandLineArgumentMatcher(new String[] { "-d", mockBranchSpecName })), any(Map.class))).thenReturn(resultMaps); when(resultMap.get(CODE0)).thenReturn("268435456"); when(resultMap.get(FMT0)).thenReturn("%branch%"); when(resultMap.get("branch")).thenReturn(mockBranchSpecName); String deleteBranchSpec = branchSpecDelegator.deleteBranchSpec(mockBranchSpecName, mock(DeleteBranchSpecOptions.class)); assertThat(deleteBranchSpec, is(mockBranchSpecName)); verify(server).execMapCmdList(BRANCH.toString(), new String[] { "-d", mockBranchSpecName }, null); }