DefaultParserTest.java revision 1870:4aa2e64eff30
1/*
2 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24package jdk.test.failurehandler.value;
25
26import org.junit.Assert;
27import org.junit.Test;
28
29public class DefaultParserTest {
30    @Test
31    public void testParseStringArray() throws Exception {
32        DefaultParser parser = new DefaultParser();
33        String line = "a aa   aaa";
34        String[] result = {"a", "aa", "", "", "aaa"};
35        Assert.assertArrayEquals(result,
36                (Object[]) parser.parse(result.getClass(), line, " "));
37
38        line = null;
39        result = new String[]{};
40        Assert.assertArrayEquals(result,
41                (Object[]) parser.parse(result.getClass(), line, " "));
42    }
43
44    @Test
45    public void testParseObjectArray() throws Exception {
46        DefaultParser parser = new DefaultParser();
47        String line = "a aa   aaa";
48        String[] result = {"a", "aa", "", "", "aaa"};
49        Assert.assertArrayEquals(result,
50                (String[]) parser.parse(result.getClass(), line, " "));
51        Object[] result2 = {"a", "aa", "", "", "aaa"};
52        Assert.assertArrayEquals(result2,
53                (Object[]) parser.parse(result.getClass(), line, " "));
54    }
55
56    @Test
57    public void testParseCharArray() throws Exception {
58        DefaultParser parser = new DefaultParser();
59        String line = "a b c a";
60        char[] result = {'a', 'b', 'c', 'a'};
61        Assert.assertArrayEquals(result,
62                (char[]) parser.parse(result.getClass(), line, " "));
63
64        Character[] result2 = {'a', 'b', 'c', 'a'};
65        Assert.assertArrayEquals(result2,
66                (Character[]) parser.parse(result2.getClass(), line, " "));
67    }
68
69    @Test
70    public void testParseBoolean() throws Exception {
71        DefaultParser parser = new DefaultParser();
72        String line = "a b c a";
73        Assert.assertEquals(false,
74                (boolean) parser.parse(boolean.class, line, " "));
75        Assert.assertEquals(Boolean.FALSE,
76                parser.parse(Boolean.class, line, " "));
77        line = "trUe";
78        Assert.assertEquals(true,
79                (boolean) parser.parse(boolean.class, line, " "));
80        Assert.assertEquals(Boolean.TRUE,
81                parser.parse(Boolean.class, line, " "));
82    }
83
84    @Test
85    public void testParseShort() throws Exception {
86        DefaultParser parser = new DefaultParser();
87        Assert.assertSame("10", (short) 10,
88                parser.parse(short.class, "10", " "));
89        Assert.assertSame("010", (short) 8,
90                parser.parse(short.class, "010", " "));
91        Assert.assertSame("0x10", (short) 16,
92                parser.parse(short.class, "0x10", " "));
93    }
94
95    @Test
96    public void testParseByte() throws Exception {
97        DefaultParser parser = new DefaultParser();
98        Assert.assertSame("11", (byte) 11,
99                parser.parse(byte.class, "11", " "));
100        Assert.assertSame("011", (byte) 9,
101                parser.parse(byte.class, "011", " "));
102        Assert.assertSame("0x11", (byte) 17,
103                parser.parse(byte.class, "0x11", " "));
104    }
105
106    @Test
107    public void testParseInt() throws Exception {
108        DefaultParser parser = new DefaultParser();
109        Assert.assertEquals("20", (int) 20,
110                parser.parse(int.class, "20", " "));
111        Assert.assertEquals("020", (int) 16,
112                parser.parse(int.class, "020", " "));
113        Assert.assertEquals("0x20", (int) 32,
114                parser.parse(int.class, "0x20", " "));
115    }
116
117
118}
119