View Javadoc
1   package org.apache.maven.scm.provider.accurev.cli;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file
5    * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the
6    * Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a
7    * copy of the License at
8    *
9    * http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS"
12   * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language
13   * governing permissions and limitations under the License.
14   */
15  
16  import static org.hamcrest.Matchers.hasItem;
17  import static org.hamcrest.Matchers.is;
18  import static org.junit.Assert.assertThat;
19  
20  import java.io.File;
21  import java.io.IOException;
22  import java.util.ArrayList;
23  import java.util.List;
24  
25  import org.codehaus.plexus.util.cli.StreamConsumer;
26  import org.junit.Test;
27  
28  public class FileConsumerTest
29  {
30  
31      @Test
32      public void testConsumeAdd() throws IOException
33      {
34          List<File> extractedFiles = new ArrayList<File>();
35  
36          StreamConsumer consumer = new FileConsumer( extractedFiles, FileConsumer.ADD_PATTERN );
37  
38          consumer.consumeLine( "Added and kept element /./src/main/java/Application.java" );
39          consumer.consumeLine( "Added and kept element \\.\\src\\main\\java\\Windows.java" );
40  
41          assertThat( extractedFiles.size(), is( 2 ) );
42          assertThat( extractedFiles, hasItem( new File( "src/main/java/Application.java" ) ) );
43          assertThat( extractedFiles, hasItem( new File( "src\\main\\java\\Windows.java" ) ) );
44      }
45  
46      @Test
47      public void testConsumeUpdate() throws IOException
48      {
49          List<File> extractedFiles = new ArrayList<File>();
50          StreamConsumer consumer = new FileConsumer( extractedFiles, FileConsumer.UPDATE_PATTERN );
51  
52          consumer.consumeLine( "Content (1 K) of \"readme.txt\" - ok" );
53          consumer.consumeLine( "Creating dir \"src/main/java/org\" ." );
54          consumer.consumeLine( "Updating (creating) dir /./src/test/java" );
55          consumer.consumeLine( "Updating element \\.\\src\\main\\java\\Application.java" );
56  
57          assertThat( extractedFiles.size(), is( 2 ) );
58          assertThat( extractedFiles, hasItem( new File( "readme.txt" ) ) );
59          assertThat( extractedFiles, hasItem( new File( "src\\main\\java\\Application.java" ) ) );
60      }
61  
62      @Test
63      public void testConsumePromoted() throws IOException
64      {
65          List<File> extractedFiles = new ArrayList<File>();
66  
67          StreamConsumer consumer = new FileConsumer( extractedFiles, FileConsumer.PROMOTE_PATTERN );
68  
69          consumer.consumeLine( "Promoted element /./src/main/java/Application.java" );
70          consumer.consumeLine( "Promoted element \\.\\src\\main\\java\\Windows.java" );
71  
72          assertThat( extractedFiles.size(), is( 2 ) );
73          assertThat( extractedFiles, hasItem( new File( "src/main/java/Application.java" ) ) );
74          assertThat( extractedFiles, hasItem( new File( "src\\main\\java\\Windows.java" ) ) );
75      }
76  
77      @Test
78      public void testConsumeRemoved() throws IOException
79      {
80          List<File> extractedFiles = new ArrayList<File>();
81          StreamConsumer consumer = new FileConsumer( extractedFiles, FileConsumer.DEFUNCT_PATTERN );
82  
83          consumer.consumeLine( "Recursively removing \"tcktests/src\" ." );
84          consumer.consumeLine( "Removing \"tcktests/src/main/java/Application.java\" ." );
85          consumer.consumeLine( "Removing \"tcktests/src/main/java\" ." );
86          consumer.consumeLine( "Removing \"tcktests/src/main\" ." );
87          consumer.consumeLine( "Removing \"tcktests/src\" ." );
88  
89          assertThat( extractedFiles.size(), is( 4 ) );
90          assertThat( extractedFiles, hasItem( new File( "tcktests/src" ) ) );
91          assertThat( extractedFiles, hasItem( new File( "tcktests/src/main/java/Application.java" ) ) );
92      }
93  }