View Javadoc
1   package org.apache.maven.scm.provider.git.gitexe.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 org.apache.maven.scm.ScmFile;
23  import org.apache.maven.scm.ScmFileStatus;
24  import org.apache.maven.scm.log.DefaultLog;
25  import org.apache.maven.scm.provider.git.gitexe.command.remove.GitRemoveConsumer;
26  import org.codehaus.plexus.PlexusTestCase;
27  
28  import java.io.BufferedReader;
29  import java.io.File;
30  import java.io.FileReader;
31  import java.util.List;
32  
33  /**
34   * @author <a href="mailto:struberg@yahoo.de">Mark Struberg</a>
35   */
36  public class GitRemoveConsumerTest
37      extends PlexusTestCase
38  {
39      
40      public void testConsumerRemovedFile() 
41      {
42          GitRemoveConsumer consumer = new GitRemoveConsumer( new DefaultLog() );
43          
44          consumer.consumeLine( "rm 'project.xml'" );
45          
46          List<ScmFile> changedFiles = consumer.getRemovedFiles();
47          
48          assertNotNull( changedFiles );
49          assertEquals( 1, changedFiles.size() );
50      }
51      
52      public void testLog1Consumer()
53      throws Exception
54      {
55          GitRemoveConsumer consumer = new GitRemoveConsumer( new DefaultLog() );
56  
57          File f = getTestFile( "/src/test/resources/git/remove/gitrm.gitlog" );
58  
59          BufferedReader r = new BufferedReader( new FileReader( f ) );
60  
61          String line;
62  
63          while ( ( line = r.readLine() ) != null )
64          {
65              consumer.consumeLine( line );
66          }
67  
68          List<ScmFile> changedFiles = consumer.getRemovedFiles();
69          
70          assertEquals( 2, changedFiles.size() );
71  
72          testScmFile( (ScmFile) changedFiles.get( 0 ), "src/main/java/Application.java", ScmFileStatus.DELETED );
73          testScmFile( (ScmFile) changedFiles.get( 1 ), "src/test/java/Test.java" , ScmFileStatus.DELETED );
74      }
75   
76      public void testEmptyLogConsumer()
77      throws Exception
78      {
79          GitRemoveConsumer consumer = new GitRemoveConsumer( new DefaultLog() );
80  
81          File f = getTestFile( "/src/test/resources/git/remove/gitrm-empty.gitlog" );
82  
83          BufferedReader r = new BufferedReader( new FileReader( f ) );
84  
85          String line;
86  
87          while ( ( line = r.readLine() ) != null )
88          {
89              consumer.consumeLine( line );
90          }
91  
92          List<ScmFile> changedFiles = consumer.getRemovedFiles();
93          
94          assertEquals( 0, changedFiles.size() );
95     }    
96      
97      private void testScmFile( ScmFile fileToTest, String expectedFilePath, ScmFileStatus expectedStatus )
98      {
99          assertEquals( expectedFilePath, fileToTest.getPath() );
100         assertEquals( expectedStatus, fileToTest.getStatus() );
101     }
102  
103 }