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