Revision 1968
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.192/org.gvsig.tools.lib/src/test/java/org/gvsig/tools/junit/AbstractLibraryAutoInitTestCase.java | ||
---|---|---|
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 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 |
* 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 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
25 |
* |
|
26 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
27 |
* of the Valencian Government (CIT) |
|
28 |
* |
|
29 |
* This program is free software; you can redistribute it and/or |
|
30 |
* modify it under the terms of the GNU General Public License |
|
31 |
* as published by the Free Software Foundation; either version 2 |
|
32 |
* of the License, or (at your option) any later version. |
|
33 |
* |
|
34 |
* This program is distributed in the hope that it will be useful, |
|
35 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
36 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
37 |
* GNU General Public License for more details. |
|
38 |
* |
|
39 |
* You should have received a copy of the GNU General Public License |
|
40 |
* along with this program; if not, write to the Free Software |
|
41 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
42 |
* MA 02110-1301, USA. |
|
43 |
* |
|
44 |
*/ |
|
45 |
|
|
46 |
/* |
|
47 |
* AUTHORS (In addition to CIT): |
|
48 |
* 2009 {DiSiD Technologies} {{Task}} |
|
49 |
*/ |
|
50 |
package org.gvsig.tools.junit; |
|
51 |
|
|
52 |
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer; |
|
53 |
|
|
54 |
import junit.framework.TestCase; |
|
55 |
|
|
56 |
/** |
|
57 |
* @author <a href="mailto:cordinyana@gvsig.org">C?sar Ordi?ana</a> |
|
58 |
*/ |
|
59 |
public abstract class AbstractLibraryAutoInitTestCase extends TestCase { |
|
60 |
|
|
61 |
/** |
|
62 |
* @see TestCase#TestCase() |
|
63 |
*/ |
|
64 |
public AbstractLibraryAutoInitTestCase() { |
|
65 |
super(); |
|
66 |
} |
|
67 |
|
|
68 |
/** |
|
69 |
* @see TestCase#TestCase(String) |
|
70 |
*/ |
|
71 |
public AbstractLibraryAutoInitTestCase(String name) { |
|
72 |
super(name); |
|
73 |
} |
|
74 |
|
|
75 |
protected final void setUp() throws Exception { |
|
76 |
super.setUp(); |
|
77 |
|
|
78 |
new DefaultLibrariesInitializer().fullInitialize(); |
|
79 |
|
|
80 |
doSetUp(); |
|
81 |
} |
|
82 |
|
|
83 |
protected abstract void doSetUp() throws Exception; |
|
84 |
} |
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.192/org.gvsig.tools.lib/src/test/java/org/gvsig/tools/AllTests.java | ||
---|---|---|
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 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 |
* 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 |
package org.gvsig.tools; |
|
25 |
|
|
26 |
import junit.framework.Test; |
|
27 |
import junit.framework.TestSuite; |
|
28 |
|
|
29 |
import org.gvsig.tools.dynobject.ImportDynClassTest; |
|
30 |
import org.gvsig.tools.persistence.BasicListTest; |
|
31 |
import org.gvsig.tools.persistence.BasicMapTest; |
|
32 |
import org.gvsig.tools.persistence.BasicSetTest; |
|
33 |
import org.gvsig.tools.persistence.BasicTypesArrayTest; |
|
34 |
import org.gvsig.tools.persistence.BasicTypesTest; |
|
35 |
import org.gvsig.tools.persistence.case1.Case1AllTests; |
|
36 |
|
|
37 |
public class AllTests { |
|
38 |
|
|
39 |
public static Test suite() { |
|
40 |
TestSuite suite = new TestSuite("Test for org.gvsig.tools.persistence"); |
|
41 |
|
|
42 |
// Persistence tests |
|
43 |
suite.addTestSuite(BasicMapTest.class); |
|
44 |
suite.addTestSuite(BasicTypesArrayTest.class); |
|
45 |
suite.addTestSuite(BasicSetTest.class); |
|
46 |
suite.addTestSuite(BasicListTest.class); |
|
47 |
suite.addTestSuite(BasicTypesTest.class); |
|
48 |
suite.addTest(Case1AllTests.suite()); |
|
49 |
|
|
50 |
// DynObject tests |
|
51 |
suite.addTestSuite(ImportDynClassTest.class); |
|
52 |
return suite; |
|
53 |
} |
|
54 |
|
|
55 |
} |
|
0 | 56 |
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.192/org.gvsig.tools.lib/src/test/java/org/gvsig/tools/packageutils/DefaultVersionTest.java | ||
---|---|---|
1 |
package org.gvsig.tools.packageutils; |
|
2 |
|
|
3 |
import junit.framework.TestCase; |
|
4 |
|
|
5 |
import org.gvsig.tools.packageutils.impl.DefaultVersion; |
|
6 |
|
|
7 |
public class DefaultVersionTest extends TestCase { |
|
8 |
|
|
9 |
public void testFormat() { |
|
10 |
DefaultVersion v = new DefaultVersion(); |
|
11 |
v.parse("1.2.3-SNAPSHOT-4"); |
|
12 |
String s = v.format("%M.%m.%r-%c-%b"); |
|
13 |
assertEquals("1.2.3-SNAPSHOT-4", s); |
|
14 |
} |
|
15 |
} |
|
0 | 16 |
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.192/org.gvsig.tools.lib/src/test/java/org/gvsig/tools/packageutils/VersionTest_peta.java | ||
---|---|---|
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 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 |
* 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 |
package org.gvsig.tools.packageutils; |
|
25 |
|
|
26 |
import junit.framework.TestCase; |
|
27 |
|
|
28 |
import org.gvsig.tools.packageutils.impl.DefaultVersion; |
|
29 |
|
|
30 |
public class VersionTest_peta extends TestCase { |
|
31 |
|
|
32 |
public void testParseVersion() { |
|
33 |
Version v = new DefaultVersion(); |
|
34 |
|
|
35 |
v.parse("2.3.20-SNAPSHOT-10"); |
|
36 |
assertEquals("0002.0003.0020-SNAPSHOT-0010", v.fullFormat()); |
|
37 |
|
|
38 |
v.parse("2.3.20-SNAPSHOT"); |
|
39 |
assertEquals("0002.0003.0020-SNAPSHOT-0000", v.fullFormat()); |
|
40 |
|
|
41 |
v.parse("2.3.20-10"); |
|
42 |
assertEquals("0002.0003.0020-AAAA-0010", v.fullFormat()); |
|
43 |
|
|
44 |
v.parse("2.3.20"); |
|
45 |
assertEquals("0002.0003.0020-AAAA-0000", v.fullFormat()); |
|
46 |
|
|
47 |
v.parse("2.3"); |
|
48 |
assertEquals("0002.0003.0000-AAAA-0000", v.fullFormat()); |
|
49 |
|
|
50 |
v.parse("2"); |
|
51 |
assertEquals("0002.0000.0000-AAAA-0000", v.fullFormat()); |
|
52 |
} |
|
53 |
|
|
54 |
public void testCompareVersion() { |
|
55 |
Version v1 = new DefaultVersion(); |
|
56 |
Version v2 = new DefaultVersion(); |
|
57 |
|
|
58 |
v1.parse("2.3.20-SNAPSHOT-10"); |
|
59 |
v2.parse("2.3"); |
|
60 |
boolean b = v2.check("<", v1); |
|
61 |
assert (b); |
|
62 |
|
|
63 |
} |
|
64 |
|
|
65 |
protected void doSetUp() throws Exception { |
|
66 |
// TODO Auto-generated method stub |
|
67 |
|
|
68 |
} |
|
69 |
} |
|
0 | 70 |
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.192/org.gvsig.tools.lib/src/test/java/org/gvsig/tools/packageutils/PackageManagerTest_peta.java | ||
---|---|---|
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 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 |
* 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 |
* 2010 {Prodevelop} {Task} |
|
27 |
*/ |
|
28 |
|
|
29 |
package org.gvsig.tools.packageutils; |
|
30 |
|
|
31 |
import java.io.ByteArrayInputStream; |
|
32 |
import java.io.ByteArrayOutputStream; |
|
33 |
import java.io.IOException; |
|
34 |
import java.io.InputStream; |
|
35 |
|
|
36 |
import junit.framework.TestCase; |
|
37 |
|
|
38 |
import org.gvsig.tools.packageutils.impl.DefaultPackageInfo; |
|
39 |
import org.gvsig.tools.packageutils.impl.DefaultPackageManager; |
|
40 |
|
|
41 |
/** |
|
42 |
* @author <a href="mailto:jpiera@gvsig.org">Jorge Piera Llodrá</a> |
|
43 |
*/ |
|
44 |
public class PackageManagerTest_peta extends TestCase { |
|
45 |
|
|
46 |
PackageManager manager = null; |
|
47 |
|
|
48 |
private PackageManager getManager() { |
|
49 |
if (this.manager == null) { |
|
50 |
this.manager = new DefaultPackageManager(); |
|
51 |
} |
|
52 |
return this.manager; |
|
53 |
} |
|
54 |
|
|
55 |
protected void doSetUp() throws Exception { |
|
56 |
// Do nothing |
|
57 |
|
|
58 |
} |
|
59 |
|
|
60 |
public void testReadPackage() throws IOException { |
|
61 |
InputStream fis = getClass().getResourceAsStream("package1.info"); |
|
62 |
|
|
63 |
PackageInfo packageInfo = new DefaultPackageInfo(); |
|
64 |
|
|
65 |
getManager().readPacakgeInfo(packageInfo, fis); |
|
66 |
// System.out.println(packageInfo.toString()); |
|
67 |
|
|
68 |
assertEquals(packageInfo.getCode(), "org.gvsig.myplugin"); |
|
69 |
assertEquals(packageInfo.getName(), "myplugin"); |
|
70 |
assertEquals(packageInfo.getDescription(), "Test"); |
|
71 |
assertEquals(packageInfo.getVersion().toString(), "1.0.0-0"); |
|
72 |
assertEquals(packageInfo.getState(), "RC1"); |
|
73 |
assertEquals(packageInfo.isOfficial(), true); |
|
74 |
} |
|
75 |
|
|
76 |
public void testWritePackage() throws IOException { |
|
77 |
PackageInfo packageInfo1 = new DefaultPackageInfo(); |
|
78 |
PackageInfo packageInfo2 = new DefaultPackageInfo(); |
|
79 |
|
|
80 |
packageInfo1.setCode("org.gvsig.myplugin"); |
|
81 |
packageInfo1.setName("My name"); |
|
82 |
packageInfo1.setDescription("My description"); |
|
83 |
packageInfo1.getVersion().parse("1.0.0"); |
|
84 |
packageInfo1.setState("final"); |
|
85 |
packageInfo1.setOfficial(false); |
|
86 |
packageInfo1.setType("plugin"); |
|
87 |
|
|
88 |
ByteArrayOutputStream out = new ByteArrayOutputStream(); |
|
89 |
|
|
90 |
getManager().writePacakgeInfo(packageInfo1, out); |
|
91 |
getManager().readPacakgeInfo(packageInfo2, new ByteArrayInputStream(out.toByteArray())); |
|
92 |
|
|
93 |
assertEquals("org.gvsig.myplugin", packageInfo2.getCode()); |
|
94 |
assertEquals("My name", packageInfo2.getName()); |
|
95 |
assertEquals("My description", packageInfo2.getDescription()); |
|
96 |
assertEquals("1.0.0-0", packageInfo2.getVersion().toString()); |
|
97 |
assertEquals("final", packageInfo2.getState()); |
|
98 |
assertEquals(false, packageInfo2.isOfficial()); |
|
99 |
} |
|
100 |
|
|
101 |
} |
|
0 | 102 |
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.192/org.gvsig.tools.lib/src/test/java/org/gvsig/tools/packageutils/DependencyTest_peta.java | ||
---|---|---|
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 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 |
* 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 |
package org.gvsig.tools.packageutils; |
|
25 |
|
|
26 |
import junit.framework.TestCase; |
|
27 |
|
|
28 |
import org.gvsig.tools.packageutils.impl.DefaultDependency; |
|
29 |
|
|
30 |
public class DependencyTest_peta extends TestCase { |
|
31 |
|
|
32 |
public void testParse() { |
|
33 |
Dependency dep = new DefaultDependency(); |
|
34 |
|
|
35 |
dep.parse("required: org.gvsig.app >= 2.0.0-SNAPSHOT-2030"); |
|
36 |
String s = dep.toString(); |
|
37 |
assertEquals("required: org.gvsig.app >= 2.0.0-SNAPSHOT-2030", s); |
|
38 |
} |
|
39 |
|
|
40 |
protected void doSetUp() throws Exception { |
|
41 |
// TODO Auto-generated method stub |
|
42 |
|
|
43 |
} |
|
44 |
} |
|
0 | 45 |
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.192/org.gvsig.tools.lib/src/test/java/org/gvsig/tools/datatypes/impl/coercion/CoerceToDoubleTest.java | ||
---|---|---|
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 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 |
* 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 |
package org.gvsig.tools.datatypes.impl.coercion; |
|
25 |
|
|
26 |
import org.gvsig.tools.dataTypes.CoercionException; |
|
27 |
import org.gvsig.tools.dataTypes.impl.coercion.CoerceToDouble; |
|
28 |
|
|
29 |
/** |
|
30 |
* Unit tests for the {@link CoerceToDouble} class. |
|
31 |
* |
|
32 |
* @author gvSIG Team |
|
33 |
* @version $Id$ |
|
34 |
*/ |
|
35 |
public class CoerceToDoubleTest extends CoercionTestAbstract { |
|
36 |
|
|
37 |
public void testCoerce() throws Exception { |
|
38 |
CoerceToDouble coerce = new CoerceToDouble(); |
|
39 |
|
|
40 |
Double double12 = new Double(12.0f); |
|
41 |
|
|
42 |
assertCoercion(coerce, new Integer(12), double12); |
|
43 |
assertCoercion(coerce, new Long(12l), double12); |
|
44 |
assertCoercion(coerce, new Float(12.0f), double12); |
|
45 |
assertCoercion(coerce, new Double(12.0d), double12); |
|
46 |
assertCoercion(coerce, "12", double12); |
|
47 |
assertCoercion(coerce, "12.0", double12); |
|
48 |
assertCoercion(coerce, "0x000C", double12); |
|
49 |
} |
|
50 |
|
|
51 |
private void assertCoercion(CoerceToDouble coerce, Object value, |
|
52 |
Double expected) throws CoercionException { |
|
53 |
assertCoercion(coerce, value, Double.class, expected); |
|
54 |
} |
|
55 |
|
|
56 |
} |
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.192/org.gvsig.tools.lib/src/test/java/org/gvsig/tools/datatypes/impl/coercion/CoerceToIntTest.java | ||
---|---|---|
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 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 |
* 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 |
package org.gvsig.tools.datatypes.impl.coercion; |
|
25 |
|
|
26 |
import org.gvsig.tools.dataTypes.CoercionException; |
|
27 |
import org.gvsig.tools.dataTypes.impl.coercion.CoerceToInt; |
|
28 |
|
|
29 |
/** |
|
30 |
* Unit tests for the {@link CoerceToInt} class. |
|
31 |
* |
|
32 |
* @author gvSIG Team |
|
33 |
* @version $Id$ |
|
34 |
*/ |
|
35 |
public class CoerceToIntTest extends CoercionTestAbstract { |
|
36 |
|
|
37 |
public void testCoerce() throws Exception { |
|
38 |
CoerceToInt coerce = new CoerceToInt(); |
|
39 |
|
|
40 |
Integer integer12 = new Integer(12); |
|
41 |
|
|
42 |
assertCoercion(coerce, new Integer(12), integer12); |
|
43 |
assertCoercion(coerce, new Long(12l), integer12); |
|
44 |
assertCoercion(coerce, new Float(12.0f), integer12); |
|
45 |
assertCoercion(coerce, new Double(12.0d), integer12); |
|
46 |
assertCoercion(coerce, "12", integer12); |
|
47 |
assertCoercion(coerce, "0x0C", integer12); |
|
48 |
} |
|
49 |
|
|
50 |
private void assertCoercion(CoerceToInt coerce, Object value, |
|
51 |
Integer expected) |
|
52 |
throws CoercionException { |
|
53 |
assertCoercion(coerce, value, Integer.class, expected); |
|
54 |
} |
|
55 |
|
|
56 |
} |
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.192/org.gvsig.tools.lib/src/test/java/org/gvsig/tools/datatypes/impl/coercion/CoerceToDateTimeTest.java | ||
---|---|---|
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 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 |
* 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 |
package org.gvsig.tools.datatypes.impl.coercion; |
|
25 |
|
|
26 |
import java.text.DateFormat; |
|
27 |
import java.util.Calendar; |
|
28 |
import java.util.Date; |
|
29 |
|
|
30 |
import org.gvsig.tools.dataTypes.CoercionException; |
|
31 |
import org.gvsig.tools.dataTypes.DataTypesManager.Coercion; |
|
32 |
import org.gvsig.tools.dataTypes.impl.coercion.CoerceToDate; |
|
33 |
import org.gvsig.tools.dataTypes.impl.coercion.CoerceToDateTime; |
|
34 |
|
|
35 |
/** |
|
36 |
* Unit tests for the {@link CoerceToDate} class. |
|
37 |
* |
|
38 |
* @author gvSIG Team |
|
39 |
* @version $Id$ |
|
40 |
*/ |
|
41 |
public class CoerceToDateTimeTest extends CoercionTestAbstract { |
|
42 |
|
|
43 |
public void testCoerce() throws Exception { |
|
44 |
CoerceToDateTime coerce = new CoerceToDateTime(); |
|
45 |
|
|
46 |
Calendar calendar = Calendar.getInstance(); |
|
47 |
// Remember the month value is in format 0 to 11, instead of 1 to 12, |
|
48 |
// so september is the 8th month |
|
49 |
calendar.set(2011, 8, 5, 10, 5, 30); |
|
50 |
Date date = calendar.getTime(); |
|
51 |
|
|
52 |
assertCoercion(coerce, date, date); |
|
53 |
DateFormat format = |
|
54 |
DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM); |
|
55 |
assertCoercion(coerce, format.format(date), date); |
|
56 |
} |
|
57 |
|
|
58 |
private void assertCoercion(Coercion coerce, Object value, Date expected) |
|
59 |
throws CoercionException { |
|
60 |
Object result = coerce.coerce(value); |
|
61 |
assertEquals(Date.class, result.getClass()); |
|
62 |
Date resultDate = (Date) result; |
|
63 |
assertEquals(expected.getYear(), resultDate.getYear()); |
|
64 |
assertEquals(expected.getMonth(), resultDate.getMonth()); |
|
65 |
assertEquals(expected.getDay(), resultDate.getDay()); |
|
66 |
assertEquals(expected.getHours(), resultDate.getHours()); |
|
67 |
assertEquals(expected.getMinutes(), resultDate.getMinutes()); |
|
68 |
assertEquals(expected.getSeconds(), resultDate.getSeconds()); |
|
69 |
} |
|
70 |
|
|
71 |
} |
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.192/org.gvsig.tools.lib/src/test/java/org/gvsig/tools/datatypes/impl/coercion/CoerceToDateTest.java | ||
---|---|---|
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 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 |
* 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 |
package org.gvsig.tools.datatypes.impl.coercion; |
|
25 |
|
|
26 |
import java.text.DateFormat; |
|
27 |
import java.util.Calendar; |
|
28 |
import java.util.Date; |
|
29 |
|
|
30 |
import org.gvsig.tools.dataTypes.CoercionException; |
|
31 |
import org.gvsig.tools.dataTypes.impl.coercion.CoerceToDate; |
|
32 |
|
|
33 |
/** |
|
34 |
* Unit tests for the {@link CoerceToDate} class. |
|
35 |
* |
|
36 |
* @author gvSIG Team |
|
37 |
* @version $Id$ |
|
38 |
*/ |
|
39 |
public class CoerceToDateTest extends CoercionTestAbstract { |
|
40 |
|
|
41 |
public void testCoerce() throws Exception { |
|
42 |
CoerceToDate coerce = new CoerceToDate(); |
|
43 |
|
|
44 |
Calendar calendar = Calendar.getInstance(); |
|
45 |
// Remember the month value is in format 0 to 11, instead of 1 to 12, |
|
46 |
// so september is the 8th month |
|
47 |
calendar.set(2011, 8, 5); |
|
48 |
Date date = calendar.getTime(); |
|
49 |
|
|
50 |
assertCoercion(coerce, date, date); |
|
51 |
DateFormat format = DateFormat.getDateInstance(DateFormat.SHORT); |
|
52 |
assertCoercion(coerce, format.format(date), date); |
|
53 |
} |
|
54 |
|
|
55 |
private void assertCoercion(CoerceToDate coerce, Object value, Date expected) |
|
56 |
throws CoercionException { |
|
57 |
Object result = coerce.coerce(value); |
|
58 |
assertEquals(Date.class, result.getClass()); |
|
59 |
Date resultDate = (Date) result; |
|
60 |
assertEquals(expected.getYear(), resultDate.getYear()); |
|
61 |
assertEquals(expected.getMonth(), resultDate.getMonth()); |
|
62 |
assertEquals(expected.getDay(), resultDate.getDay()); |
|
63 |
} |
|
64 |
|
|
65 |
} |
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.192/org.gvsig.tools.lib/src/test/java/org/gvsig/tools/datatypes/impl/coercion/CoerceToTimeTest.java | ||
---|---|---|
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 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 |
* 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 |
package org.gvsig.tools.datatypes.impl.coercion; |
|
25 |
|
|
26 |
import java.text.DateFormat; |
|
27 |
import java.util.Calendar; |
|
28 |
import java.util.Date; |
|
29 |
|
|
30 |
import org.gvsig.tools.dataTypes.CoercionException; |
|
31 |
import org.gvsig.tools.dataTypes.DataTypesManager.Coercion; |
|
32 |
import org.gvsig.tools.dataTypes.impl.coercion.CoerceToDate; |
|
33 |
import org.gvsig.tools.dataTypes.impl.coercion.CoerceToTime; |
|
34 |
|
|
35 |
/** |
|
36 |
* Unit tests for the {@link CoerceToDate} class. |
|
37 |
* |
|
38 |
* @author gvSIG Team |
|
39 |
* @version $Id$ |
|
40 |
*/ |
|
41 |
public class CoerceToTimeTest extends CoercionTestAbstract { |
|
42 |
|
|
43 |
public void testCoerce() throws Exception { |
|
44 |
CoerceToTime coerce = new CoerceToTime(); |
|
45 |
|
|
46 |
Calendar calendar = Calendar.getInstance(); |
|
47 |
// Remember the month value is in format 0 to 11, instead of 1 to 12, |
|
48 |
// so september is the 8th month |
|
49 |
calendar.set(2011, 8, 5, 10, 5, 30); |
|
50 |
Date date = calendar.getTime(); |
|
51 |
|
|
52 |
assertCoercion(coerce, date, date); |
|
53 |
DateFormat format = DateFormat.getTimeInstance(DateFormat.MEDIUM); |
|
54 |
assertCoercion(coerce, format.format(date), date); |
|
55 |
} |
|
56 |
|
|
57 |
private void assertCoercion(Coercion coerce, Object value, Date expected) |
|
58 |
throws CoercionException { |
|
59 |
Object result = coerce.coerce(value); |
|
60 |
assertEquals(Date.class, result.getClass()); |
|
61 |
Date resultDate = (Date) result; |
|
62 |
assertEquals(expected.getHours(), resultDate.getHours()); |
|
63 |
assertEquals(expected.getMinutes(), resultDate.getMinutes()); |
|
64 |
assertEquals(expected.getSeconds(), resultDate.getSeconds()); |
|
65 |
} |
|
66 |
|
|
67 |
} |
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.192/org.gvsig.tools.lib/src/test/java/org/gvsig/tools/datatypes/impl/coercion/CoerceToBooleanTest.java | ||
---|---|---|
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 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 |
* 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 |
package org.gvsig.tools.datatypes.impl.coercion; |
|
25 |
|
|
26 |
import org.gvsig.tools.dataTypes.CoercionException; |
|
27 |
import org.gvsig.tools.dataTypes.impl.coercion.CoerceToBoolean; |
|
28 |
|
|
29 |
/** |
|
30 |
* Unit tests for the {@link CoerceToBoolean} class. |
|
31 |
* |
|
32 |
* @author gvSIG Team |
|
33 |
* @version $Id$ |
|
34 |
*/ |
|
35 |
public class CoerceToBooleanTest extends CoercionTestAbstract { |
|
36 |
|
|
37 |
public void testCoerce() throws Exception { |
|
38 |
CoerceToBoolean coerce = new CoerceToBoolean(); |
|
39 |
|
|
40 |
assertCoercion(coerce, Boolean.TRUE, Boolean.TRUE); |
|
41 |
assertCoercion(coerce, Boolean.FALSE, Boolean.FALSE); |
|
42 |
assertCoercion(coerce, "true", Boolean.TRUE); |
|
43 |
assertCoercion(coerce, "false", Boolean.FALSE); |
|
44 |
assertCoercion(coerce, new Integer(1), Boolean.TRUE); |
|
45 |
assertCoercion(coerce, new Integer(0), Boolean.FALSE); |
|
46 |
assertCoercion(coerce, new Float(1.0f), Boolean.TRUE); |
|
47 |
assertCoercion(coerce, new Float(0.0f), Boolean.FALSE); |
|
48 |
} |
|
49 |
|
|
50 |
private void assertCoercion(CoerceToBoolean coerce, Object value, |
|
51 |
Boolean expected) throws CoercionException { |
|
52 |
assertCoercion(coerce, value, Boolean.class, expected); |
|
53 |
} |
|
54 |
|
|
55 |
} |
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.192/org.gvsig.tools.lib/src/test/java/org/gvsig/tools/datatypes/impl/coercion/CoerceToFileTest.java | ||
---|---|---|
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 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 |
* 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 |
package org.gvsig.tools.datatypes.impl.coercion; |
|
25 |
|
|
26 |
import java.io.File; |
|
27 |
|
|
28 |
import org.gvsig.tools.dataTypes.CoercionException; |
|
29 |
import org.gvsig.tools.dataTypes.impl.coercion.CoerceToFile; |
|
30 |
|
|
31 |
/** |
|
32 |
* Unit tests for the {@link CoerceToFile} class. |
|
33 |
* |
|
34 |
* @author gvSIG Team |
|
35 |
* @version $Id$ |
|
36 |
*/ |
|
37 |
public class CoerceToFileTest extends CoercionTestAbstract { |
|
38 |
|
|
39 |
public void testCoerce() throws Exception { |
|
40 |
CoerceToFile coerce = new CoerceToFile(); |
|
41 |
|
|
42 |
// Test with absolute path |
|
43 |
testFileCoercion(coerce, "/tmp/test.txt"); |
|
44 |
|
|
45 |
// Test with relative path |
|
46 |
testFileCoercion(coerce, "test.txt"); |
|
47 |
} |
|
48 |
|
|
49 |
private void testFileCoercion(CoerceToFile coerce, String path) |
|
50 |
throws CoercionException { |
|
51 |
File file = new File(path); |
|
52 |
assertCoercion(coerce, file, file); |
|
53 |
assertCoercion(coerce, file.getPath(), file); |
|
54 |
assertCoercion(coerce, file.toURI(), file.getAbsoluteFile()); |
|
55 |
} |
|
56 |
|
|
57 |
private void assertCoercion(CoerceToFile coerce, Object value, File expected) |
|
58 |
throws CoercionException { |
|
59 |
assertCoercion(coerce, value, File.class, expected); |
|
60 |
} |
|
61 |
|
|
62 |
} |
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.192/org.gvsig.tools.lib/src/test/java/org/gvsig/tools/datatypes/impl/coercion/CoerceToLongTest.java | ||
---|---|---|
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 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 |
* 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 |
package org.gvsig.tools.datatypes.impl.coercion; |
|
25 |
|
|
26 |
import org.gvsig.tools.dataTypes.CoercionException; |
|
27 |
import org.gvsig.tools.dataTypes.impl.coercion.CoerceToLong; |
|
28 |
|
|
29 |
/** |
|
30 |
* Unit tests for the {@link CoerceToLong} class. |
|
31 |
* |
|
32 |
* @author gvSIG Team |
|
33 |
* @version $Id$ |
|
34 |
*/ |
|
35 |
public class CoerceToLongTest extends CoercionTestAbstract { |
|
36 |
|
|
37 |
public void testCoerce() throws Exception { |
|
38 |
CoerceToLong coerce = new CoerceToLong(); |
|
39 |
|
|
40 |
Long long12 = new Long(12); |
|
41 |
|
|
42 |
assertCoercion(coerce, new Integer(12), long12); |
|
43 |
assertCoercion(coerce, new Long(12l), long12); |
|
44 |
assertCoercion(coerce, new Float(12.0f), long12); |
|
45 |
assertCoercion(coerce, new Double(12.0d), long12); |
|
46 |
assertCoercion(coerce, "12", long12); |
|
47 |
assertCoercion(coerce, "0x000C", long12); |
|
48 |
} |
|
49 |
|
|
50 |
private void assertCoercion(CoerceToLong coerce, Object value, Long expected) |
|
51 |
throws CoercionException { |
|
52 |
assertCoercion(coerce, value, Long.class, expected); |
|
53 |
} |
|
54 |
|
|
55 |
} |
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.192/org.gvsig.tools.lib/src/test/java/org/gvsig/tools/datatypes/impl/coercion/CoerceToURITest.java | ||
---|---|---|
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 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 |
* 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 |
package org.gvsig.tools.datatypes.impl.coercion; |
|
25 |
|
|
26 |
import java.net.URI; |
|
27 |
|
|
28 |
import org.gvsig.tools.dataTypes.CoercionException; |
|
29 |
import org.gvsig.tools.dataTypes.impl.coercion.CoerceToURI; |
|
30 |
|
|
31 |
/** |
|
32 |
* Unit tests for the {@link CoerceToURI} class. |
|
33 |
* |
|
34 |
* @author gvSIG Team |
|
35 |
* @version $Id$ |
|
36 |
*/ |
|
37 |
public class CoerceToURITest extends CoercionTestAbstract { |
|
38 |
|
|
39 |
public void testCoerce() throws Exception { |
|
40 |
CoerceToURI coerce = new CoerceToURI(); |
|
41 |
|
|
42 |
URI uri = new URI("http://www.gvsig.org"); |
|
43 |
|
|
44 |
assertCoercion(coerce, uri, uri); |
|
45 |
assertCoercion(coerce, uri.toString(), uri); |
|
46 |
} |
|
47 |
|
|
48 |
private void assertCoercion(CoerceToURI coerce, Object value, URI expected) |
|
49 |
throws CoercionException { |
|
50 |
assertCoercion(coerce, value, URI.class, expected); |
|
51 |
} |
|
52 |
|
|
53 |
} |
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.192/org.gvsig.tools.lib/src/test/java/org/gvsig/tools/datatypes/impl/coercion/CoercionTestAbstract.java | ||
---|---|---|
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 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 |
* 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 |
package org.gvsig.tools.datatypes.impl.coercion; |
|
25 |
|
|
26 |
import junit.framework.TestCase; |
|
27 |
|
|
28 |
import org.gvsig.tools.dataTypes.CoercionException; |
|
29 |
import org.gvsig.tools.dataTypes.DataTypesManager.Coercion; |
|
30 |
|
|
31 |
/** |
|
32 |
* Parent abstract class for Unit tests of the {@link Coercion} implementations. |
|
33 |
* |
|
34 |
* @author gvSIG Team |
|
35 |
* @version $Id$ |
|
36 |
*/ |
|
37 |
public class CoercionTestAbstract extends TestCase { |
|
38 |
|
|
39 |
/** |
|
40 |
* Asserts the result of a coercion |
|
41 |
* |
|
42 |
* @param coercion |
|
43 |
* to apply |
|
44 |
* @param value |
|
45 |
* to coerce |
|
46 |
* @param expectedClass |
|
47 |
* class that must have the result of the coercion |
|
48 |
* @param expectedResult |
|
49 |
* value that must have the result of the coercion |
|
50 |
* @throws CoercionException |
|
51 |
* if there is an error while performing the coercion |
|
52 |
*/ |
|
53 |
protected void assertCoercion(Coercion coercion, Object value, |
|
54 |
Class expectedClass, Object expectedResult) |
|
55 |
throws CoercionException { |
|
56 |
Object result = coercion.coerce(value); |
|
57 |
assertEquals(expectedClass, result.getClass()); |
|
58 |
assertEquals(expectedResult, result); |
|
59 |
} |
|
60 |
|
|
61 |
} |
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.192/org.gvsig.tools.lib/src/test/java/org/gvsig/tools/datatypes/impl/coercion/CoerceToURLTest.java | ||
---|---|---|
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 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 |
* 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 |
package org.gvsig.tools.datatypes.impl.coercion; |
|
25 |
|
|
26 |
import java.net.URL; |
|
27 |
|
|
28 |
import org.gvsig.tools.dataTypes.CoercionException; |
|
29 |
import org.gvsig.tools.dataTypes.impl.coercion.CoerceToURL; |
|
30 |
|
|
31 |
/** |
|
32 |
* Unit tests for the {@link CoerceToURL} class. |
|
33 |
* |
|
34 |
* @author gvSIG Team |
|
35 |
* @version $Id$ |
|
36 |
*/ |
|
37 |
public class CoerceToURLTest extends CoercionTestAbstract { |
|
38 |
|
|
39 |
public void testCoerce() throws Exception { |
|
40 |
CoerceToURL coerce = new CoerceToURL(); |
|
41 |
|
|
42 |
URL url = new URL("http://www.gvsig.org"); |
|
43 |
|
|
44 |
assertCoercion(coerce, url, url); |
|
45 |
assertCoercion(coerce, url.toString(), url); |
|
46 |
} |
|
47 |
|
|
48 |
private void assertCoercion(CoerceToURL coerce, Object value, URL expected) |
|
49 |
throws CoercionException { |
|
50 |
assertCoercion(coerce, value, URL.class, expected); |
|
51 |
} |
|
52 |
|
|
53 |
} |
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.192/org.gvsig.tools.lib/src/test/java/org/gvsig/tools/datatypes/impl/coercion/CoerceToByteTest.java | ||
---|---|---|
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 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 |
* 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 |
package org.gvsig.tools.datatypes.impl.coercion; |
|
25 |
|
|
26 |
import org.gvsig.tools.dataTypes.CoercionException; |
|
27 |
import org.gvsig.tools.dataTypes.impl.coercion.CoerceToByte; |
|
28 |
|
|
29 |
/** |
|
30 |
* Unit tests for the {@link CoerceToByte} class. |
|
31 |
* |
|
32 |
* @author gvSIG Team |
|
33 |
* @version $Id$ |
|
34 |
*/ |
|
35 |
public class CoerceToByteTest extends CoercionTestAbstract { |
|
36 |
|
|
37 |
public void testCoerce() throws Exception { |
|
38 |
CoerceToByte coerce = new CoerceToByte(); |
|
39 |
|
|
40 |
Byte byte12 = new Byte((byte) 12); |
|
41 |
|
|
42 |
assertCoercion(coerce, new Byte((byte) 12), byte12); |
|
43 |
assertCoercion(coerce, new Integer(12), byte12); |
|
44 |
assertCoercion(coerce, new Long(12l), byte12); |
|
45 |
assertCoercion(coerce, new Float(12.0f), byte12); |
|
46 |
assertCoercion(coerce, new Double(12.0d), byte12); |
|
47 |
assertCoercion(coerce, "12", byte12); |
|
48 |
assertCoercion(coerce, "0xC", byte12); |
|
49 |
} |
|
50 |
|
|
51 |
private void assertCoercion(CoerceToByte coerce, Object value, Byte expected) |
|
52 |
throws CoercionException { |
|
53 |
assertCoercion(coerce, value, Byte.class, expected); |
|
54 |
} |
|
55 |
|
|
56 |
} |
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.192/org.gvsig.tools.lib/src/test/java/org/gvsig/tools/datatypes/impl/coercion/CoerceToFloatTest.java | ||
---|---|---|
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 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 |
* 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 |
package org.gvsig.tools.datatypes.impl.coercion; |
|
25 |
|
|
26 |
import org.gvsig.tools.dataTypes.CoercionException; |
|
27 |
import org.gvsig.tools.dataTypes.impl.coercion.CoerceToFloat; |
|
28 |
|
|
29 |
/** |
|
30 |
* Unit tests for the {@link CoerceToFloat} class. |
|
31 |
* |
|
32 |
* @author gvSIG Team |
|
33 |
* @version $Id$ |
|
34 |
*/ |
|
35 |
public class CoerceToFloatTest extends CoercionTestAbstract { |
|
36 |
|
|
37 |
public void testCoerce() throws Exception { |
|
38 |
CoerceToFloat coerce = new CoerceToFloat(); |
|
39 |
|
|
40 |
Float float12 = new Float(12.0f); |
|
41 |
|
|
42 |
assertCoercion(coerce, new Integer(12), float12); |
|
43 |
assertCoercion(coerce, new Long(12l), float12); |
|
44 |
assertCoercion(coerce, new Float(12.0f), float12); |
|
45 |
assertCoercion(coerce, new Double(12.0d), float12); |
|
46 |
assertCoercion(coerce, "12", float12); |
|
47 |
assertCoercion(coerce, "12.0", float12); |
|
48 |
assertCoercion(coerce, "0x000C", float12); |
|
49 |
} |
|
50 |
|
|
51 |
private void assertCoercion(CoerceToFloat coerce, Object value, |
|
52 |
Float expected) throws CoercionException { |
|
53 |
assertCoercion(coerce, value, Float.class, expected); |
|
54 |
} |
|
55 |
|
|
56 |
} |
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.192/org.gvsig.tools.lib/src/test/java/org/gvsig/tools/datatypes/impl/coercion/CoerceToStringTest.java | ||
---|---|---|
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 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 |
* 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 |
package org.gvsig.tools.datatypes.impl.coercion; |
|
25 |
|
|
26 |
import org.gvsig.tools.dataTypes.CoercionException; |
|
27 |
import org.gvsig.tools.dataTypes.impl.coercion.CoerceToString; |
|
28 |
|
|
29 |
/** |
|
30 |
* Unit tests for the {@link CoerceToString} class. |
|
31 |
* |
|
32 |
* @author gvSIG Team |
|
33 |
* @version $Id$ |
|
34 |
*/ |
|
35 |
public class CoerceToStringTest extends CoercionTestAbstract { |
|
36 |
|
|
37 |
public void testCoerce() throws Exception { |
|
38 |
CoerceToString coerce = new CoerceToString(); |
|
39 |
|
|
40 |
String string = "123"; |
|
41 |
|
|
42 |
assertCoercion(coerce, string, string); |
|
43 |
assertCoercion(coerce, new StringBuffer(string), string); |
|
44 |
assertCoercion(coerce, Integer.valueOf(string), string); |
|
45 |
} |
|
46 |
|
|
47 |
private void assertCoercion(CoerceToString coerce, Object value, |
|
48 |
String expected) |
|
49 |
throws CoercionException { |
|
50 |
assertCoercion(coerce, value, String.class, expected); |
|
51 |
} |
|
52 |
|
|
53 |
} |
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.192/org.gvsig.tools.lib/src/test/java/org/gvsig/tools/exception/BaseExceptionTest.java | ||
---|---|---|
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 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 |
* 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 |
*/ |
|
27 |
package org.gvsig.tools.exception; |
|
28 |
|
|
29 |
import junit.framework.TestCase; |
|
30 |
|
|
31 |
public class BaseExceptionTest extends TestCase { |
|
32 |
|
|
33 |
protected void setUp() throws Exception { |
|
34 |
super.setUp(); |
|
35 |
} |
|
36 |
|
|
37 |
protected void tearDown() throws Exception { |
|
38 |
super.tearDown(); |
|
39 |
} |
|
40 |
|
|
41 |
public void testSimple(){ |
|
42 |
try { |
|
43 |
throw new NullPointerException("Excepcion de puntero nulo"); |
|
44 |
} catch (NullPointerException e){ |
|
45 |
IBaseException de = createDriverException("SimpleDriver", e); |
|
46 |
assertEquals("Error in the driver SimpleDrivers", de.getMessage()); |
|
47 |
assertEquals( |
|
48 |
"Error in the driver SimpleDrivers\nExcepcion de puntero nulo", |
|
49 |
de.getMessageStack()); |
|
50 |
} |
|
51 |
} |
|
52 |
|
|
53 |
public void testSimpleLocalized(){ |
|
54 |
class MyTranslator implements ExceptionTranslator { |
|
55 |
public String getText(String clave) { |
|
56 |
return clave.toUpperCase(); |
|
57 |
} |
|
58 |
} |
|
59 |
BaseException.setTranslator(new MyTranslator()); |
|
60 |
try { |
|
61 |
throw new NullPointerException("Excepcion de puntero nulo"); |
|
62 |
} catch (NullPointerException e){ |
|
63 |
IBaseException de = createDriverException("SimpleDriver", e); |
|
64 |
assertEquals("ERROR_IN_THE_DRIVER_%(DRIVERNAME)S",de.getLocalizedMessage()); |
|
65 |
assertTrue(de |
|
66 |
.getLocalizedMessageStack() |
|
67 |
.startsWith( |
|
68 |
"ERROR_IN_THE_DRIVER_%(DRIVERNAME)S\nExcepcion de puntero nulo")); |
|
69 |
} |
|
70 |
BaseException.setTranslator(null); |
|
71 |
} |
|
72 |
|
|
73 |
public void testSimple2(){ |
|
74 |
try { |
|
75 |
throw new NullPointerException("Excepcion de puntero nulo"); |
|
76 |
} catch (NullPointerException e){ |
|
77 |
IBaseException de = createBadDateException("SimpleDriver", e); |
|
78 |
assertEquals("Driver SimpleDrivers: Formato de fecha incorrecto", |
|
79 |
de.getMessage()); |
|
80 |
assertEquals( |
|
81 |
"Driver SimpleDrivers: Formato de fecha incorrecto\nExcepcion de puntero nulo", |
|
82 |
de.getMessageStack()); |
|
83 |
} |
|
84 |
} |
|
85 |
|
|
86 |
public void testSimpleLocalized2(){ |
|
87 |
class MyTranslator implements ExceptionTranslator { |
|
88 |
public String getText(String clave) { |
|
89 |
return clave.toUpperCase(); |
|
90 |
} |
|
91 |
} |
|
92 |
BaseException.setTranslator(new MyTranslator()); |
|
93 |
try { |
|
94 |
throw new NullPointerException("Excepcion de puntero nulo"); |
|
95 |
} catch (NullPointerException e){ |
|
96 |
IBaseException de = createBadDateException("SimpleDriver", e); |
|
97 |
assertEquals("DRIVER_%(DRIVERNAME)S_FORMATO_DE_FECHA_INCORRECTO",de.getLocalizedMessage()); |
|
98 |
assertTrue(de |
|
99 |
.getLocalizedMessageStack() |
|
100 |
.startsWith( |
|
101 |
"DRIVER_%(DRIVERNAME)S_FORMATO_DE_FECHA_INCORRECTO\nExcepcion de puntero nulo")); |
|
102 |
} |
|
103 |
BaseException.setTranslator(null); |
|
104 |
} |
|
105 |
|
|
106 |
public void testTranslatorWithoutInterface() { |
|
107 |
class MyTranslator implements ExceptionTranslator { |
|
108 |
public String getText(String clave) { |
|
109 |
return clave.toUpperCase(); |
|
110 |
} |
|
111 |
} |
|
112 |
BaseException.setTranslator(new MyTranslator()); |
|
113 |
try { |
|
114 |
throw new NullPointerException("Excepcion de puntero nulo"); |
|
115 |
} catch (NullPointerException e){ |
|
116 |
IBaseException de = createBadDateException("SimpleDriver", e); |
|
117 |
assertEquals("DRIVER_%(DRIVERNAME)S_FORMATO_DE_FECHA_INCORRECTO",de.getLocalizedMessage()); |
|
118 |
assertTrue(de |
|
119 |
.getLocalizedMessageStack() |
|
120 |
.startsWith( |
|
121 |
"DRIVER_%(DRIVERNAME)S_FORMATO_DE_FECHA_INCORRECTO\nExcepcion de puntero nulo")); |
|
122 |
} |
|
123 |
BaseException.setTranslator(null); |
|
124 |
|
|
125 |
} |
|
126 |
|
|
127 |
public void testInsertBlanksAtStart() { |
|
128 |
String src = "test"; |
|
129 |
|
|
130 |
assertEquals("test", BaseException.insertBlanksAtStart(src, 0)); |
|
131 |
|
|
132 |
assertEquals("test", BaseException.insertBlanksAtStart(src, -5)); |
|
133 |
|
|
134 |
assertEquals(" test", BaseException.insertBlanksAtStart(src, 2)); |
|
135 |
|
|
136 |
assertEquals(" test", BaseException.insertBlanksAtStart(src, 6)); |
|
137 |
} |
|
138 |
|
|
139 |
protected IBaseException createDriverException(String driver, |
|
140 |
Throwable throwable) { |
|
141 |
return new DriverException(driver, throwable); |
|
142 |
} |
|
143 |
|
|
144 |
protected IBaseException createBadDateException(String driver, |
|
145 |
Throwable throwable) { |
|
146 |
return new BadDateException(driver, throwable); |
|
147 |
} |
|
148 |
|
|
149 |
class BadDateException extends DriverException { |
|
150 |
private static final long serialVersionUID = -8985920349210629998L; |
|
151 |
private static final String KEY = "Driver_%(driverName)s_Formato_de_fecha_incorrecto"; |
|
152 |
|
|
153 |
private static final String MESSAGE = "Driver %(driverName)s: Formato de fecha incorrecto"; |
|
154 |
|
|
155 |
public BadDateException(String driverName, Throwable cause) { |
|
156 |
super(driverName, MESSAGE, cause, KEY, serialVersionUID); |
|
157 |
} |
|
158 |
} |
|
159 |
|
|
160 |
} |
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.192/org.gvsig.tools.lib/src/test/java/org/gvsig/tools/exception/DriverException.java | ||
---|---|---|
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 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 |
Also available in: Unified diff