View Javadoc
1   package org.apache.maven.scm.provider.git.gitexe.command.update;
2   
3   import java.io.BufferedReader;
4   import java.io.File;
5   import java.io.Reader;
6   
7   import org.apache.maven.scm.log.DefaultLog;
8   import org.codehaus.plexus.PlexusTestCase;
9   import org.codehaus.plexus.util.ReaderFactory;
10  
11  /*
12   * Licensed to the Apache Software Foundation (ASF) under one
13   * or more contributor license agreements.  See the NOTICE file
14   * distributed with this work for additional information
15   * regarding copyright ownership.  The ASF licenses this file
16   * to you under the Apache License, Version 2.0 (the
17   * "License"); you may not use this file except in compliance
18   * with the License.  You may obtain a copy of the License at
19   *
20   *   http://www.apache.org/licenses/LICENSE-2.0
21   *
22   * Unless required by applicable law or agreed to in writing,
23   * software distributed under the License is distributed on an
24   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
25   * KIND, either express or implied.  See the License for the
26   * specific language governing permissions and limitations
27   * under the License.
28   */
29  
30  /**
31   * @author <a href="mailto:struberg@yahoo.de">Mark Struberg</a>
32   * @since 1.2
33   *
34   */
35  public class GitLatestRevisionCommandConsumerTest
36      extends PlexusTestCase
37  {
38      public void testUpToDate()
39          throws Exception
40      {
41  
42          GitLatestRevisionCommandConsumer consumer = buildGitLatestRevisionCommandConsumer( "/src/test/resources/git/update/git-update-latest-rev.out" );
43  
44          String latestRev = consumer.getLatestRevision();
45  
46          assertNotNull( latestRev );
47          assertEquals( "a300c56a341bae8d0eb5ec4ed5551a11c75a5a6e", latestRev );
48      }
49  
50      
51      // utils methods
52  
53      private GitLatestRevisionCommandConsumer buildGitLatestRevisionCommandConsumer( String fileName )
54          throws Exception
55      {
56          GitLatestRevisionCommandConsumer consumer = new GitLatestRevisionCommandConsumer( new DefaultLog() );
57  
58          BufferedReader r = getGitLogBufferedReader( fileName );
59  
60          String line;
61  
62          while ( ( line = r.readLine() ) != null )
63          {
64              //System.out.println(" line " + line );
65              consumer.consumeLine( line );
66          }
67          return consumer;
68      }
69  
70      private BufferedReader getGitLogBufferedReader( String fileName )
71          throws Exception
72      {
73          File f = getTestFile( fileName );
74          Reader reader = ReaderFactory.newReader( f, "UTF-8" );
75          return new BufferedReader( reader );
76      }
77  }