View Javadoc
1   package org.apache.maven.scm.provider.accurev.cli;
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.hamcrest.Matchers.is;
23  import static org.hamcrest.Matchers.isOneOf;
24  import static org.junit.Assert.assertThat;
25  
26  import java.util.regex.Matcher;
27  import java.util.regex.Pattern;
28  
29  import org.apache.maven.scm.provider.accurev.AccuRevStat;
30  import org.junit.Test;
31  
32  public class AccuRevStatTest
33  {
34  
35      private static final String[] STAT_RESULTS;
36  
37      static
38      {
39          String defunct = "./defunct.xml            maventst_ggardner/3 (2/3) (defunct) (kept) (member)";
40          String modified = "./src/main/java/Modified.java  maventst_ggardner/2 (2/2) (modified) (member)";
41          String kept = "./src/main/java/Kept.java  maventst_ggardner/3 (2/3) (kept) (member)";
42          String external = "./src/test/java/External.java  (external)";
43          String missing = "./Missing.jpg            maventst/1 (2/1) (missing)";
44  
45          STAT_RESULTS = new String[] { defunct, modified, kept, external, missing };
46      }
47  
48      @Test
49      public void testDEFUNCT()
50          throws Exception
51      {
52          assertStatType( AccuRevStat.DEFUNCT, "-D", "./defunct.xml" );
53      }
54  
55      @Test
56      public void testEXTERNAL()
57          throws Exception
58      {
59          assertStatType( AccuRevStat.EXTERNAL, "-x", "./src/test/java/External.java" );
60      }
61  
62      @Test
63      public void testKEPT()
64          throws Exception
65      {
66          assertStatType( AccuRevStat.KEPT, "-k", "./src/main/java/Kept.java", "./defunct.xml" );
67      }
68  
69      @Test
70      public void testMISSING()
71          throws Exception
72      {
73          assertStatType( AccuRevStat.MISSING, "-M", "./Missing.jpg" );
74      }
75  
76      @Test
77      public void testMODIFIED()
78          throws Exception
79      {
80          assertStatType( AccuRevStat.MODIFIED, "-m", "./src/main/java/Modified.java" );
81      }
82  
83      private void assertStatType( AccuRevStat accuRevStat, String expectedStatArg, String... expectedMatches )
84      {
85          assertThat( accuRevStat.getStatArg(), is( expectedStatArg ) );
86          Pattern matchPattern = accuRevStat.getMatchPattern();
87  
88          int matchCount = 0;
89  
90          for ( String stat : STAT_RESULTS )
91          {
92  
93              Matcher matcher = matchPattern.matcher( stat );
94  
95              if ( matcher.matches() )
96              {
97                  String matched = matcher.group( 1 );
98                  assertThat( matched, isOneOf( expectedMatches ) );
99                  matchCount++;
100             }
101         }
102         assertThat( matchCount, is( expectedMatches.length ) );
103     }
104 }