### Question:
DeepCopy { public static Object copy(Object orig) { Object copy = null; try { ByteArrayOutputStream bos = new ByteArrayOutputStream(); ObjectOutputStream out = new ObjectOutputStream(bos); out.writeObject(orig); out.flush(); out.close(); ObjectInputStream in = new ObjectInputStream( new ByteArrayInputStream(bos.toByteArray())); copy = in.readObject(); in.close(); } catch (IOException e) { e.printStackTrace(); } catch (ClassNotFoundException cnfe) { cnfe.printStackTrace(); } return copy; }  static Object copy(Object orig);  }### Answer:
@Test public void shouldMakeACopyWhenOneLevelDeep() { Integer original = 1; Integer copy = (Integer) DeepCopy.copy(original); Assert.assertNotSame(copy, original); }
@Test public void shouldMakeACopyWhenTwoLevelsDeep() { Integer original = 1; List<Integer> originalList = new ArrayList<Integer>(); originalList.add(original); List<Integer> copyList = (List<Integer>) DeepCopy.copy(originalList); Assert.assertNotSame(copyList, originalList); Assert.assertNotSame(copyList.get(0), original); }