1 32 33 package com.jeantessier.metrics; 34 35 import junit.framework.*; 36 37 public class TestMeasurementDescriptor extends TestCase { 38 private MeasurementDescriptor descriptor; 39 40 protected void setUp() { 41 descriptor = new MeasurementDescriptor(); 42 } 43 44 public void testCreate() { 45 assertNull("descriptor.ShortName() not initialized to null", descriptor.getShortName()); 46 assertNull("descriptor.LongName() not initialized to null", descriptor.getLongName()); 47 assertNull("descriptor.Class() not initialized to null", descriptor.getClassFor()); 48 } 49 50 public void testShortName() { 51 assertNull("descriptor.ShortName() not initialized to null", descriptor.getShortName()); 52 descriptor.setShortName("foo"); 53 assertEquals("descriptor.ShortName()", "foo", descriptor.getShortName()); 54 } 55 56 public void testLongName() { 57 assertNull("descriptor.LongName() not initialized to null", descriptor.getLongName()); 58 descriptor.setLongName("bar"); 59 assertEquals("descriptor.LongName()", "bar", descriptor.getLongName()); 60 } 61 62 public void testNonExistingClass() { 63 assertNull("descriptor.Class() not initialized to null", descriptor.getClassFor()); 64 try { 65 descriptor.getClassForByName("nop such class"); 66 fail("set class to non-existing class"); 67 } catch (ClassNotFoundException ex) { 68 } 70 } 71 72 public void testNullClass() { 73 assertNull("descriptor.Class() not initialized to null", descriptor.getClassFor()); 74 try { 75 descriptor.setClassFor((Class ) null); 76 fail("set class to null"); 77 } catch (IllegalArgumentException ex) { 78 } 80 } 81 82 public void testClass() { 83 assertNull("descriptor.Class() not initialized to null", descriptor.getClassFor()); 84 descriptor.setClassFor(com.jeantessier.metrics.CounterMeasurement.class); 85 assertEquals("descriptor.Class()", com.jeantessier.metrics.CounterMeasurement.class, descriptor.getClassFor()); 86 } 87 88 public void testClassByName() throws ClassNotFoundException { 89 descriptor.getClassForByName(com.jeantessier.metrics.CounterMeasurement.class.getName()); 90 assertEquals("descriptor.Class()", com.jeantessier.metrics.CounterMeasurement.class, descriptor.getClassFor()); 91 } 92 } 93 | Popular Tags |