1   package org.apache.maven.cvslib;
2   
3   /* ====================================================================
4    *   Licensed to the Apache Software Foundation (ASF) under one or more
5    *   contributor license agreements.  See the NOTICE file distributed with
6    *   this work for additional information regarding copyright ownership.
7    *   The ASF licenses this file to You under the Apache License, Version 2.0
8    *   (the "License"); you may not use this file except in compliance with
9    *   the License.  You may obtain a copy of the License at
10   *
11   *       http://www.apache.org/licenses/LICENSE-2.0
12   *
13   *   Unless required by applicable law or agreed to in writing, software
14   *   distributed under the License is distributed on an "AS IS" BASIS,
15   *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   *   See the License for the specific language governing permissions and
17   *   limitations under the License.
18   * ====================================================================
19   */
20  
21  import java.io.FileInputStream;
22  import java.util.Collection;
23  import java.util.Iterator;
24  import junit.framework.TestCase;
25  
26  import org.apache.maven.changelog.ChangeLogEntry;
27  
28  
29  /**
30   * Test cases for {@link CvsChangeLogParser}
31   * @author dion
32   * @version $Id: CvsChangeLogParserTest.java 532339 2007-04-25 12:28:56Z ltheussl $
33   */
34  public class CvsChangeLogParserTest extends TestCase
35  {
36  
37      /** the {@link CvsChangeLogParser} used for testing */
38      private CvsChangeLogParser instance;
39      /** file with test results to check against */
40      private String testFile;
41      /** file with test results to check against */
42      private String testFile2;
43  
44      /**
45       * Create a test with the given name
46       * @param testName the name of the test
47       */
48      public CvsChangeLogParserTest(String testName)
49      {
50          super(testName);
51      }
52  
53      /**
54       * Initialize per test data
55       * @throws Exception when there is an unexpected problem
56       */
57      public void setUp() throws Exception
58      {
59          String baseDir = System.getProperty("basedir");
60          assertNotNull("The system property basedir was not defined.", baseDir);
61          testFile = baseDir + "/src/test-resources/cvslib/cvslog.txt";
62          testFile2 = baseDir + "/src/test-resources/cvslib/cvslog_new.txt";
63          instance = new CvsChangeLogParser();
64      }
65  
66      /**
67       * Test of parse method
68       * @throws Exception when there is an unexpected problem
69       */
70      public void testParse() throws Exception
71      {
72          parse(testFile);
73      }
74      
75      /**
76       * Test of parse method
77       * @throws Exception when there is an unexpected problem
78       */
79      public void testParse2() throws Exception
80      {
81          parse(testFile2);
82      }
83      
84      /**
85       * Test of parse method
86       * @throws Exception when there is an unexpected problem
87       */
88      public void parse(String file) throws Exception
89      {
90          FileInputStream fis = new FileInputStream(file);
91          Collection entries = instance.parse(fis);
92          assertEquals("Wrong number of entries returned", 3, entries.size());
93          ChangeLogEntry entry = null;
94          for (Iterator i = entries.iterator(); i.hasNext(); )
95          {
96              entry = (ChangeLogEntry) i.next();
97              assertTrue("ChangeLogEntry erroneously picked up",
98                  entry.toString().indexOf("ChangeLogEntry.java") == -1);
99          }
100     }
101 
102     // Add test methods here, they have to start with 'test' name.
103     // for example:
104     // public void testHello() {}
105 
106 
107 }