Debian Codegraph @

maven-scm-providers/maven-scm-provider-accurev/src/test/java/org/apache/maven/scm/ChangeSetMatcher.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.apache.maven.scm.ChangeFileMatcher.changeFile;
23 import static org.apache.maven.scm.CollectionSizeMatcher.size;
24 import static org.hamcrest.Matchers.allOf;
25 import static org.hamcrest.Matchers.any;
26 import static org.hamcrest.Matchers.is;
27
28 import java.util.List;
29
30 import org.hamcrest.Description;
31 import org.hamcrest.Matcher;
32 import org.hamcrest.Matchers;
33 import org.hamcrest.TypeSafeMatcher;
34
35 public class ChangeSetMatcher
36 extends TypeSafeMatcher<ChangeSet>
37 {
38
39 private String comment;
40
41 private Matcher<Iterable<ChangeFile>> changeFilesMatcher;
42
43 @SuppressWarnings( "unchecked" )
44 public ChangeSetMatcher( String comment, String... fileNames )
45 {
46 this.comment = comment;
47
48 Matcher<ChangeFile> elementMatchers[] = new ChangeFileMatcher[fileNames.length];
49 for ( int i = 0; i < elementMatchers.length; i++ )
50 {
51 elementMatchers[i] = changeFile( fileNames[i], any( String.class ) );
52 }
53 this.changeFilesMatcher =
54 allOf( Matchers.<ChangeFile>hasItems( elementMatchers ), size( fileNames.length, ChangeFile.class ) );
55 }
56
57 @Override
58 public boolean matchesSafely( ChangeSet changeSet )
59 {
60 List<ChangeFile> files = changeSet.getFiles();
61 return is( comment ).matches( changeSet.getComment() ) && changeFilesMatcher.matches( files );
62 }
63
64 public void describeTo( Description desc )
65 {
66 desc.appendText( "ChangeSet with comment=" );
67 desc.appendValue( comment );
68 desc.appendText( " and files matching " );
69 desc.appendDescriptionOf( changeFilesMatcher );
70 }
71
72 public static Matcher<ChangeSet> changeSet( String comment, String... fileNames )
73 {
74 return new ChangeSetMatcher( comment, fileNames );
75 }
76 }