| 1 |
|
package com.puppycrawl.tools.checkstyle; |
| 2 |
|
|
| 3 |
|
import com.puppycrawl.tools.checkstyle.api.AuditEvent; |
| 4 |
|
import com.puppycrawl.tools.checkstyle.api.Configuration; |
| 5 |
|
|
| 6 |
|
import java.io.ByteArrayInputStream; |
| 7 |
|
import java.io.ByteArrayOutputStream; |
| 8 |
|
import java.io.File; |
| 9 |
|
import java.io.IOException; |
| 10 |
|
import java.io.InputStreamReader; |
| 11 |
|
import java.io.LineNumberReader; |
| 12 |
|
import java.io.OutputStream; |
| 13 |
|
import java.io.PrintStream; |
| 14 |
|
import java.util.Locale; |
| 15 |
|
import java.util.Properties; |
| 16 |
|
|
| 17 |
|
import junit.framework.TestCase; |
| 18 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (41) |
Complexity: 9 |
Complexity Density: 0.29 |
|
| 19 |
|
public abstract class BaseCheckTestCase |
| 20 |
|
extends TestCase |
| 21 |
|
{ |
| 22 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 4 |
Complexity Density: 4 |
|
| 23 |
|
protected static class BriefLogger |
| 24 |
|
extends DefaultLogger |
| 25 |
|
{ |
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 26 |
448
|
public BriefLogger(OutputStream out)... |
| 27 |
|
{ |
| 28 |
448
|
super(out, true); |
| 29 |
|
} |
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
| 30 |
448
|
public void auditStarted(AuditEvent evt) {}... |
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
| 31 |
459
|
public void fileFinished(AuditEvent evt) {}... |
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
| 32 |
459
|
public void fileStarted(AuditEvent evt) {}... |
| 33 |
|
} |
| 34 |
|
|
| 35 |
|
protected final ByteArrayOutputStream mBAOS = new ByteArrayOutputStream(); |
| 36 |
|
protected final PrintStream mStream = new PrintStream(mBAOS); |
| 37 |
|
protected final Properties mProps = new Properties(); |
| 38 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 39 |
920
|
public static DefaultConfiguration createCheckConfig(Class aClazz)... |
| 40 |
|
{ |
| 41 |
920
|
final DefaultConfiguration checkConfig = |
| 42 |
|
new DefaultConfiguration(aClazz.getName()); |
| 43 |
920
|
return checkConfig; |
| 44 |
|
} |
| 45 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
|
| 46 |
449
|
protected Checker createChecker(Configuration aCheckConfig)... |
| 47 |
|
throws Exception |
| 48 |
|
{ |
| 49 |
449
|
final DefaultConfiguration dc = createCheckerConfig(aCheckConfig); |
| 50 |
449
|
final Checker c = new Checker(); |
| 51 |
|
|
| 52 |
|
|
| 53 |
449
|
final Locale locale = Locale.ENGLISH; |
| 54 |
449
|
c.setLocaleCountry(locale.getCountry()); |
| 55 |
449
|
c.setLocaleLanguage(locale.getLanguage()); |
| 56 |
449
|
c.configure(dc); |
| 57 |
440
|
c.addListener(new BriefLogger(mStream)); |
| 58 |
440
|
return c; |
| 59 |
|
} |
| 60 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
|
| 61 |
435
|
protected DefaultConfiguration createCheckerConfig(Configuration aConfig)... |
| 62 |
|
{ |
| 63 |
435
|
final DefaultConfiguration dc = |
| 64 |
|
new DefaultConfiguration("configuration"); |
| 65 |
435
|
final DefaultConfiguration twConf = createCheckConfig(TreeWalker.class); |
| 66 |
|
|
| 67 |
435
|
twConf.addAttribute("charset", "iso-8859-1"); |
| 68 |
435
|
dc.addChild(twConf); |
| 69 |
435
|
twConf.addChild(aConfig); |
| 70 |
435
|
return dc; |
| 71 |
|
} |
| 72 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 73 |
477
|
protected static String getPath(String aFilename)... |
| 74 |
|
throws IOException |
| 75 |
|
{ |
| 76 |
477
|
final File f = new File(System.getProperty("testinputs.dir"), |
| 77 |
|
aFilename); |
| 78 |
477
|
return f.getCanonicalPath(); |
| 79 |
|
} |
| 80 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 81 |
405
|
protected void verify(Configuration aConfig, String aFileName, String[] aExpected)... |
| 82 |
|
throws Exception |
| 83 |
|
{ |
| 84 |
405
|
verify(createChecker(aConfig), aFileName, aFileName, aExpected); |
| 85 |
|
} |
| 86 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 87 |
36
|
protected void verify(Checker aC, String aFileName, String[] aExpected)... |
| 88 |
|
throws Exception |
| 89 |
|
{ |
| 90 |
36
|
verify(aC, aFileName, aFileName, aExpected); |
| 91 |
|
} |
| 92 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 93 |
440
|
protected void verify(Checker aC,... |
| 94 |
|
String aProcessedFilename, |
| 95 |
|
String aMessageFileName, |
| 96 |
|
String[] aExpected) |
| 97 |
|
throws Exception |
| 98 |
|
{ |
| 99 |
440
|
verify(aC, |
| 100 |
|
new File[] {new File(aProcessedFilename)}, |
| 101 |
|
aMessageFileName, aExpected); |
| 102 |
|
} |
| 103 |
|
|
|
|
|
|