1   package org.apache.maven.scm.provider.cvslib.command.changelog;
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.ChangeSet;
23  import org.apache.maven.scm.log.DefaultLog;
24  import org.apache.maven.scm.provider.cvslib.AbstractCvsScmTest;
25  
26  import java.io.BufferedReader;
27  import java.io.File;
28  import java.io.FileInputStream;
29  import java.io.InputStreamReader;
30  import java.util.Collection;
31  import java.util.Iterator;
32  
33  /**
34   * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
35   * @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
36   * @version $Id: CvsChangeLogConsumerTest.java 1057015 2011-01-09 20:10:42Z olamy $
37   */
38  public class CvsChangeLogConsumerTest
39      extends AbstractCvsScmTest
40  {
41      /**
42       * file with test results to check against
43       */
44      private File testFile;
45  
46      /**
47       * Initialize per test data
48       *
49       * @throws Exception when there is an unexpected problem
50       */
51      public void setUp()
52          throws Exception
53      {
54          super.setUp();
55  
56          testFile = getTestFile( "/src/test/resources/cvslib/changelog/cvslog.txt" );
57      }
58  
59      /**
60       * Test of parse method
61       *
62       * @throws Exception when there is an unexpected problem
63       */
64      public void testParse()
65          throws Exception
66      {
67          CvsChangeLogConsumer command = new CvsChangeLogConsumer( new DefaultLog(), null );
68  
69          FileInputStream fis = new FileInputStream( testFile );
70          BufferedReader in = new BufferedReader( new InputStreamReader( fis ) );
71          String s = in.readLine();
72          while ( s != null )
73          {
74              command.consumeLine( s );
75              s = in.readLine();
76          }
77  
78          Collection<ChangeSet> entries = command.getModifications();
79          assertEquals( "Wrong number of entries returned", 3, entries.size() );
80          ChangeSet entry = null;
81          for ( Iterator<ChangeSet> i = entries.iterator(); i.hasNext(); )
82          {
83              entry = i.next();
84              assertTrue( "ChangeLogEntry erroneously picked up",
85                          entry.toString().indexOf( "ChangeLogEntry.java" ) == -1 );
86          }
87      }
88  }