View Javadoc
1   package org.apache.maven.scm.provider.accurev.command.remove;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *    http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import static org.apache.maven.scm.ScmFileMatcher.assertHasScmFile;
23  import static org.hamcrest.Matchers.is;
24  import static org.hamcrest.Matchers.notNullValue;
25  import static org.junit.Assert.assertThat;
26  import static org.mockito.Mockito.when;
27  
28  import java.io.File;
29  import java.util.Collections;
30  import java.util.List;
31  
32  import org.apache.maven.scm.CommandParameter;
33  import org.apache.maven.scm.CommandParameters;
34  import org.apache.maven.scm.ScmFileSet;
35  import org.apache.maven.scm.ScmFileStatus;
36  import org.apache.maven.scm.command.remove.RemoveScmResult;
37  import org.apache.maven.scm.provider.accurev.command.AbstractAccuRevCommandTest;
38  import org.junit.Test;
39  
40  public class AccuRevRemoveCommandTest
41      extends AbstractAccuRevCommandTest
42  {
43  
44      @Test
45      public void testRemove()
46          throws Exception
47      {
48          final ScmFileSet testFileSet = new ScmFileSet( basedir, new File( "src/main/java/Foo.java" ) );
49  
50          List<File> removedFiles = Collections.singletonList( new File( "removed/file" ) );
51  
52          when( accurev.defunct( basedir, testFileSet.getFileList(), "A deleted file" ) ).thenReturn( removedFiles );
53  
54          AccuRevRemoveCommand command = new AccuRevRemoveCommand( getLogger() );
55  
56          CommandParameters commandParameters = new CommandParameters();
57          commandParameters.setString( CommandParameter.MESSAGE, "A deleted file" );
58          RemoveScmResult result = command.remove( repo, testFileSet, commandParameters );
59  
60          assertThat( result.isSuccess(), is( true ) );
61          assertThat( result.getRemovedFiles().size(), is( 1 ) );
62          assertHasScmFile( result.getRemovedFiles(), "removed/file", ScmFileStatus.DELETED );
63      }
64  
65      @Test
66      public void testAddFailed()
67          throws Exception
68      {
69          final ScmFileSet testFileSet = new ScmFileSet( basedir, new File( "src/main/java/Foo.java" ) );
70  
71          when( accurev.defunct( basedir, testFileSet.getFileList(), "A deleted file" ) ).thenReturn( null );
72  
73          AccuRevRemoveCommand command = new AccuRevRemoveCommand( getLogger() );
74  
75          CommandParameters commandParameters = new CommandParameters();
76          commandParameters.setString( CommandParameter.MESSAGE, "A deleted file" );
77          RemoveScmResult result = command.remove( repo, testFileSet, commandParameters );
78  
79          assertThat( result.isSuccess(), is( false ) );
80          assertThat( result.getProviderMessage(), notNullValue() );
81      }
82  
83  }