001: /*
002: * Copyright (c) 2001-2007, Jean Tessier
003: * All rights reserved.
004: *
005: * Redistribution and use in source and binary forms, with or without
006: * modification, are permitted provided that the following conditions
007: * are met:
008: *
009: * * Redistributions of source code must retain the above copyright
010: * notice, this list of conditions and the following disclaimer.
011: *
012: * * Redistributions in binary form must reproduce the above copyright
013: * notice, this list of conditions and the following disclaimer in the
014: * documentation and/or other materials provided with the distribution.
015: *
016: * * Neither the name of Jean Tessier nor the names of his contributors
017: * may be used to endorse or promote products derived from this software
018: * without specific prior written permission.
019: *
020: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
021: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
022: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
023: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
024: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
025: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
026: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
027: * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
028: * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
029: * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
030: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
031: */
032:
033: package com.jeantessier.metrics;
034:
035: import junit.framework.*;
036:
037: public class TestMeasurementDescriptor extends TestCase {
038: private MeasurementDescriptor descriptor;
039:
040: protected void setUp() {
041: descriptor = new MeasurementDescriptor();
042: }
043:
044: public void testCreate() {
045: assertNull("descriptor.ShortName() not initialized to null",
046: descriptor.getShortName());
047: assertNull("descriptor.LongName() not initialized to null",
048: descriptor.getLongName());
049: assertNull("descriptor.Class() not initialized to null",
050: descriptor.getClassFor());
051: }
052:
053: public void testShortName() {
054: assertNull("descriptor.ShortName() not initialized to null",
055: descriptor.getShortName());
056: descriptor.setShortName("foo");
057: assertEquals("descriptor.ShortName()", "foo", descriptor
058: .getShortName());
059: }
060:
061: public void testLongName() {
062: assertNull("descriptor.LongName() not initialized to null",
063: descriptor.getLongName());
064: descriptor.setLongName("bar");
065: assertEquals("descriptor.LongName()", "bar", descriptor
066: .getLongName());
067: }
068:
069: public void testNonExistingClass() {
070: assertNull("descriptor.Class() not initialized to null",
071: descriptor.getClassFor());
072: try {
073: descriptor.getClassForByName("nop such class");
074: fail("set class to non-existing class");
075: } catch (ClassNotFoundException ex) {
076: // Do nothing
077: }
078: }
079:
080: public void testNullClass() {
081: assertNull("descriptor.Class() not initialized to null",
082: descriptor.getClassFor());
083: try {
084: descriptor.setClassFor(null);
085: fail("set class to null");
086: } catch (IllegalArgumentException ex) {
087: // Do nothing
088: }
089: }
090:
091: public void testClass() {
092: assertNull("descriptor.Class() not initialized to null",
093: descriptor.getClassFor());
094: descriptor
095: .setClassFor(com.jeantessier.metrics.CounterMeasurement.class);
096: assertEquals("descriptor.Class()",
097: com.jeantessier.metrics.CounterMeasurement.class,
098: descriptor.getClassFor());
099: }
100:
101: public void testClassByName() throws ClassNotFoundException {
102: descriptor
103: .getClassForByName(com.jeantessier.metrics.CounterMeasurement.class
104: .getName());
105: assertEquals("descriptor.Class()",
106: com.jeantessier.metrics.CounterMeasurement.class,
107: descriptor.getClassFor());
108: }
109: }
|