package org.goldonship.designpattern.creational.prototype;

import org.junit.Test;

import java.util.Date;

import static junit.framework.TestCase.assertEquals;
import static junit.framework.TestCase.assertNotSame;

/**
 * * Created by Goldonship on 2017/10/29.
 **/
public class CloneTest {
    @Test
    public void testShallowCopy() throws CloneNotSupportedException {
        Date date = new Date(1241314415234L);
        ShallowCopy shallow = new ShallowCopy("bruce", date);
        ShallowCopy cloneShallow = (ShallowCopy) shallow.clone();
        date.setTime(2124124124L);
        assertEquals(shallow, cloneShallow);
    }

    @Test
    public void testDeepCopy() throws CloneNotSupportedException {
        Date date = new Date(1241314415234L);
        DeepCopy deep = new DeepCopy("bruce", date);
        DeepCopy clone = (DeepCopy) deep.clone();
        date.setTime(2124124124L);
        assertNotSame(deep, clone);
    }
}