KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tools > ant > taskdefs > optional > metamata > MAuditParserTest


1 /*
2  * Copyright 2002,2004 The Apache Software Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */

17 package org.apache.tools.ant.taskdefs.optional.metamata;
18
19 import java.io.File JavaDoc;
20
21 import junit.framework.TestCase;
22
23 import org.apache.tools.ant.util.StringUtils;
24
25 /**
26  * Test for the Audit parser.
27  *
28  */

29 public class MAuditParserTest extends TestCase {
30
31     private MAuditParser parser;
32
33     public MAuditParserTest(String JavaDoc s) {
34         super(s);
35     }
36
37     protected void setUp() {
38         parser = new MAuditParser();
39     }
40
41     public void testViolation() {
42         String JavaDoc line = "file:\\WebGain\\QA\\examples\\auditexamples\\Vector.java:55: Array declarators (\"[]\") should be placed with their component types and not after field/method declarations (5.27).";
43         // the replace is done to simulate a platform dependant separator since
44
// the parser may do some magic with the file separator
45
line = StringUtils.replace(line, "\\", File.separator);
46         MAuditParser.Violation violation = parser.parseLine(line);
47         assertEquals("\\WebGain\\QA\\examples\\auditexamples\\Vector.java",
48                 StringUtils.replace(violation.file, File.separator, "\\"));
49         assertEquals("55", violation.line);
50         assertEquals("Array declarators (\"[]\") should be placed with their component types and not after field/method declarations (5.27).", violation.error);
51     }
52
53     public void testNonViolation(){
54         String JavaDoc line = "Audit completed with 36 violations.";
55         Object JavaDoc violation = parser.parseLine(line);
56         assertNull(violation);
57     }
58
59     public void testFilePathInViolation(){
60         String JavaDoc line = "file:\\WebGain\\QA\\examples\\auditexamples\\Hashtable.java:302: Loop variable defined at file:\\WebGain\\QA\\examples\\auditexamples\\Hashtable.java:300 is being modified (5.16).";
61         line = StringUtils.replace(line, "\\", File.separator);
62         MAuditParser.Violation violation = parser.parseLine(line);
63         assertEquals("\\WebGain\\QA\\examples\\auditexamples\\Hashtable.java",
64                 StringUtils.replace(violation.file, File.separator, "\\"));
65         assertEquals("302", violation.line);
66         assertEquals("Loop variable defined at Hashtable.java:300 is being modified (5.16).", violation.error);
67     }
68
69 }
70
Popular Tags