0

Earlier, I had a java class:

public enum Currency
{
   PENNY,
   NICKLE,
   DIME,
   QUARTER;
}

Now I have made changes in the class and it looks like this:

 public enum Currency
    {
        PENNY("Penny"),
        NICKLE("Nickle"),
        DIME("Dime"),
        QUARTER("Quarter");

    /**
     * Instantiates a new currency.
     * 
     * @param currencyType the currency type
     */
    Currency(String currencyType)
    {
        this.value = currencyType;
    }

    String value;

    /**
     * Gets the value
     *
     */
    public String getValue()
    {
        return this.value;
    }
}

I want to check if the Currency class object is getting serialized and deserialized properly. How should I check this through unit testing in java ? I'm using DynamoDB to store the values of Currency. Currently they are being stored as Enum constants. Now when I have customized the enum's and added the value field. As far as I understood, serialization and deserialization is necessary when data transfer takes place through network. Please correct me here if I'm wrong. Also I'm using this value field to write to excel file using Apache POI. My question is the serialization and deseralization check necessary here for the custom enum class here ?

sheenaLal
  • 3
  • 1
  • 7
  • Check [this](http://stackoverflow.com/questions/3840356/how-to-test-in-java-that-a-class-implements-serializable-correctly-not-just-is) already answered question. – Jay Apr 01 '16 at 06:02
  • @Jay Thanks for the link.I have a doubt in the link. When unit-testing what should I put in assertEquals(deserializedObj, ). The deserializedObj has been obtained using ObjectInputStream and readObject. I don't understand what should I put instead of ? – sheenaLal Apr 01 '16 at 06:23
  • An object that contains the data you expect the deserialized object to contain, of course. It's a test. – user207421 Apr 01 '16 at 06:50
  • @EJP I'm using DynamoDB to store the values of Currency. Currently they are being stored as Enum constants. Now when I have customized the enum's and added the value field. As far as I understood, serialization and deserialization is necessary when data transfer takes place through network. Please correct me here if I'm wrong. My question to you is the serialization and deseralization check necessary here for the custom enum class here ? – sheenaLal Apr 01 '16 at 07:15

0 Answers0