1 29 30 package nextapp.echo2.app.test; 31 32 import nextapp.echo2.app.Extent; 33 import junit.framework.TestCase; 34 35 39 public class ExtentTest extends TestCase { 40 41 private static final Extent _50_CENTIMETERS = new Extent(50, Extent.CM); 42 private static final Extent _50_EM = new Extent(50, Extent.EM); 43 private static final Extent _50_EX = new Extent(50, Extent.EX); 44 private static final Extent _50_INCHES = new Extent(50, Extent.IN); 45 private static final Extent _50_MILLIMETERS = new Extent(50, Extent.MM); 46 private static final Extent _50_PERCENT = new Extent(50, Extent.PERCENT); 47 private static final Extent _50_PICAS = new Extent(50, Extent.PC); 48 private static final Extent _50_PIXELS = new Extent(50, Extent.PX); 49 private static final Extent _50_POINT = new Extent(50, Extent.PT); 50 51 54 public void testAdd() { 55 assertEquals(Extent.add(_50_EM, _50_EM), new Extent(100, Extent.EM)); 56 } 57 58 61 public void testEquals() { 62 assertEquals(new Extent(20, Extent.CM), new Extent(20, Extent.CM)); 63 assertFalse(new Extent(20, Extent.CM).equals(new Extent(21, Extent.CM))); 64 assertFalse(new Extent(20, Extent.MM).equals(new Extent(21, Extent.CM))); 65 } 66 67 70 public void testCompareTo() { 71 assertTrue(_50_INCHES.compareTo(_50_INCHES) == 0); 72 assertTrue(_50_CENTIMETERS.compareTo(_50_INCHES) < 0); 73 assertTrue(_50_MILLIMETERS.compareTo(_50_INCHES) < 0); 74 assertTrue(_50_PICAS.compareTo(_50_INCHES) < 0); 75 assertTrue(_50_POINT.compareTo(_50_INCHES) < 0); 76 assertTrue(_50_INCHES.compareTo(_50_CENTIMETERS) == 0 - _50_CENTIMETERS.compareTo(_50_INCHES)); 77 assertTrue(_50_POINT.compareTo(_50_INCHES) == 0 - _50_INCHES.compareTo(_50_POINT)); 78 79 assertTrue(_50_EX.compareTo(_50_PIXELS) != 0); 80 assertTrue(_50_EX.compareTo(_50_PIXELS) == 0 - _50_PIXELS.compareTo(_50_EX)); 81 } 82 83 86 public void testIsComparableTo() { 87 assertTrue(_50_CENTIMETERS.isComparableTo(_50_MILLIMETERS)); 88 assertTrue(_50_INCHES.isComparableTo(_50_MILLIMETERS)); 89 assertTrue(_50_PICAS.isComparableTo(_50_MILLIMETERS)); 90 assertTrue(_50_POINT.isComparableTo(_50_MILLIMETERS)); 91 assertTrue(_50_PIXELS.isComparableTo(_50_PIXELS)); 92 assertFalse(_50_PERCENT.isComparableTo(_50_MILLIMETERS)); 93 assertFalse(_50_PERCENT.isComparableTo(_50_PIXELS)); 94 } 95 96 99 public void testIsEnglish() { 100 assertFalse(_50_CENTIMETERS.isEnglish()); 101 assertFalse(_50_EM.isEnglish()); 102 assertFalse(_50_EX.isEnglish()); 103 assertTrue(_50_INCHES.isEnglish()); 104 assertFalse(_50_MILLIMETERS.isEnglish()); 105 assertFalse(_50_PERCENT.isEnglish()); 106 assertTrue(_50_PICAS.isEnglish()); 107 assertFalse(_50_PIXELS.isEnglish()); 108 assertTrue(_50_POINT.isEnglish()); 109 } 110 111 114 public void testIsSI() { 115 assertTrue(_50_CENTIMETERS.isSI()); 116 assertFalse(_50_EM.isSI()); 117 assertFalse(_50_EX.isSI()); 118 assertFalse(_50_INCHES.isSI()); 119 assertTrue(_50_MILLIMETERS.isSI()); 120 assertFalse(_50_PERCENT.isSI()); 121 assertFalse(_50_PICAS.isSI()); 122 assertFalse(_50_PIXELS.isSI()); 123 assertFalse(_50_POINT.isSI()); 124 } 125 126 129 public void testIsPercentage() { 130 assertFalse(_50_CENTIMETERS.isPercentage()); 131 assertFalse(_50_EM.isPercentage()); 132 assertFalse(_50_EX.isPercentage()); 133 assertFalse(_50_INCHES.isPercentage()); 134 assertFalse(_50_MILLIMETERS.isPercentage()); 135 assertTrue(_50_PERCENT.isPercentage()); 136 assertFalse(_50_PICAS.isPercentage()); 137 assertFalse(_50_PIXELS.isPercentage()); 138 assertFalse(_50_POINT.isPercentage()); 139 } 140 141 144 public void testIsPrint() { 145 assertTrue(_50_CENTIMETERS.isPrint()); 146 assertFalse(_50_EM.isPrint()); 147 assertFalse(_50_EX.isPrint()); 148 assertTrue(_50_INCHES.isPrint()); 149 assertTrue(_50_MILLIMETERS.isPrint()); 150 assertFalse(_50_PERCENT.isPrint()); 151 assertTrue(_50_PICAS.isPrint()); 152 assertFalse(_50_PIXELS.isPrint()); 153 assertTrue(_50_POINT.isPrint()); 154 } 155 156 159 public void testToMm() { 160 assertEquals(20, new Extent(20, Extent.MM).toMm()); 161 assertEquals(20, new Extent(2, Extent.CM).toMm()); 162 assertEquals(2540, new Extent(100, Extent.IN).toMm()); 163 assertEquals(2540, new Extent(7200, Extent.PT).toMm()); 164 assertEquals(2540, new Extent(600, Extent.PC).toMm()); 165 166 try { 167 new Extent(1, Extent.EM).toMm(); 168 fail("Did not throw IllegalStateException."); 169 } catch (IllegalStateException ex) { 170 } 172 173 try { 174 new Extent(1, Extent.EX).toMm(); 175 fail("Did not throw IllegalStateException."); 176 } catch (IllegalStateException ex) { 177 } 179 180 try { 181 new Extent(1, Extent.PERCENT).toMm(); 182 fail("Did not throw IllegalStateException."); 183 } catch (IllegalStateException ex) { 184 } 186 187 try { 188 new Extent(1, Extent.PX).toMm(); 189 fail("Did not throw IllegalStateException."); 190 } catch (IllegalStateException ex) { 191 } 193 } 194 195 198 public void testToPoint() { 199 assertEquals(20, new Extent(20, Extent.PT).toPoint()); 200 assertEquals(7200, new Extent(2540, Extent.MM).toPoint()); 201 assertEquals(7200, new Extent(254, Extent.CM).toPoint()); 202 assertEquals(7200, new Extent(100, Extent.IN).toPoint()); 203 assertEquals(7200, new Extent(600, Extent.PC).toPoint()); 204 205 try { 206 new Extent(1, Extent.EM).toPoint(); 207 fail("Did not throw IllegalStateException."); 208 } catch (IllegalStateException ex) { 209 } 211 212 try { 213 new Extent(1, Extent.EX).toPoint(); 214 fail("Did not throw IllegalStateException."); 215 } catch (IllegalStateException ex) { 216 } 218 219 try { 220 new Extent(1, Extent.PERCENT).toPoint(); 221 fail("Did not throw IllegalStateException."); 222 } catch (IllegalStateException ex) { 223 } 225 226 try { 227 new Extent(1, Extent.PX).toPoint(); 228 fail("Did not throw IllegalStateException."); 229 } catch (IllegalStateException ex) { 230 } 232 } 233 } 234 | Popular Tags |