/** * Attempt to add nothing. * * @throws Exception */ @Test public void testAddNothing() throws Exception { when(client.addFiles(fileSpecsToAdd, Boolean.FALSE, -1, null, Boolean.FALSE)) .thenReturn(fileSpecsAdded); AddScmResult addResult = (AddScmResult) addCommand.execute(repository, scmFileSet, parameters); Assert.assertTrue("The result was not a success.", addResult.isSuccess()); }
/** * Attempts to add one file, but the operation fails and no exception is thrown by P4Java. The * result of the command should be a failure. * * @throws Exception */ @Test public void testAddFail() throws Exception { File fileToAdd = new File("src/test/resources/testAdd/fileToAdd.txt"); files.add(fileToAdd); when(client.addFiles(fileSpecsToAdd, Boolean.FALSE, -1, null, Boolean.FALSE)) .thenReturn(fileSpecsAdded); AddScmResult addResult = (AddScmResult) addCommand.execute(repository, scmFileSet, parameters); Assert.assertTrue( "Should not be a success, attempt to add should have failed.", !addResult.isSuccess()); }
/** * Attempts to add a file but the P4Java API throws an exception. Verify the exception is * propagated. * * @throws Exception */ @Test(expected = ScmException.class) public void testAddException() throws Exception { File fileToAdd = new File("src/test/resources/testAdd/fileToAdd.txt"); files.add(fileToAdd); ScmFile scmFile = new ScmFile(fileToAdd.getAbsolutePath(), ScmFileStatus.ADDED); scmFilesAdded.add(scmFile); when(client.addFiles(fileSpecsToAdd, Boolean.FALSE, -1, null, Boolean.FALSE)) .thenThrow(new AccessException("User does not have permission to add file.")); addCommand.execute(repository, scmFileSet, parameters); }
/** * Attempt to add one file, expect that one file is returned as added. * * @throws Exception */ @Test public void testAddOne() throws Exception { File fileToAdd = new File("src/test/resources/testAdd/fileToAdd.txt"); files.add(fileToAdd); IFileSpec fileSpec = mock(IFileSpec.class); when(fileSpec.getDepotPathString()).thenReturn("//depot/path/string/fileToAdd.txt"); when(fileSpec.getAction()).thenReturn(FileAction.ADD); fileSpecsToAdd.add(fileSpec); fileSpecsAdded.add(fileSpec); ScmFile scmFile = new ScmFile(fileToAdd.getAbsolutePath(), ScmFileStatus.ADDED); scmFilesAdded.add(scmFile); when(client.addFiles(fileSpecsToAdd, Boolean.FALSE, -1, null, Boolean.FALSE)) .thenReturn(fileSpecsAdded); AddScmResult addResult = (AddScmResult) addCommand.execute(repository, scmFileSet, parameters); Assert.assertTrue("The result was not a success.", addResult.isSuccess()); }