01: /*
02: Copyright 2004-2007 Paul R. Holser, Jr. All rights reserved.
03: Licensed under the Academic Free License version 3.0
04: */
05:
06: package joptsimple.util;
07:
08: import java.util.ArrayList;
09: import java.util.Collections;
10: import java.util.List;
11: import java.util.StringTokenizer;
12:
13: import joptsimple.Helpers;
14: import junit.framework.TestCase;
15:
16: /**
17: * @author <a href="mailto:pholser@alumni.rice.edu">Paul Holser</a>
18: * @version $Id: ColumnarDataTestCase.java,v 1.7 2007/04/10 20:06:26 pholser Exp $
19: */
20: public abstract class ColumnarDataTestCase extends TestCase {
21: protected ColumnarData grid;
22:
23: protected void setUp() throws Exception {
24: super .setUp();
25:
26: grid = new ColumnarData(headers());
27: }
28:
29: protected abstract String[] headers();
30:
31: protected List lines() {
32: return split(grid.format(), Helpers.LINE_SEPARATOR);
33: }
34:
35: private static List split(String target, String separator) {
36: List pieces = new ArrayList();
37:
38: for (StringTokenizer lexer = new StringTokenizer(target,
39: separator); lexer.hasMoreTokens();) {
40:
41: pieces.add(lexer.nextToken());
42: }
43:
44: return Collections.unmodifiableList(pieces);
45: }
46: }
|