Statistics
| Revision:

root / branches / v2_0_0_prep / libraries / libCompat / src-test / org / gvsig / compat / lang / StringUtilsTestParent.java @ 31544

History | View | Annotate | Download (3.11 KB)

1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 * 
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 * 
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 * 
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
 * MA  02110-1301, USA.
20
 * 
21
 */
22

    
23
/*
24
 * AUTHORS (In addition to CIT):
25
 * 2008 {{Company}}   {{Task}}
26
 */
27
package org.gvsig.compat.lang;
28

    
29
import java.util.Arrays;
30
import java.util.List;
31

    
32
import junit.framework.TestCase;
33

    
34
/**
35
 * Parent class for Unit tests for {@link org.gvsig.compat.lang.StringUtils}
36
 * implementations.
37
 * 
38
 * @author <a href="mailto:cordin@disid.com">C?sar Ordi?ana</a>
39
 */
40
public abstract class StringUtilsTestParent extends TestCase {
41

    
42
    private StringUtils utils;
43

    
44
    protected void setUp() throws Exception {
45
        super.setUp();
46
        utils = createUtils();
47
    }
48

    
49
    /**
50
     * Return a new instance of an implementation of the StringUtils interface.
51
     * 
52
     * @return a new StringUtils instance
53
     */
54
    protected abstract StringUtils createUtils();
55

    
56
    /**
57
     * Test method for
58
     * {@link org.gvsig.compat.se.lang.StandardStringUtils#split(java.lang.String, java.lang.String)}
59
     * .
60
     */
61
    public void testSplitString() {
62
        // Check the result is the same as the returned with the String.split
63
        // method.
64
        List list1;
65
        List list2;
66

    
67
        String testString = "En un lugar de la Mancha";
68
        String regex = " ";
69

    
70
        list1 = Arrays.asList(new String[] { "En", "un", "lugar", "de", "la",
71
                "Mancha" });
72

    
73
        list2 = Arrays.asList(utils.split(testString, regex));
74

    
75
        assertEquals(list1, list2);
76

    
77
        list1 = Arrays.asList(new String[] { "En", "un lugar de la Mancha" });
78

    
79
        list2 = Arrays.asList(utils.split(testString, regex, 2));
80

    
81
        assertEquals(list1, list2);
82
    }
83

    
84
    /**
85
     * Test method for
86
     * {@link org.gvsig.compat.se.lang.StandardStringUtils#replaceAll(java.lang.String, java.lang.String, java.lang.String)}
87
     * .
88
     */
89
    public void testReplaceAll() {
90
        // Check the result is the same as the returned with the
91
        // String.replaceAll method.
92
        String testString = "En un lugar de la Mancha";
93
        String regex = " ";
94
        String replacement = "_";
95

    
96
        assertEquals("En_un_lugar_de_la_Mancha", utils
97
                .replaceAll(testString, regex, replacement));
98
        
99
        // Check replaceFirst
100
        assertEquals("En_un lugar de la Mancha", utils
101
                        .replaceFirst(testString, regex, replacement));
102
    }
103
}