1 package com.atlassian.scheduler.util;
2
3 import com.google.common.collect.ImmutableMap;
4 import org.junit.Test;
5
6 import java.io.Serializable;
7 import java.util.Date;
8 import java.util.Map;
9
10 import static com.atlassian.scheduler.util.Safe.copy;
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertNotSame;
13 import static org.junit.Assert.assertNull;
14 import static org.junit.Assert.assertSame;
15 import static org.junit.Assert.assertTrue;
16
17
18
19
20 public class SafeTest {
21 @Test
22 public void testCopyDateNull() {
23 assertNull(copy((Date) null));
24 }
25
26 @Test
27 public void testCopyDate() {
28 final Date now = new Date();
29 final Date copy = copy(now);
30 assertEquals(now, copy);
31 assertNotSame(now, copy);
32 }
33
34 @Test
35 public void testCopyMapNull() {
36 final Map<String, Serializable> map = copy((Map<String, Serializable>) null);
37 assertTrue("Should be an ImmutableMap", map instanceof ImmutableMap);
38 }
39
40 @Test
41 public void testCopyMapKnownImmutable() {
42 final ImmutableMap<String, Serializable> map = ImmutableMap.<String, Serializable>builder()
43 .put("Hello", 42L)
44 .put("World", true)
45 .build();
46 assertSame(map, copy(map));
47 }
48 }