KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > compliance > metadata > MBeanFeatureInfoTEST


1 /*
2  * JBoss, the OpenSource J2EE webOS
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7
8 package test.compliance.metadata;
9
10
11 import junit.framework.TestCase;
12 import junit.framework.AssertionFailedError;
13
14 import javax.management.MBeanFeatureInfo;
15
16 /**
17  * Tests MBeanFeatureInfo.
18  *
19  * @author <a HREF="mailto:juha@jboss.org">Juha Lindfors</a>.
20  * @version $Revision: 1.4 $
21  */

22 public class MBeanFeatureInfoTEST extends TestCase
23 {
24    public MBeanFeatureInfoTEST(String s)
25    {
26       super(s);
27    }
28
29    /**
30     * Tests <tt>MBeanOperationInfo(String descr, Method m)</tt> constructor.
31     */

32    public void testConstructor()
33    {
34       try
35       {
36          MBeanFeatureInfo info = new MBeanFeatureInfo("Name", "This is a description.");
37          
38          assertTrue(info.getName().equals("Name"));
39          assertTrue(info.getDescription().equals("This is a description."));
40       }
41       catch (AssertionFailedError e)
42       {
43          throw e;
44       }
45       catch (Throwable t)
46       {
47          t.printStackTrace();
48          fail("Unexpected error: " + t.toString());
49       }
50    }
51
52    public void testHashCode()
53       throws Exception
54    {
55       MBeanFeatureInfo info1 = new MBeanFeatureInfo("name", "description");
56       MBeanFeatureInfo info2 = new MBeanFeatureInfo("name", "description");
57
58       assertTrue("Different instances with the same hashcode are equal", info1.hashCode() == info2.hashCode());
59    }
60
61    public void testEquals()
62       throws Exception
63    {
64       MBeanFeatureInfo info = new MBeanFeatureInfo("name", "description");
65
66       assertTrue("Null should not be equal", info.equals(null) == false);
67       assertTrue("Only MBeanFeatureInfo should be equal", info.equals(new Object()) == false);
68
69       MBeanFeatureInfo info2 = new MBeanFeatureInfo("name", "description");
70
71       assertTrue("Different instances of the same data are equal", info.equals(info2));
72       assertTrue("Different instances of the same data are equal", info2.equals(info));
73
74       info2 = new MBeanFeatureInfo("name2", "description");
75
76       assertTrue("Different instances with different names are not equal", info.equals(info2) == false);
77       assertTrue("Different instances with different names are not equal", info2.equals(info) == false);
78
79       info2 = new MBeanFeatureInfo("name", "description2");
80
81       assertTrue("Different instances with different descriptions are not equal", info.equals(info2) == false);
82       assertTrue("Different instances with different descritpions are not equal", info2.equals(info) == false);
83    }
84 }
85
Popular Tags