1 package org.apache.maven.scm.provider.accurev.cli;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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 }