Debian Codegraph @

maven-scm-providers/maven-scm-provider-accurev/src/test/java/org/apache/maven/scm/ChangeFileMatcher.java

raw symbols SCIP
1 package org.apache.maven.scm;
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.any;
23 import static org.hamcrest.Matchers.is;
24
25 import java.io.File;
26
27 import org.hamcrest.Description;
28 import org.hamcrest.Matcher;
29 import org.hamcrest.TypeSafeMatcher;
30
31 public class ChangeFileMatcher
32 extends TypeSafeMatcher<ChangeFile>
33 {
34
35 private String fileName;
36
37 private Matcher<String> versionMatcher;
38
39 public ChangeFileMatcher( String fileName, Matcher<String> versionMatcher )
40 {
41 this.fileName = new File( fileName ).getPath();
42 this.versionMatcher = versionMatcher;
43 }
44
45 @Override
46 public boolean matchesSafely( ChangeFile changeFile )
47 {
48 return is( fileName ).matches( new File( changeFile.getName() ).getPath() );
49 }
50
51 public void describeTo( Description desc )
52 {
53 desc.appendText( "ChangeFile with name=" );
54 desc.appendValue( fileName );
55 desc.appendText( " and version matching " );
56 desc.appendDescriptionOf( versionMatcher );
57
58 }
59
60 public static Matcher<ChangeFile> changeFile( String fileName )
61 {
62 return new ChangeFileMatcher( fileName, any( String.class ) );
63 }
64
65 public static Matcher<ChangeFile> changeFile( String fileName, Matcher<String> versionMatcher )
66 {
67 return new ChangeFileMatcher( fileName, versionMatcher );
68 }
69 }