Coverage Report - org.apache.maven.scm.tck.command.blame.BlameCommandTckTest
 
Classes in this File Line Coverage Branch Coverage Complexity
BlameCommandTckTest
0 %
0/37
0 %
0/8
1,5
 
 1  
 package org.apache.maven.scm.tck.command.blame;
 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 org.apache.maven.scm.ScmFileSet;
 23  
 import org.apache.maven.scm.ScmTckTestCase;
 24  
 import org.apache.maven.scm.ScmTestCase;
 25  
 import org.apache.maven.scm.command.blame.BlameLine;
 26  
 import org.apache.maven.scm.command.blame.BlameScmResult;
 27  
 import org.apache.maven.scm.command.checkin.CheckInScmResult;
 28  
 import org.apache.maven.scm.manager.ScmManager;
 29  
 import org.apache.maven.scm.provider.ScmProvider;
 30  
 import org.apache.maven.scm.repository.ScmRepository;
 31  
 
 32  
 import java.util.Date;
 33  
 
 34  
 /**
 35  
  * @author Evgeny Mandrikov
 36  
  */
 37  0
 public abstract class BlameCommandTckTest
 38  
     extends ScmTckTestCase
 39  
 {
 40  
     private static final String COMMIT_MSG = "Second changelog";
 41  
 
 42  
     public void testBlameCommand()
 43  
         throws Exception
 44  
     {
 45  0
         ScmRepository repository = getScmRepository();
 46  0
         ScmManager manager = getScmManager();
 47  0
         ScmProvider provider = manager.getProviderByRepository( getScmRepository() );
 48  0
         ScmFileSet fileSet = new ScmFileSet( getWorkingCopy() );
 49  
 
 50  
         BlameScmResult result;
 51  
         BlameLine line;
 52  
 
 53  
         // === readme.txt ===
 54  0
         result = manager.blame( repository, fileSet, "readme.txt" );
 55  0
         assertNotNull( "The command returned a null result.", result );
 56  0
         assertResultIsSuccess( result );
 57  0
         assertEquals( "Expected 1 line in blame", 1, result.getLines().size() );
 58  0
         line = result.getLines().get( 0 );
 59  0
         String initialRevision = line.getRevision();
 60  
 
 61  
         //Make a timestamp that we know are after initial revision but before the second
 62  0
         Date timeBeforeSecond = new Date(); // Current time
 63  
         // pause a couple seconds...
 64  0
         Thread.sleep( 2000 );
 65  
         //Make a change to the readme.txt and commit the change
 66  0
         ScmTestCase.makeFile( getWorkingCopy(), "/readme.txt", "changed readme.txt" );
 67  0
         CheckInScmResult checkInResult = provider.checkIn( getScmRepository(), fileSet, COMMIT_MSG );
 68  0
         assertTrue( "Unable to checkin changes to the repository", checkInResult.isSuccess() );
 69  
 
 70  0
         result = manager.blame( repository, fileSet, "readme.txt" );
 71  
 
 72  
         // pause a couple seconds...
 73  0
         Thread.sleep( 2000 );
 74  0
         Date timeAfterSecond = new Date(); // Current time
 75  
 
 76  0
         assertNotNull( "The command returned a null result.", result );
 77  0
         assertResultIsSuccess( result );
 78  
 
 79  0
         assertEquals( "Expected 1 line in blame", 1, result.getLines().size() );
 80  0
         line = result.getLines().get( 0 );
 81  
 
 82  0
         assertNotNull( "Expected not null author", line.getAuthor() );
 83  0
         assertNotNull( "Expected not null revision", line.getRevision() );
 84  0
         assertNotNull( "Expected not null date", line.getDate() );
 85  
 
 86  0
         assertTrue( "Expected another revision", !initialRevision.equals( line.getRevision() ) );
 87  0
         if ( isTestDateTime() )
 88  
         {
 89  0
             assertDateBetween( timeBeforeSecond, timeAfterSecond, line.getDate() );
 90  
         }
 91  
 
 92  
         // === pom.xml ===
 93  0
         result = manager.blame( repository, fileSet, "pom.xml" );
 94  
 
 95  0
         assertNotNull( "The command returned a null result.", result );
 96  
 
 97  0
         assertResultIsSuccess( result );
 98  
 
 99  0
         verifyResult( result );
 100  0
     }
 101  
 
 102  
     protected boolean isTestDateTime()
 103  
     {
 104  0
         return true;
 105  
     }
 106  
 
 107  
     protected void assertDateBetween( Date start, Date end, Date actual )
 108  
     {
 109  0
         assertTrue( "Expected date between " + start + " and " + end + ", but was " + actual,
 110  
                     start.before( actual ) && actual.before( end ) );
 111  0
     }
 112  
 
 113  
     protected abstract void verifyResult( BlameScmResult result );
 114  
 }