001package org.apache.maven.scm.provider.accurev.command.blame;
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.hamcrest.Matchers.is;
023import static org.junit.Assert.assertThat;
024import static org.mockito.Mockito.when;
025
026import java.io.File;
027import java.util.Collections;
028import java.util.Date;
029
030import org.apache.maven.scm.CommandParameter;
031import org.apache.maven.scm.CommandParameters;
032import org.apache.maven.scm.ScmFileSet;
033import org.apache.maven.scm.command.blame.BlameLine;
034import org.apache.maven.scm.command.blame.BlameScmResult;
035import org.apache.maven.scm.provider.accurev.command.AbstractAccuRevCommandTest;
036import org.junit.Test;
037
038public class AccuRevBlameCommandTest
039    extends AbstractAccuRevCommandTest
040{
041
042    @Test
043    public void testBlame()
044        throws Exception
045    {
046
047        final File file = new File( "src/main/java/Foo.java" );
048        final ScmFileSet testFileSet = new ScmFileSet( basedir, file );
049
050        final Date date = new Date();
051        final BlameLine blameLine = new BlameLine( date, "12", "theAuthor" );
052
053        when( accurev.annotate( basedir, file ) ).thenReturn( Collections.singletonList( blameLine ) );
054
055        AccuRevBlameCommand command = new AccuRevBlameCommand( getLogger() );
056
057        CommandParameters commandParameters = new CommandParameters();
058        commandParameters.setString( CommandParameter.FILE, file.getPath() );
059        BlameScmResult result = command.blame( repo, testFileSet, commandParameters );
060
061        assertThat( result.isSuccess(), is( true ) );
062        assertThat( result.getLines().size(), is( 1 ) );
063        assertThat( ( (BlameLine) result.getLines().get( 0 ) ), is( blameLine ) );
064
065    }
066}