mx4j/src/test/test/javax/management/openmbean TabularTypeTest.java,1.6,1.7

Simone Bordet <[email protected]> Sun, 10 Oct 2004 16:39:44 +0000
Newsgroups gmane.comp.java.mx4j.cvs
Message-ID <[email protected]>
Update of /cvsroot/mx4j/mx4j/src/test/test/javax/management/openmbean
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25772/src/test/test/javax/management/openmbean

Modified Files:
	TabularTypeTest.java 
Log Message:
Fixed implementation of hashCode() following the spec, and cleaned up the test case

Index: TabularTypeTest.java
===================================================================
RCS file: /cvsroot/mx4j/mx4j/src/test/test/javax/management/openmbean/TabularTypeTest.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** TabularTypeTest.java	4 Sep 2004 15:44:22 -0000	1.6
--- TabularTypeTest.java	10 Oct 2004 16:39:41 -0000	1.7
***************
*** 18,22 ****
  import javax.management.openmbean.TabularType;
  
! import junit.framework.TestCase;
  
  /**
--- 18,22 ----
  import javax.management.openmbean.TabularType;
  
! import test.MX4JTestCase;
  
  /**
***************
*** 24,28 ****
   * @version $Revision$
   */
! public class TabularTypeTest extends TestCase
  {
     private String[] itemNames = null;
--- 24,28 ----
   * @version $Revision$
   */
! public class TabularTypeTest extends MX4JTestCase
  {
     private String[] itemNames = null;
***************
*** 41,45 ****
     protected void setUp() throws Exception
     {
-       super.setUp();
        itemNames = new String[]{"model", "color", "size", "price"};
        itemDescriptions = new String[]{"TShirt's model name", "TShirt's color", "TShirt's size", "TShirt's price"};
--- 41,44 ----
***************
*** 64,110 ****
     }
  
!    protected void tearDown() throws Exception
!    {
!       super.tearDown();
!    }
! 
!    public void testEquals()
     {
!       try
!       {
!          String[] itemNames2 = {"model", "color", "size", "price"};
!          String[] itemDescriptions2 = {"Manufacturer's model name", "The shirt's color", "How big is it", "How much does it cost"};
!          OpenType[] itemTypes2 = {SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.FLOAT};
!          String[] indexNames2 = {"model", "color", "size"};
!          CompositeType tShirtType2 = new CompositeType("tShirt", "a TShirt", itemNames, itemDescriptions, itemTypes);
!          TabularType allTShirtTypes2 = new TabularType("tShirts", "List of available TShirts", tShirtType, indexNames);
!          assertTrue(allTShirtTypes.equals(allTShirtTypes2));
!          // assert reverse
!          assertTrue(allTShirtTypes2.equals(allTShirtTypes));
!       }
!       catch (OpenDataException e)
!       {
!          e.printStackTrace();
!       }
     }
  
!    public void testNotEqual()
     {
! 
!       try
!       {
!          String[] itemNames3 = {"model3", "color3", "size3", "price3"};
!          String[] itemDescriptions3 = {"TShirt's model name", "TShirt's color", "TShirt's size", "TShirt's price"};
!          OpenType[] itemTypes3 = {SimpleType.STRING, SimpleType.BOOLEAN, SimpleType.STRING, SimpleType.FLOAT};
!          String[] indexNames3 = {"model4", "color", "size"};
!          CompositeType tShirtType3 = new CompositeType("tShirt3", "a TShirt", itemNames, itemDescriptions, itemTypes);
!          TabularType allTShirtTypes3 = new TabularType("tShirts3", "List of available TShirts", tShirtType, indexNames);
! 
!          assertTrue(!(allTShirtTypes.equals(allTShirtTypes3)));
!       }
!       catch (OpenDataException e)
!       {
!          e.printStackTrace();
!       }
     }
  
--- 63,88 ----
     }
  
!    public void testEquals() throws Exception
     {
!       String[] itemNames2 = {"model", "color", "size", "price"};
!       String[] itemDescriptions2 = {"Manufacturer's model name", "The shirt's color", "How big is it", "How much does it cost"};
!       OpenType[] itemTypes2 = {SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.FLOAT};
!       String[] indexNames2 = {"model", "color", "size"};
!       CompositeType tShirtType2 = new CompositeType("tShirt", "a TShirt", itemNames2, itemDescriptions2, itemTypes2);
!       TabularType allTShirtTypes2 = new TabularType("tShirts", "List of available TShirts", tShirtType2, indexNames2);
!       assertTrue(allTShirtTypes.equals(allTShirtTypes2));
!       // assert reverse
!       assertTrue(allTShirtTypes2.equals(allTShirtTypes));
     }
  
!    public void testNotEqual() throws Exception
     {
!       String[] itemNames3 = {"model3", "color3", "size3", "price3"};
!       String[] itemDescriptions3 = {"TShirt's model name", "TShirt's color", "TShirt's size", "TShirt's price"};
!       OpenType[] itemTypes3 = {SimpleType.STRING, SimpleType.BOOLEAN, SimpleType.STRING, SimpleType.FLOAT};
!       String[] indexNames3 = {"model3", "color3", "size3"};
!       CompositeType tShirtType3 = new CompositeType("tShirt3", "a TShirt", itemNames3, itemDescriptions3, itemTypes3);
!       TabularType allTShirtTypes3 = new TabularType("tShirts3", "List of available TShirts", tShirtType3, indexNames3);
!       assertFalse(allTShirtTypes.equals(allTShirtTypes3));
     }
  
***************
*** 112,116 ****
     {
        CompositeType test = allTShirtTypes.getRowType();
- 
        assertEquals(test, tShirtType);
     }
--- 90,93 ----
***************
*** 129,167 ****
     }
  
!    public void testHashCode()
     {
!       try
!       {
!          String[] itemNames2 = {"model", "color", "size", "price"};
!          String[] itemDescriptions2 = {"Manufacturer's model name", "The shirt's color", "How big is it", "How much does it cost"};
!          OpenType[] itemTypes2 = {SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.FLOAT};
!          String[] indexNames2 = {"model", "color", "size"};
!          CompositeType tShirtType2 = new CompositeType("tShirt", "a TShirt", itemNames, itemDescriptions, itemTypes);
!          TabularType allTShirtTypes2 = new TabularType("tShirts", "List of available TShirts", tShirtType2, indexNames);
! 
!          String[] itemNames3 = {"model3", "color3", "size3", "price3"};
!          String[] itemDescriptions3 = {"TShirt's model name", "TShirt's color", "TShirt's size", "TShirt's price"};
!          OpenType[] itemTypes3 = {SimpleType.STRING, SimpleType.BOOLEAN, SimpleType.STRING, SimpleType.FLOAT};
!          String[] indexNames3 = {"model4", "color", "size"};
!          CompositeType tShirtType3 = new CompositeType("tShirt3", "a TShirt", itemNames, itemDescriptions, itemTypes);
!          TabularType allTShirtTypes3 = new TabularType("tShirts3", "List of available TShirts", tShirtType3, indexNames);
  
!          int code1 = allTShirtTypes.hashCode();
!          int code2 = allTShirtTypes2.hashCode();
!          assertEquals(code2, "tShirts".hashCode() + tShirtType2.hashCode() + (new HashSet(Arrays.asList(indexNames))).hashCode());
!          int code3 = allTShirtTypes3.hashCode();
  
!          assertEquals(code1, code2);
!          assertTrue(code1 != code3);
!       }
!       catch (OpenDataException e)
!       {
!          e.printStackTrace();
!       }
!    }
  
!    public void testReadObject()
!    {
!       ////// TODO ////////
     }
  
--- 106,132 ----
     }
  
!    public void testHashCode() throws Exception
     {
!       String[] itemNames2 = {"model", "color", "size", "price"};
!       String[] itemDescriptions2 = {"Manufacturer's model name", "The shirt's color", "How big is it", "How much does it cost"};
!       OpenType[] itemTypes2 = {SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.FLOAT};
!       String[] indexNames2 = {"model", "color", "size"};
!       CompositeType tShirtType2 = new CompositeType("tShirt", "a TShirt", itemNames2, itemDescriptions2, itemTypes2);
!       TabularType allTShirtTypes2 = new TabularType("tShirts", "List of available TShirts", tShirtType2, indexNames2);
  
!       String[] itemNames3 = {"model3", "color3", "size3", "price3"};
!       String[] itemDescriptions3 = {"TShirt's model name", "TShirt's color", "TShirt's size", "TShirt's price"};
!       OpenType[] itemTypes3 = {SimpleType.STRING, SimpleType.BOOLEAN, SimpleType.STRING, SimpleType.FLOAT};
!       String[] indexNames3 = {"model3", "color3", "size3"};
!       CompositeType tShirtType3 = new CompositeType("tShirt3", "a TShirt", itemNames3, itemDescriptions3, itemTypes3);
!       TabularType allTShirtTypes3 = new TabularType("tShirts3", "List of available TShirts", tShirtType3, indexNames3);
  
!       int code1 = allTShirtTypes.hashCode();
!       int code2 = allTShirtTypes2.hashCode();
!       assertEquals(code2, "tShirts".hashCode() + tShirtType2.hashCode() + (new HashSet(Arrays.asList(indexNames))).hashCode());
!       int code3 = allTShirtTypes3.hashCode();
  
!       assertEquals(code1, code2);
!       assertTrue(code1 != code3);
     }
  
***************
*** 188,201 ****
        try
        {
!          TabularType winecatalog =
!                  new TabularType(null,
!                                  "Catalog of available wines",
!                                  wine,
!                                  new String[]{"Winery", "Vintage"});
           fail("Expecting IllegalArgumentException");
        }
        catch (IllegalArgumentException x)
        {
-          assertTrue(true);
        }
     }
--- 153,164 ----
        try
        {
!          new TabularType(null,
!                          "Catalog of available wines",
!                          wine,
!                          new String[]{"Winery", "Vintage"});
           fail("Expecting IllegalArgumentException");
        }
        catch (IllegalArgumentException x)
        {
        }
     }
***************
*** 205,218 ****
        try
        {
!          TabularType winecatalog =
!                  new TabularType("",
!                                  "Catalog of available wines",
!                                  wine,
!                                  new String[]{"Winery", "Vintage"});
           fail("Expecting IllegalArgumentException");
        }
        catch (IllegalArgumentException x)
        {
-          assertTrue(true);
        }
     }
--- 168,179 ----
        try
        {
!          new TabularType("",
!                          "Catalog of available wines",
!                          wine,
!                          new String[]{"Winery", "Vintage"});
           fail("Expecting IllegalArgumentException");
        }
        catch (IllegalArgumentException x)
        {
        }
     }
***************
*** 222,235 ****
        try
        {
!          TabularType winecatalog =
!                  new TabularType("Wine Catalog",
!                                  null,
!                                  wine,
!                                  new String[]{"Winery", "Vintage"});
           fail("Expecting IllegalArgumentException");
        }
        catch (IllegalArgumentException x)
        {
-          assertTrue(true);
        }
     }
--- 183,194 ----
        try
        {
!          new TabularType("Wine Catalog",
!                          null,
!                          wine,
!                          new String[]{"Winery", "Vintage"});
           fail("Expecting IllegalArgumentException");
        }
        catch (IllegalArgumentException x)
        {
        }
     }
***************
*** 239,252 ****
        try
        {
!          TabularType winecatalog =
!                  new TabularType("Wine Catalog",
!                                  "",
!                                  wine,
!                                  new String[]{"Winery", "Vintage"});
           fail("Expecting IllegalArgumentException");
        }
        catch (IllegalArgumentException x)
        {
-          assertTrue(true);
        }
     }
--- 198,209 ----
        try
        {
!          new TabularType("Wine Catalog",
!                          "",
!                          wine,
!                          new String[]{"Winery", "Vintage"});
           fail("Expecting IllegalArgumentException");
        }
        catch (IllegalArgumentException x)
        {
        }
     }
***************
*** 256,269 ****
        try
        {
!          TabularType winecatalog =
!                  new TabularType("Wine Catalog",
!                                  "Catalog of available wines",
!                                  null,
!                                  new String[]{"Winery", "Vintage"});
           fail("Expecting IllegalArgumentException");
        }
        catch (IllegalArgumentException x)
        {
-          assertTrue(true);
        }
     }
--- 213,224 ----
        try
        {
!          new TabularType("Wine Catalog",
!                          "Catalog of available wines",
!                          null,
!                          new String[]{"Winery", "Vintage"});
           fail("Expecting IllegalArgumentException");
        }
        catch (IllegalArgumentException x)
        {
        }
     }
***************
*** 273,286 ****
        try
        {
!          TabularType winecatalog =
!                  new TabularType("Wine Catalog",
!                                  "Catalog of available wines",
!                                  wine,
!                                  null);
           fail("Expecting IllegalArgumentException");
        }
        catch (IllegalArgumentException x)
        {
-          assertTrue(true);
        }
     }
--- 228,239 ----
        try
        {
!          new TabularType("Wine Catalog",
!                          "Catalog of available wines",
!                          wine,
!                          null);
           fail("Expecting IllegalArgumentException");
        }
        catch (IllegalArgumentException x)
        {
        }
     }
***************
*** 290,303 ****
        try
        {
!          TabularType winecatalog =
!                  new TabularType("Wine Catalog",
!                                  "Catalog of available wines",
!                                  wine,
!                                  new String[0]);
           fail("Expecting IllegalArgumentException");
        }
        catch (IllegalArgumentException x)
        {
-          assertTrue(true);
        }
     }
--- 243,254 ----
        try
        {
!          new TabularType("Wine Catalog",
!                          "Catalog of available wines",
!                          wine,
!                          new String[0]);
           fail("Expecting IllegalArgumentException");
        }
        catch (IllegalArgumentException x)
        {
        }
     }
***************
*** 307,320 ****
        try
        {
!          TabularType winecatalog =
!                  new TabularType("Wine Catalog",
!                                  "Catalog of available wines",
!                                  wine,
!                                  new String[]{"Region", "Vintage"});
           fail("Expecting OpenDataException");
        }
        catch (OpenDataException x)
        {
-          assertTrue(true);
        }
     }
--- 258,269 ----
        try
        {
!          new TabularType("Wine Catalog",
!                          "Catalog of available wines",
!                          wine,
!                          new String[]{"Region", "Vintage"});
           fail("Expecting OpenDataException");
        }
        catch (OpenDataException x)
        {
        }
     }



-------------------------------------------------------
This SF.net email is sponsored by: IT Product Guide on ITManagersJournal
Use IT products in your business? Tell us what you think of them. Give us
Your Opinions, Get Free ThinkGeek Gift Certificates! Click to find out more
http://productguide.itmanagersjournal.com/guidepromo.tmpl