package net.time4j.calendar.bahai;

import net.time4j.calendar.frenchrev.FrenchRepublicanCalendar;
import net.time4j.calendar.frenchrev.Sansculottides;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;


@RunWith(JUnit4.class)
public class SerializationTest {

    @Test
    public void serializeNormal() throws IOException, ClassNotFoundException {
        roundtrip(BadiCalendar.ofComplete(3, 19, 19, BadiMonth.valueOf(19), 19));
    }

    @Test
    public void serializeAyyamIHa() throws IOException, ClassNotFoundException {
        roundtrip(BadiCalendar.ofIntercalary(19, 19, 4));
    }

    private static void roundtrip(Object obj)
        throws IOException, ClassNotFoundException {

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        ObjectOutputStream oos = new ObjectOutputStream(baos);
        oos.writeObject(obj);
        byte[] data = baos.toByteArray();
        oos.close();
        ByteArrayInputStream bais = new ByteArrayInputStream(data);
        ObjectInputStream ois = new ObjectInputStream(bais);
        assertThat(ois.readObject(), is(obj));
        ois.close();
    }

}
package net.time4j.calendar.bahai;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;


@RunWith(JUnit4.class)
public class SerializationTest {

    @Test
    public void serializeNormal() throws IOException, ClassNotFoundException {
        roundtrip(BadiCalendar.ofComplete(3, 19, 19, BadiMonth.valueOf(19), 19));
    }

    @Test
    public void serializeAyyamIHa() throws IOException, ClassNotFoundException {
        roundtrip(BadiCalendar.ofIntercalary(19, 19, 4));
    }

    private static void roundtrip(Object obj)
        throws IOException, ClassNotFoundException {

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        ObjectOutputStream oos = new ObjectOutputStream(baos);
        oos.writeObject(obj);
        byte[] data = baos.toByteArray();
        oos.close();
        ByteArrayInputStream bais = new ByteArrayInputStream(data);
        ObjectInputStream ois = new ObjectInputStream(bais);
        assertThat(ois.readObject(), is(obj));
        ois.close();
    }

}
remove unused imports