001package org.apache.maven.scm.provider.accurev.cli; 002 003/* 004 * Licensed to the Apache Software Foundation (ASF) under one 005 * or more contributor license agreements. See the NOTICE file 006 * distributed with this work for additional information 007 * regarding copyright ownership. The ASF licenses this file 008 * to you under the Apache License, Version 2.0 (the 009 * "License"); you may not use this file except in compliance 010 * with the License. You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, 015 * software distributed under the License is distributed on an 016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 017 * KIND, either express or implied. See the License for the 018 * specific language governing permissions and limitations 019 * under the License. 020 */ 021 022import static org.hamcrest.Matchers.is; 023import static org.hamcrest.Matchers.isOneOf; 024import static org.junit.Assert.assertThat; 025 026import java.util.regex.Matcher; 027import java.util.regex.Pattern; 028 029import org.apache.maven.scm.provider.accurev.AccuRevStat; 030import org.junit.Test; 031 032public class AccuRevStatTest 033{ 034 035 private static final String[] STAT_RESULTS; 036 037 static 038 { 039 String defunct = "./defunct.xml maventst_ggardner/3 (2/3) (defunct) (kept) (member)"; 040 String modified = "./src/main/java/Modified.java maventst_ggardner/2 (2/2) (modified) (member)"; 041 String kept = "./src/main/java/Kept.java maventst_ggardner/3 (2/3) (kept) (member)"; 042 String external = "./src/test/java/External.java (external)"; 043 String missing = "./Missing.jpg maventst/1 (2/1) (missing)"; 044 045 STAT_RESULTS = new String[] { defunct, modified, kept, external, missing }; 046 } 047 048 @Test 049 public void testDEFUNCT() 050 throws Exception 051 { 052 assertStatType( AccuRevStat.DEFUNCT, "-D", "./defunct.xml" ); 053 } 054 055 @Test 056 public void testEXTERNAL() 057 throws Exception 058 { 059 assertStatType( AccuRevStat.EXTERNAL, "-x", "./src/test/java/External.java" ); 060 } 061 062 @Test 063 public void testKEPT() 064 throws Exception 065 { 066 assertStatType( AccuRevStat.KEPT, "-k", "./src/main/java/Kept.java", "./defunct.xml" ); 067 } 068 069 @Test 070 public void testMISSING() 071 throws Exception 072 { 073 assertStatType( AccuRevStat.MISSING, "-M", "./Missing.jpg" ); 074 } 075 076 @Test 077 public void testMODIFIED() 078 throws Exception 079 { 080 assertStatType( AccuRevStat.MODIFIED, "-m", "./src/main/java/Modified.java" ); 081 } 082 083 private void assertStatType( AccuRevStat accuRevStat, String expectedStatArg, String... expectedMatches ) 084 { 085 assertThat( accuRevStat.getStatArg(), is( expectedStatArg ) ); 086 Pattern matchPattern = accuRevStat.getMatchPattern(); 087 088 int matchCount = 0; 089 090 for ( String stat : STAT_RESULTS ) 091 { 092 093 Matcher matcher = matchPattern.matcher( stat ); 094 095 if ( matcher.matches() ) 096 { 097 String matched = matcher.group( 1 ); 098 assertThat( matched, isOneOf( expectedMatches ) ); 099 matchCount++; 100 } 101 } 102 assertThat( matchCount, is( expectedMatches.length ) ); 103 } 104}