1 package org.pojomatic.internal;
2
3 import static org.testng.Assert.assertEquals;
4
5 import java.util.List;
6
7 import org.pojomatic.PropertyElement;
8 import org.pojomatic.formatter.EnhancedPojoFormatter;
9 import org.pojomatic.formatter.PojoFormatter;
10 import org.testng.annotations.BeforeClass;
11 import org.testng.annotations.BeforeMethod;
12 import org.testng.annotations.Test;
13
14 @Deprecated
15 public class EnhancedPojoFormatterWrapperTest {
16
17 private static class SimplePojoFormatter implements PojoFormatter {
18 @Override public String getToStringPrefix(Class<?> pojoClass) { return "pre-" + pojoClass.getSimpleName(); }
19 @Override public String getToStringSuffix(Class<?> pojoClass) { return "post-" + pojoClass.getSimpleName(); }
20 @Override public String getPropertyPrefix(PropertyElement property) { return property.getName() + "-pre"; }
21 @Override public String getPropertySuffix(PropertyElement property) { return property.getName() + "-post"; }
22 }
23
24 int sampleField;
25
26 private static EnhancedPojoFormatter wrapper = new EnhancedPojoFormatterWrapper(new SimplePojoFormatter());
27
28 private static PropertyElement property;
29
30 private StringBuilder builder;
31
32 @BeforeClass
33 public static void initProperty() throws ReflectiveOperationException {
34 property = new PropertyField(EnhancedPojoFormatterWrapperTest.class.getDeclaredField("sampleField"), "foo");
35 }
36
37 @BeforeMethod
38 public void initStringBuidler() {
39 builder = new StringBuilder();
40 }
41
42 @Test
43 public void appendPropertyPrefix() {
44 wrapper.appendPropertyPrefix(builder, property);
45 assertEquals(builder.toString(), "foo-pre");
46 }
47
48 @Test
49 public void appendPropertySuffix() {
50 wrapper.appendPropertySuffix(builder, property);
51 assertEquals(builder.toString(), "foo-post");
52 }
53
54 @Test
55 public void appendToStringPrefix() {
56 wrapper.appendToStringPrefix(builder, List.class);
57 assertEquals(builder.toString(), "pre-List");
58 }
59
60 @Test
61 public void appendToStringSuffix() {
62 wrapper.appendToStringSuffix(builder, List.class);
63 assertEquals(builder.toString(), "post-List");
64 }
65
66 @Test
67 public void getPropertyPrefix() {
68 assertEquals(wrapper.getPropertyPrefix(property), "foo-pre");
69 }
70
71 @Test
72 public void getPropertySuffix() {
73 assertEquals(wrapper.getPropertySuffix(property), "foo-post");
74 }
75
76 @Test
77 public void getToStringPrefix() {
78 assertEquals(wrapper.getToStringPrefix(List.class), "pre-List");
79 }
80
81 @Test
82 public void getToStringSuffix() {
83 assertEquals(wrapper.getToStringSuffix(List.class), "post-List");
84 }
85 }