001package org.apache.maven.scm; 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.apache.maven.scm.ChangeFileMatcher.changeFile; 023import static org.apache.maven.scm.CollectionSizeMatcher.size; 024import static org.hamcrest.Matchers.allOf; 025import static org.hamcrest.Matchers.any; 026import static org.hamcrest.Matchers.is; 027 028import java.util.List; 029 030import org.hamcrest.Description; 031import org.hamcrest.Matcher; 032import org.hamcrest.Matchers; 033import org.hamcrest.TypeSafeMatcher; 034 035public class ChangeSetMatcher 036 extends TypeSafeMatcher<ChangeSet> 037{ 038 039 private String comment; 040 041 private Matcher<Iterable<ChangeFile>> changeFilesMatcher; 042 043 @SuppressWarnings( "unchecked" ) 044 public ChangeSetMatcher( String comment, String... fileNames ) 045 { 046 this.comment = comment; 047 048 Matcher<ChangeFile> elementMatchers[] = new ChangeFileMatcher[fileNames.length]; 049 for ( int i = 0; i < elementMatchers.length; i++ ) 050 { 051 elementMatchers[i] = changeFile( fileNames[i], any( String.class ) ); 052 } 053 this.changeFilesMatcher = 054 allOf( Matchers.<ChangeFile>hasItems( elementMatchers ), size( fileNames.length, ChangeFile.class ) ); 055 } 056 057 @Override 058 public boolean matchesSafely( ChangeSet changeSet ) 059 { 060 List<ChangeFile> files = changeSet.getFiles(); 061 return is( comment ).matches( changeSet.getComment() ) && changeFilesMatcher.matches( files ); 062 } 063 064 public void describeTo( Description desc ) 065 { 066 desc.appendText( "ChangeSet with comment=" ); 067 desc.appendValue( comment ); 068 desc.appendText( " and files matching " ); 069 desc.appendDescriptionOf( changeFilesMatcher ); 070 } 071 072 public static Matcher<ChangeSet> changeSet( String comment, String... fileNames ) 073 { 074 return new ChangeSetMatcher( comment, fileNames ); 075 } 076}