1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.grouplens.grapht.reflect.internal;
21
22 import org.apache.commons.lang3.SerializationUtils;
23 import org.junit.Test;
24
25 import javax.annotation.Nullable;
26 import java.io.IOException;
27
28 import static org.hamcrest.Matchers.*;
29 import static org.junit.Assert.assertThat;
30
31 public class FieldInjectionPointTest {
32
33 String foo;
34 @Nullable
35 String nullable;
36
37 @Test
38 public void testNotNullable() throws NoSuchFieldException {
39 FieldInjectionPoint nonnull = new FieldInjectionPoint(getClass().getDeclaredField("foo"));
40 assertThat(nonnull.isNullable(), equalTo(false));
41 }
42
43 @Test
44 public void testNullable() throws NoSuchFieldException {
45 FieldInjectionPoint field = new FieldInjectionPoint(getClass().getDeclaredField("nullable"));
46 assertThat(field.isNullable(), equalTo(true));
47 }
48
49 @Test
50 public void testSerialize() throws NoSuchFieldException, IOException, ClassNotFoundException {
51 FieldInjectionPoint fip = new FieldInjectionPoint(getClass().getDeclaredField("foo"));
52 FieldInjectionPoint fip2 = SerializationUtils.clone(fip);
53 assertThat(fip2, equalTo(fip));
54 assertThat(fip2, not(sameInstance(fip)));
55 }
56 }