1 package au.com.bytecode.opencsv.bean;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 import static org.junit.Assert.assertEquals;
21 import static org.junit.Assert.assertNotNull;
22 import static org.junit.Assert.assertTrue;
23
24 import java.io.StringReader;
25 import java.util.List;
26
27 import org.junit.Test;
28
29
30 public class ColumnPositionMappingStrategyTest {
31
32 @Test
33 public void testParse() {
34 String s = "" +
35 "kyle,123456,emp123\n" +
36 "jimmy,abcnum,cust09878";
37 ColumnPositionMappingStrategy<MockBean> strat = new ColumnPositionMappingStrategy<MockBean>();
38 strat.setType(MockBean.class);
39 String[] columns = new String[] {"name", "orderNumber", "id"};
40 strat.setColumnMapping(columns);
41
42 CsvToBean<MockBean> csv = new CsvToBean<MockBean>();
43 List<MockBean> list = csv.parse(strat, new StringReader(s));
44 assertNotNull(list);
45 assertTrue(list.size() == 2);
46 MockBean bean = list.get(0);
47 assertEquals("kyle", bean.getName());
48 assertEquals("123456", bean.getOrderNumber());
49 assertEquals("emp123", bean.getId());
50 }
51
52 }