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