avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From blorit...@apache.org
Subject cvs commit: avalon-sandbox/merlin/meta-spi/src/test/org/apache/avalon/meta/model/test CategoryTestCase.java
Date Tue, 08 Jul 2003 19:53:46 GMT
bloritsch    2003/07/08 12:53:46

  Modified:    merlin/meta-spi/src/java/org/apache/avalon/meta/model
                        Category.java
               merlin/meta-spi/src/test/org/apache/avalon/meta/model/test
                        CategoryTestCase.java
  Log:
  Only way to test if the serialization truly worked.
  
  Revision  Changes    Path
  1.4       +27 -1     avalon-sandbox/merlin/meta-spi/src/java/org/apache/avalon/meta/model/Category.java
  
  Index: Category.java
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/merlin/meta-spi/src/java/org/apache/avalon/meta/model/Category.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- Category.java	8 Jul 2003 19:01:48 -0000	1.3
  +++ Category.java	8 Jul 2003 19:53:46 -0000	1.4
  @@ -196,4 +196,30 @@
       {
           return m_target;
       }
  +
  +    public boolean equals(Object other)
  +    {
  +        boolean isEqual = other instanceof Category;
  +
  +        if ( isEqual )
  +        {
  +            Category test = (Category) other;
  +            isEqual = m_name.equals(test.m_name);
  +            if (isEqual) isEqual = m_priority.equals(test.m_priority);
  +            if (isEqual) isEqual = m_target.equals(test.m_target);
  +        }
  +
  +        return isEqual;
  +    }
  +
  +    public int hashCode()
  +    {
  +        int hash = m_name.hashCode();
  +        hash >>>= 13;
  +        hash ^= m_priority.hashCode();
  +        hash >>>= 5;
  +        hash ^= m_target.hashCode();
  +
  +        return hash;
  +    }
   }
  
  
  
  1.2       +28 -0     avalon-sandbox/merlin/meta-spi/src/test/org/apache/avalon/meta/model/test/CategoryTestCase.java
  
  Index: CategoryTestCase.java
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/merlin/meta-spi/src/test/org/apache/avalon/meta/model/test/CategoryTestCase.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- CategoryTestCase.java	8 Jul 2003 19:01:48 -0000	1.1
  +++ CategoryTestCase.java	8 Jul 2003 19:53:46 -0000	1.2
  @@ -52,6 +52,8 @@
   import junit.framework.TestCase;
   import org.apache.avalon.meta.model.Category;
   
  +import java.io.*;
  +
   /**
    * CategoryTestCase does XYZ
    *
  @@ -112,5 +114,31 @@
           assertEquals( name, cat.getName() );
           assertEquals( priority, cat.getPriority() );
           assertEquals( target, cat.getTarget() );
  +    }
  +
  +    public void testSerialization() throws IOException, ClassNotFoundException
  +    {
  +        File file = new File("name.test");
  +        String name = "name";
  +        String priority = Category.WARN;
  +        String target = "test";
  +        Category original = new Category( name, priority, target );
  +
  +        testCategory( original, name, priority, target );
  +
  +        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(file));
  +        oos.writeObject(original);
  +        oos.close();
  +
  +        ObjectInputStream ois = new ObjectInputStream( new FileInputStream(file));
  +        Category serialized = (Category)ois.readObject();
  +        ois.close();
  +
  +        file.delete();
  +
  +        testCategory( serialized, name, priority, target );
  +
  +        assertEquals( original, serialized );
  +        assertEquals( original.hashCode(), serialized.hashCode() );
       }
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: cvs-unsubscribe@avalon.apache.org
For additional commands, e-mail: cvs-help@avalon.apache.org


Mime
View raw message