001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package test.compliance.metadata;
023:
024: import junit.framework.TestCase;
025: import junit.framework.AssertionFailedError;
026:
027: import javax.management.MBeanFeatureInfo;
028:
029: /**
030: * Tests MBeanFeatureInfo.
031: *
032: * @author <a href="mailto:juha@jboss.org">Juha Lindfors</a>.
033: * @version $Revision: 57200 $
034: */
035: public class MBeanFeatureInfoTEST extends TestCase {
036: public MBeanFeatureInfoTEST(String s) {
037: super (s);
038: }
039:
040: /**
041: * Tests <tt>MBeanOperationInfo(String descr, Method m)</tt> constructor.
042: */
043: public void testConstructor() {
044: try {
045: MBeanFeatureInfo info = new MBeanFeatureInfo("Name",
046: "This is a description.");
047:
048: assertTrue(info.getName().equals("Name"));
049: assertTrue(info.getDescription().equals(
050: "This is a description."));
051: } catch (AssertionFailedError e) {
052: throw e;
053: } catch (Throwable t) {
054: t.printStackTrace();
055: fail("Unexpected error: " + t.toString());
056: }
057: }
058:
059: public void testHashCode() throws Exception {
060: MBeanFeatureInfo info1 = new MBeanFeatureInfo("name",
061: "description");
062: MBeanFeatureInfo info2 = new MBeanFeatureInfo("name",
063: "description");
064:
065: assertTrue(
066: "Different instances with the same hashcode are equal",
067: info1.hashCode() == info2.hashCode());
068: }
069:
070: public void testEquals() throws Exception {
071: MBeanFeatureInfo info = new MBeanFeatureInfo("name",
072: "description");
073:
074: assertTrue("Null should not be equal",
075: info.equals(null) == false);
076: assertTrue("Only MBeanFeatureInfo should be equal", info
077: .equals(new Object()) == false);
078:
079: MBeanFeatureInfo info2 = new MBeanFeatureInfo("name",
080: "description");
081:
082: assertTrue("Different instances of the same data are equal",
083: info.equals(info2));
084: assertTrue("Different instances of the same data are equal",
085: info2.equals(info));
086:
087: info2 = new MBeanFeatureInfo("name2", "description");
088:
089: assertTrue(
090: "Different instances with different names are not equal",
091: info.equals(info2) == false);
092: assertTrue(
093: "Different instances with different names are not equal",
094: info2.equals(info) == false);
095:
096: info2 = new MBeanFeatureInfo("name", "description2");
097:
098: assertTrue(
099: "Different instances with different descriptions are not equal",
100: info.equals(info2) == false);
101: assertTrue(
102: "Different instances with different descritpions are not equal",
103: info2.equals(info) == false);
104: }
105: }
|