Added unit tests.

This commit is contained in:
Oliver Burn 2005-08-03 11:32:47 +00:00
parent a5d30bf353
commit 0f12e6e3c3
4 changed files with 82 additions and 2 deletions

View File

@ -75,7 +75,7 @@ final class AccessResult
private AccessResult(final int aCode, final String aLabel)
{
mCode = aCode;
mLabel = aLabel;
mLabel = aLabel.trim();
}
/**
@ -121,7 +121,7 @@ final class AccessResult
public static AccessResult getInstance(String aName)
{
// canonicalize argument
final String arName = aName.trim().toLowerCase();
final String arName = aName.trim();
final AccessResult retVal = (AccessResult) NAME_TO_LEVEL.get(arName);
if (retVal == null) {

View File

@ -0,0 +1,16 @@
<?xml version="1.0"?>
<!DOCTYPE import-control PUBLIC
"-//Puppy Crawl//DTD Import Control 1.0//EN"
"http://www.puppycrawl.com/dtds/import_control_1_0.dtd">
<import-control pkg="com">
<allow class="some.class"/>
<disallow class="another.class" local-only="selected"/>
<allow pkg="some.pkg"/>
<disallow pkg="another.pkg" local-only="selected"/>
<disallow pkg="and.another.pkg" exact-match="selected"/>
<subpackage name="puppycrawl">
<disallow pkg="some.pkg"/>
<disallow class="some.class"/>
</subpackage>
</import-control>

View File

@ -0,0 +1,49 @@
package com.puppycrawl.tools.checkstyle.checks.imports;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import junit.framework.TestCase;
public class AccessResultTest extends TestCase
{
public void testNormal()
{
assertEquals("ALLOWED", AccessResult.ALLOWED.getLabel());
assertEquals(AccessResult.ALLOWED.toString(), AccessResult.ALLOWED
.getLabel());
assertTrue(AccessResult.DISALLOWED.equals(AccessResult.DISALLOWED));
assertFalse(AccessResult.DISALLOWED.equals(this));
assertEquals(AccessResult.DISALLOWED.hashCode(),
AccessResult.DISALLOWED.hashCode());
final AccessResult revived = AccessResult
.getInstance(AccessResult.UNKNOWN.getLabel());
assertEquals(AccessResult.UNKNOWN, revived);
assertTrue(AccessResult.UNKNOWN == revived);
}
public void testBadname()
{
try {
AccessResult.getInstance("badname");
fail("should not get here");
}
catch (IllegalArgumentException ex) {
;
}
}
public void testSerial() throws Exception
{
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
final ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(AccessResult.ALLOWED);
final ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
final ObjectInputStream ois = new ObjectInputStream(bais);
final AccessResult revivied = (AccessResult) ois.readObject();
assertNotNull(revivied);
assertTrue(revivied == AccessResult.ALLOWED);
}
}

View File

@ -0,0 +1,15 @@
package com.puppycrawl.tools.checkstyle.checks.imports;
import com.puppycrawl.tools.checkstyle.api.CheckstyleException;
import junit.framework.TestCase;
public class ImportControlLoaderTest extends TestCase
{
public void testLoad() throws CheckstyleException
{
final PkgControl root = ImportControlLoader.load(System
.getProperty("testinputs.dir")
+ "/import-control_complete.xml");
assertNotNull(root);
}
}