View Javadoc
1   package org.pojomatic.formatter;
2   
3   import static org.testng.Assert.*;
4   
5   import java.lang.reflect.Field;
6   import java.lang.reflect.Method;
7   
8   import org.mockito.Mockito;
9   import org.pojomatic.internal.ArrayType;
10  import org.pojomatic.internal.EnhancedPropertyFormatterWrapper;
11  import org.pojomatic.internal.Type;
12  import org.pojomatic.internal.TypeProviders;
13  import org.testng.annotations.Test;
14  
15  @Deprecated
16  public class EnhancedPropertyFormatterTest {
17  
18    // for testInitialize
19    int x;
20  
21    @Test
22    public void testInitialize() throws Exception {
23      PropertyFormatter mock = Mockito.mock(PropertyFormatter.class);
24      Field field = getClass().getDeclaredField("x");
25      new EnhancedPropertyFormatterWrapper(mock).initialize(field);
26      Mockito.verify(mock).initialize(field);
27    }
28  
29    @Test(dataProvider="types", dataProviderClass=TypeProviders.class)
30    public void testAppend(Type type) throws ReflectiveOperationException {
31      EnhancedPropertyFormatter wrapper = new EnhancedPropertyFormatterWrapper(new DefaultPropertyFormatter());
32      Method m = EnhancedPropertyFormatter.class.getDeclaredMethod("appendFormatted", StringBuilder.class, type.getClazz());
33      for (Object value: type.getSampleValues()) {
34        StringBuilder builder = new StringBuilder();
35        m.invoke(wrapper, builder, value);
36        assertEquals(builder.toString(), new DefaultPropertyFormatter().format(value));
37      }
38    }
39  
40    @Test(dataProvider="types", dataProviderClass=TypeProviders.class)
41    public void testAppendArraysAsObject(Type type) throws ReflectiveOperationException {
42      Type arrayType = new ArrayType(type);
43      EnhancedPropertyFormatter wrapper = new EnhancedPropertyFormatterWrapper(new DefaultPropertyFormatter());
44      Method m = EnhancedPropertyFormatter.class.getDeclaredMethod("appendFormatted", StringBuilder.class, Object.class);
45      for (Object value: arrayType.getSampleValues()) {
46        StringBuilder builder = new StringBuilder();
47        m.invoke(wrapper, builder, value);
48        assertEquals(builder.toString(), new DefaultPropertyFormatter().format(value));
49      }
50    }
51  
52    @Test(dataProvider="types", dataProviderClass=TypeProviders.class)
53    public void testAppendArraysAsPossibleArray(Type type) throws ReflectiveOperationException {
54      Type arrayType = new ArrayType(type);
55      EnhancedPropertyFormatter wrapper = new EnhancedPropertyFormatterWrapper(new DefaultPropertyFormatter());
56      Method m = EnhancedPropertyFormatter.class.getDeclaredMethod("appendFormattedPossibleArray", StringBuilder.class, Object.class);
57      for (Object value: arrayType.getSampleValues()) {
58        StringBuilder builder = new StringBuilder();
59        m.invoke(wrapper, builder, value);
60        assertEquals(builder.toString(), new DefaultPropertyFormatter().format(value));
61      }
62    }
63  
64    @Test(dataProvider="types", dataProviderClass=TypeProviders.class)
65    public void testFormat(Type type) throws ReflectiveOperationException {
66      DefaultPropertyFormatter formatter = new DefaultPropertyFormatter();
67      EnhancedPropertyFormatter wrapper = new EnhancedPropertyFormatterWrapper(formatter);
68      for (Object value: type.getSampleValues()) {
69        assertEquals(wrapper.format(value), formatter.format(value));
70      }
71    }
72  }