<commit_before>package org.prevayler.baptism;

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

import junit.framework.TestCase;

/**
 * Shows how the baptism problem works. Used in the documentation.
 * 
 * @author <NAME>
 * @since Apr 5, 2004
 */
public class BaptismProblemTest extends TestCase {

    public void testThatSerializationNeverSerializesTheSameObjectAgain()
            throws IOException, ClassNotFoundException {

        // START SNIPPET: ex1

        ByteArrayOutputStream stream = new ByteArrayOutputStream();
        ObjectOutputStream out = new ObjectOutputStream(stream);

        Calendar c = Calendar.getInstance(); // a mutable object

        out.writeObject(c); // object is written to the stream
        out.writeObject(c); // object is already written; this references it
        c.setTimeInMillis(0); // mutate the object's state
        out.writeObject(c); // object, again, is referenced

        // END SNIPPET: ex1

        // START SNIPPET: ex2
        ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(
                stream.toByteArray()));

        Calendar c1 = (Calendar) in.readObject();
        Calendar c2 = (Calendar) in.readObject();
        Calendar c3 = (Calendar) in.readObject();
        // END SNIPPET: ex2

        // START SNIPPET: ex3
        assertEquals(c1, c2);
        assertEquals(c1, c3);
        assertEquals(c2, c3);

        assertFalse(0 == c3.getTimeInMillis());
        // END SNIPPET: ex3
    }
}<commit_msg>*** empty log message ***<commit_after>package org.prevayler.baptism;

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

import junit.framework.TestCase;

/**
 * Shows how the baptism problem works. Used in the documentation.
 * 
 * @author <NAME>
 * @since Apr 5, 2004
 */
public class BaptismProblemTest extends TestCase {

    public void testThatSerializationNeverSerializesTheSameObjectAgain()
            throws IOException, ClassNotFoundException {

        // START SNIPPET: ex1

        ByteArrayOutputStream stream = new ByteArrayOutputStream();
        ObjectOutputStream out = new ObjectOutputStream(stream);

        Calendar c = Calendar.getInstance(); // a mutable object

        out.writeObject(c); // object is written to the stream
        out.writeObject(c); // object is already written; this references it
        c.setTimeInMillis(0); // mutate the object's state
        out.writeObject(c); // object, again, is referenced

        // END SNIPPET: ex1

        // START SNIPPET: ex2
        ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(
                stream.toByteArray()));

        Calendar c1 = (Calendar) in.readObject();
        Calendar c2 = (Calendar) in.readObject();
        Calendar c3 = (Calendar) in.readObject();
        // END SNIPPET: ex2

        // START SNIPPET: ex3
        assertSame(c1, c2);
        assertSame(c2, c3);
        
        assertFalse(c.equals(c1));
        assertFalse(c.equals(c2));
        assertFalse(c.equals(c3));
        
        assertFalse(0 == c3.getTimeInMillis());
        // END SNIPPET: ex3
    }
}
{'fraction_non_alphanumeric': 0.10070671378091872, 'fraction_numerical': 0.013839811542991754, 'mean_word_length': 2.7744444444444443, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6612025', 'n_tokens_mistral': 982, 'n_tokens_neox': 917, 'n_words': 257}