1 package com.puppycrawl.tools.checkstyle.checks.imports; 2 3 import java.io.ByteArrayInputStream ; 4 import java.io.ByteArrayOutputStream ; 5 import java.io.ObjectInputStream ; 6 import java.io.ObjectOutputStream ; 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 ex) { 33 ; 34 } 35 } 36 37 public void testSerial() throws Exception 38 { 39 final ByteArrayOutputStream baos = new ByteArrayOutputStream (); 40 final ObjectOutputStream oos = new ObjectOutputStream (baos); 41 oos.writeObject(AccessResult.ALLOWED); 42 final ByteArrayInputStream bais = new ByteArrayInputStream (baos.toByteArray()); 43 final ObjectInputStream ois = new ObjectInputStream (bais); 44 final AccessResult revivied = (AccessResult) ois.readObject(); 45 assertNotNull(revivied); 46 assertTrue(revivied == AccessResult.ALLOWED); 47 } 48 } 49 | Popular Tags |