1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package test.de.smartics.properties.api.core.domain;
17
18 import static org.hamcrest.MatcherAssert.assertThat;
19 import static org.hamcrest.Matchers.equalTo;
20 import static org.hamcrest.Matchers.is;
21 import static org.mockito.Mockito.mock;
22 import static org.mockito.Mockito.when;
23
24 import java.util.ArrayList;
25 import java.util.List;
26
27 import org.apache.commons.lang.ObjectUtils;
28 import org.junit.Test;
29
30 import de.smartics.properties.api.core.domain.PropertyConstraint;
31 import de.smartics.properties.api.core.domain.PropertyDescriptor;
32 import de.smartics.properties.api.core.domain.PropertyKey;
33 import de.smartics.properties.api.core.domain.PropertyValidationException;
34 import de.smartics.properties.api.core.domain.PropertyValidationMessageBean;
35 import de.smartics.testdoc.annotations.Uut;
36
37
38
39
40 @Uut(type = PropertyValidationException.class)
41 public class PropertyValidationExceptionTest
42 {
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59 @Test
60 public void allowsToAddSerializableValue()
61 {
62 final Throwable cause = new NullPointerException("Test");
63 final PropertyKey key = new PropertyKey("key");
64 final PropertyDescriptor descriptor = mock(PropertyDescriptor.class);
65 when(descriptor.getKey()).thenReturn(key);
66
67 final List<? extends PropertyConstraint<?>> constraints =
68 new ArrayList<PropertyConstraint<?>>();
69 final String value = "test";
70 final PropertyValidationException uut =
71 new PropertyValidationException(new PropertyValidationMessageBean(
72 cause, descriptor, constraints, value));
73
74 final PropertyValidationMessageBean message = uut.getMessageBean();
75 assertThat((String) message.getValue(), is(equalTo(value)));
76 assertThat(message.getPropertyKey(), is(equalTo(key)));
77 assertThat(message.getCause(), is(equalTo(cause)));
78 assertThat(ObjectUtils.equals(message.getConstraints(), constraints),
79 is(equalTo(true)));
80 }
81
82 @Test
83 public void allowsToAddNonSerializableValueStoredInStringRepresentation()
84 {
85 final String stringRepresentation = "TEST";
86 final PropertyKey key = new PropertyKey("key");
87 final PropertyDescriptor descriptor = mock(PropertyDescriptor.class);
88 when(descriptor.getKey()).thenReturn(key);
89 final Object value = new Object()
90 {
91 @Override
92 public String toString()
93 {
94 return stringRepresentation;
95 }
96 };
97
98 final PropertyValidationException uut =
99 new PropertyValidationException(new PropertyValidationMessageBean(
100 descriptor, null, value));
101
102 final PropertyValidationMessageBean message = uut.getMessageBean();
103 assertThat((String) message.getValue(), is(equalTo(stringRepresentation)));
104 }
105 }