1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.commons.lang3.text;
19
20 import static org.junit.jupiter.api.Assertions.assertEquals;
21
22 import java.text.FieldPosition;
23 import java.text.Format;
24 import java.text.ParsePosition;
25 import java.text.SimpleDateFormat;
26 import java.util.Locale;
27
28 import org.apache.commons.lang3.AbstractLangTest;
29 import org.junit.jupiter.api.Test;
30
31
32
33
34 @Deprecated
35 public class CompositeFormatTest extends AbstractLangTest {
36
37
38
39
40 @Test
41 public void testCompositeFormat() {
42
43 final Format parser = new Format() {
44 private static final long serialVersionUID = 1L;
45
46 @Override
47 public StringBuffer format(final Object obj, final StringBuffer toAppendTo, final FieldPosition pos) {
48 throw new UnsupportedOperationException("Not implemented");
49 }
50
51 @Override
52 public Object parseObject(final String source, final ParsePosition pos) {
53 return null;
54 }
55 };
56
57 final Format formatter = new Format() {
58 private static final long serialVersionUID = 1L;
59
60 @Override
61 public StringBuffer format(final Object obj, final StringBuffer toAppendTo, final FieldPosition pos) {
62 return null;
63 }
64
65 @Override
66 public Object parseObject(final String source, final ParsePosition pos) {
67 throw new UnsupportedOperationException("Not implemented");
68 }
69 };
70
71 final CompositeFormat composite = new CompositeFormat(parser, formatter);
72
73 composite.parseObject("", null);
74 composite.format(new Object(), new StringBuffer(), null);
75 assertEquals(parser, composite.getParser(), "Parser get method incorrectly implemented");
76 assertEquals(formatter, composite.getFormatter(), "Formatter get method incorrectly implemented");
77 }
78
79 @Test
80 public void testUsage() throws Exception {
81 final Format f1 = new SimpleDateFormat("MMddyyyy", Locale.ENGLISH);
82 final Format f2 = new SimpleDateFormat("MMMM d, yyyy", Locale.ENGLISH);
83 final CompositeFormat c = new CompositeFormat(f1, f2);
84 final String testString = "January 3, 2005";
85 assertEquals(testString, c.format(c.parseObject("01032005")));
86 assertEquals(testString, c.reformat("01032005"));
87 }
88
89 }