KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > puppycrawl > tools > checkstyle > checks > imports > AccessResultTest


1 package com.puppycrawl.tools.checkstyle.checks.imports;
2
3 import java.io.ByteArrayInputStream JavaDoc;
4 import java.io.ByteArrayOutputStream JavaDoc;
5 import java.io.ObjectInputStream JavaDoc;
6 import java.io.ObjectOutputStream JavaDoc;
7 import junit.framework.TestCase;
8
9 public class AccessResultTest extends TestCase
10 {
11     public void testNormal()
12     {
13         assertEquals("ALLOWED", AccessResult.ALLOWED.getLabel());
14         assertEquals(AccessResult.ALLOWED.toString(), AccessResult.ALLOWED
15                 .getLabel());
16         assertTrue(AccessResult.DISALLOWED.equals(AccessResult.DISALLOWED));
17         assertFalse(AccessResult.DISALLOWED.equals(this));
18         assertEquals(AccessResult.DISALLOWED.hashCode(),
19                 AccessResult.DISALLOWED.hashCode());
20         final AccessResult revived = AccessResult
21                 .getInstance(AccessResult.UNKNOWN.getLabel());
22         assertEquals(AccessResult.UNKNOWN, revived);
23         assertTrue(AccessResult.UNKNOWN == revived);
24     }
25
26     public void testBadname()
27     {
28         try {
29             AccessResult.getInstance("badname");
30             fail("should not get here");
31         }
32         catch (IllegalArgumentException JavaDoc ex) {
33             ;
34         }
35     }
36
37     public void testSerial() throws Exception JavaDoc
38     {
39         final ByteArrayOutputStream JavaDoc baos = new ByteArrayOutputStream JavaDoc();
40         final ObjectOutputStream JavaDoc oos = new ObjectOutputStream JavaDoc(baos);
41         oos.writeObject(AccessResult.ALLOWED);
42         final ByteArrayInputStream JavaDoc bais = new ByteArrayInputStream JavaDoc(baos.toByteArray());
43         final ObjectInputStream JavaDoc ois = new ObjectInputStream JavaDoc(bais);
44         final AccessResult revivied = (AccessResult) ois.readObject();
45         assertNotNull(revivied);
46         assertTrue(revivied == AccessResult.ALLOWED);
47     }
48 }
49
Popular Tags