1 32 33 package com.jeantessier.classreader; 34 35 import java.io.*; 36 import java.util.*; 37 38 public class TestClassfileLoaderPermissiveDispatcher extends TestClassfileLoader { 39 public static final String TEST_FILENAME = "classes" + File.separator + "test.class"; 40 41 private ClassfileLoader loader; 42 43 protected void setUp() throws Exception { 44 super.setUp(); 45 46 loader = new TransientClassfileLoader(new PermissiveDispatcher()); 47 loader.addLoadListener(this); 48 } 49 50 public void testOneFile() { 51 String filename = TEST_FILENAME; 52 assertTrue(filename + " missing", new File(filename).exists()); 53 54 loader.load(Collections.singleton(filename)); 55 56 assertEquals("Begin Session", 1, getBeginSessionEvents().size()); 57 assertEquals("Begin Group", 1, getBeginGroupEvents().size()); 58 assertEquals("Begin File", 1, getBeginFileEvents().size()); 59 assertEquals("Begin Classfile", 1, getBeginClassfileEvents().size()); 60 assertEquals("End Classfile", 1, getEndClassfileEvents().size()); 61 assertEquals("End File", 1, getEndFileEvents().size()); 62 assertEquals("End Group", 1, getEndGroupEvents().size()); 63 assertEquals("End Session", 1, getEndSessionEvents().size()); 64 65 assertEquals("Group size", 1, ((LoadEvent) getBeginGroupEvents().getFirst()).getSize()); 66 } 67 68 public void testOneLevelZip() { 69 String filename = TEST_DIR + File.separator + "onelevel.zip"; 70 assertTrue(filename + " missing", new File(filename).exists()); 71 72 loader.load(Collections.singleton(filename)); 73 74 assertEquals("Begin Session", 1, getBeginSessionEvents().size()); 75 assertEquals("Begin Group", 1, getBeginGroupEvents().size()); 76 assertEquals("Begin File", 38, getBeginFileEvents().size()); 77 assertEquals("Begin Classfile", 17, getBeginClassfileEvents().size()); 78 assertEquals("End Classfile", 17, getEndClassfileEvents().size()); 79 assertEquals("End File", 38, getEndFileEvents().size()); 80 assertEquals("End Group", 1, getEndGroupEvents().size()); 81 assertEquals("End Session", 1, getEndSessionEvents().size()); 82 83 assertEquals("Group size", 38, ((LoadEvent) getBeginGroupEvents().getFirst()).getSize()); 84 } 85 86 public void testOneLevelJar() { 87 String filename = TEST_DIR + File.separator + "onelevel.jar"; 88 assertTrue(filename + " missing", new File(filename).exists()); 89 90 loader.load(Collections.singleton(filename)); 91 92 assertEquals("Begin Session", 1, getBeginSessionEvents().size()); 93 assertEquals("Begin Group", 1, getBeginGroupEvents().size()); 94 assertEquals("Begin File", 40, getBeginFileEvents().size()); 95 assertEquals("Begin Classfile", 17, getBeginClassfileEvents().size()); 96 assertEquals("End Classfile", 17, getEndClassfileEvents().size()); 97 assertEquals("End File", 40, getEndFileEvents().size()); 98 assertEquals("End Group", 1, getEndGroupEvents().size()); 99 assertEquals("End Session", 1, getEndSessionEvents().size()); 100 101 assertEquals("Group size", 40, ((LoadEvent) getBeginGroupEvents().getFirst()).getSize()); 102 } 103 104 public void testOneLevelMiscellaneous() { 105 String filename = TEST_DIR + File.separator + "onelevel.mis"; 106 assertTrue(filename + " missing", new File(filename).exists()); 107 108 loader.load(Collections.singleton(filename)); 109 110 assertEquals("Begin Session", 1, getBeginSessionEvents().size()); 111 assertEquals("Begin Group", 1, getBeginGroupEvents().size()); 112 assertEquals("Begin File", 38, getBeginFileEvents().size()); 113 assertEquals("Begin Classfile", 17, getBeginClassfileEvents().size()); 114 assertEquals("End Classfile", 17, getEndClassfileEvents().size()); 115 assertEquals("End File", 38, getEndFileEvents().size()); 116 assertEquals("End Group", 1, getEndGroupEvents().size()); 117 assertEquals("End Session", 1, getEndSessionEvents().size()); 118 } 119 120 public void testTwoLevelZip() { 121 String filename = TEST_DIR + File.separator + "twolevel.zip"; 122 assertTrue(filename + " missing", new File(filename).exists()); 123 124 loader.load(Collections.singleton(filename)); 125 126 assertEquals("Begin Session", 1, getBeginSessionEvents().size()); 127 assertEquals("Begin Group", 2, getBeginGroupEvents().size()); 128 assertEquals("Begin File", 39, getBeginFileEvents().size()); 129 assertEquals("Begin Classfile", 17, getBeginClassfileEvents().size()); 130 assertEquals("End Classfile", 17, getEndClassfileEvents().size()); 131 assertEquals("End File", 39, getEndFileEvents().size()); 132 assertEquals("End Group", 2, getEndGroupEvents().size()); 133 assertEquals("End Session", 1, getEndSessionEvents().size()); 134 } 135 136 public void testTwoLevelJar() { 137 String filename = TEST_DIR + File.separator + "twolevel.jar"; 138 assertTrue(filename + " missing", new File(filename).exists()); 139 140 loader.load(Collections.singleton(filename)); 141 142 assertEquals("Begin Session", 1, getBeginSessionEvents().size()); 143 assertEquals("Begin Group", 2, getBeginGroupEvents().size()); 144 assertEquals("Begin File", 41, getBeginFileEvents().size()); 145 assertEquals("Begin Classfile", 17, getBeginClassfileEvents().size()); 146 assertEquals("End Classfile", 17, getEndClassfileEvents().size()); 147 assertEquals("End File", 41, getEndFileEvents().size()); 148 assertEquals("End Group", 2, getEndGroupEvents().size()); 149 assertEquals("End Session", 1, getEndSessionEvents().size()); 150 } 151 152 public void testTwoLevelMiscellaneous() { 153 String filename = TEST_DIR + File.separator + "twolevel.mis"; 154 assertTrue(filename + " missing", new File(filename).exists()); 155 156 loader.load(Collections.singleton(filename)); 157 158 assertEquals("Begin Session", 1, getBeginSessionEvents().size()); 159 assertEquals("Begin Group", 2, getBeginGroupEvents().size()); 160 assertEquals("Begin File", 39, getBeginFileEvents().size()); 161 assertEquals("Begin Classfile", 17, getBeginClassfileEvents().size()); 162 assertEquals("End Classfile", 17, getEndClassfileEvents().size()); 163 assertEquals("End File", 39, getEndFileEvents().size()); 164 assertEquals("End Group", 2, getEndGroupEvents().size()); 165 assertEquals("End Session", 1, getEndSessionEvents().size()); 166 } 167 } 168 | Popular Tags |