Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.compat / org.gvsig.compat.se / src / test / java / org / gvsig / compat / lang / StringUtilsTestParent.java @ 40559

History | View | Annotate | Download (3.9 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
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 3
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
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
/*
25
 * AUTHORS (In addition to CIT):
26
 * 2008 {{Company}}   {{Task}}
27
 */
28
package org.gvsig.compat.lang;
29

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

    
33
import junit.framework.TestCase;
34

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

    
43
        private StringUtils utils;
44

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

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

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

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

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

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

    
76
                assertEquals(list1, list2);
77

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

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

    
82
                assertEquals(list1, list2);
83
        }
84

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

    
97
                assertEquals("En_un_lugar_de_la_Mancha",
98
                                utils.replaceAll(testString, regex, replacement));
99

    
100
                // Check replaceFirst
101
                assertEquals("En_un lugar de la Mancha",
102
                                utils.replaceFirst(testString, regex, replacement));
103
        }
104

    
105
        /**
106
         * Test method for
107
         * {@link org.gvsig.compat.se.lang.StandardStringUtils#compare(String, String, boolean)}
108
         * .
109
         */
110
        public void testCompare() {
111
                String avion = "Avi?n";
112
                String avionaccent = "Avion";
113
                String barco = "Barco";
114

    
115
                // Same value
116
                assertEquals(avion + " is not equal to " + avion, 0,
117
                                utils.compare(avion, avion, false));
118
                assertEquals(avion + " is not equal to " + avion, 0,
119
                                utils.compare(avion, avion, true));
120

    
121
                // Non localized comparison
122
                assertTrue(utils.compare(avion, barco, false) < 0);
123
                assertTrue(utils.compare(avion, avionaccent, false) > 0);
124
                assertTrue(utils.compare(barco, avion, false) > 0);
125
                assertTrue(utils.compare(avionaccent, avion, false) < 0);
126

    
127
                // Localized comparison, so accents must not be taken into account
128
                assertTrue(utils.compare(avion, barco, true) < 0);
129
                assertEquals(0, utils.compare(avion, avionaccent, true));
130
                assertTrue(utils.compare(barco, avion, true) > 0);
131
                assertEquals(0, utils.compare(avionaccent, avion, true));
132
        }
133
}