001package org.apache.maven.scm; 002 003/* 004 * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file 005 * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the 006 * Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a 007 * copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" 012 * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language 013 * governing permissions and limitations under the License. 014 */ 015 016import java.io.File; 017import java.util.List; 018 019import org.hamcrest.Description; 020import org.hamcrest.Matcher; 021import org.hamcrest.Matchers; 022import org.hamcrest.TypeSafeMatcher; 023 024public class ScmFileMatcher 025 extends TypeSafeMatcher<ScmFile> 026{ 027 028 public static Matcher<ScmFile> scmFile( String fileName, ScmFileStatus status ) 029 { 030 return new ScmFileMatcher( fileName, status ); 031 } 032 033 @SuppressWarnings( "unchecked" ) 034 public static void assertHasScmFile( List<?> actualFiles, String fileName, ScmFileStatus status ) 035 { 036 org.junit.Assert.assertThat( (List<ScmFile>) actualFiles, 037 Matchers.<ScmFile>hasItem( scmFile( fileName, status ) ) ); 038 } 039 040 private ScmFileStatus status; 041 042 private String filePath; 043 044 public ScmFileMatcher( String filePath, ScmFileStatus status ) 045 { 046 // Convert to OS specific path... 047 this.filePath = new File( filePath ).getPath(); 048 this.status = status; 049 } 050 051 public void describeTo( Description desc ) 052 { 053 desc.appendValue( "ScmFile [" ); 054 desc.appendValue( filePath ); 055 desc.appendText( "," ); 056 desc.appendValue( status ); 057 desc.appendValue( "]" ); 058 } 059 060 @Override 061 public boolean matchesSafely( ScmFile scmFile ) 062 { 063 return scmFile.getPath().equals( filePath ) && scmFile.getStatus().equals( status ); 064 } 065 066}