Revision 2283

View differences:

org.gvsig.tools/library/tags/org.gvsig.tools-3.0.244/org.gvsig.tools.lib/src/test/resources/org/gvsig/tools/persistence/BasicTypes2Test.xml
1
<?xml version="1.0"?>
2
<!--
3

  
4
    gvSIG. Desktop Geographic Information System.
5

  
6
    Copyright (C) 2007-2013 gvSIG Association.
7

  
8
    This program is free software; you can redistribute it and/or
9
    modify it under the terms of the GNU General Public License
10
    as published by the Free Software Foundation; either version 2
11
    of the License, or (at your option) any later version.
12

  
13
    This program is distributed in the hope that it will be useful,
14
    but WITHOUT ANY WARRANTY; without even the implied warranty of
15
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
    GNU General Public License for more details.
17

  
18
    You should have received a copy of the GNU General Public License
19
    along with this program; if not, write to the Free Software
20
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21
    MA  02110-1301, USA.
22

  
23
    For any additional information, do not hesitate to contact us
24
    at info AT gvsig.com, or visit our website www.gvsig.com.
25

  
26
-->
27
<definitions version="1.0.0">
28
  <classes>
29
    <class name="MyObjectBasicTypes">
30
      <description>MyObjectBasicTypes Persistence definition</description>
31
      <fields>
32
        <field name="a" type="integer"/>
33
        <field name="b" type="long"/>
34
        <field name="c" type="double"/>
35
        <field name="d" type="float"/>
36
        <field name="e" type="boolean"/>
37
        <field name="f" type="string"/>
38
        <field name="g" type="date"/>
39
      </fields>
40
    </class>
41
    <class name="Extends1Test">
42
      <description>Test the extends with namespace</description>
43
      <extends>
44
      	<class name="MyObjectBasicTypes"/>
45
      </extends>
46
      <fields>
47
      </fields>
48
    </class>
49
    <class name="MyObjectComplexTypes">
50
      <description>Test the extends with namespace</description>
51
      <extends>
52
      	<class name="MyObjectBasicTypes"/>
53
      </extends>
54
      <fields>
55
      	<field name="child" type="dynObject" subtype="MyObjectBasicTypes"></field>
56
      </fields>
57
    </class>
58
  </classes>
59
</definitions>  
0 60

  
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.244/org.gvsig.tools.lib/src/test/resources/org/gvsig/tools/persistence/DynTypesTest.xml
1
<?xml version= "1.0 "?>
2
<!--
3

  
4
    gvSIG. Desktop Geographic Information System.
5

  
6
    Copyright (C) 2007-2013 gvSIG Association.
7

  
8
    This program is free software; you can redistribute it and/or
9
    modify it under the terms of the GNU General Public License
10
    as published by the Free Software Foundation; either version 2
11
    of the License, or (at your option) any later version.
12

  
13
    This program is distributed in the hope that it will be useful,
14
    but WITHOUT ANY WARRANTY; without even the implied warranty of
15
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
    GNU General Public License for more details.
17

  
18
    You should have received a copy of the GNU General Public License
19
    along with this program; if not, write to the Free Software
20
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21
    MA  02110-1301, USA.
22

  
23
    For any additional information, do not hesitate to contact us
24
    at info AT gvsig.com, or visit our website www.gvsig.com.
25

  
26
-->
27
<definitions version="1.0.0">
28
  <classes>
29
    <class name="MyObjectDynTypes">
30
      <description>MyObjectMapType Persistence definition</description>
31
      <fields>
32
      	<field>
33
          <name>mapa</name>
34
          <type>Map</type>
35
          <mandatory>true</mandatory>
36
          <classOfItems>java.lang.String</classOfItems>
37
        </field>
38
      	<field>
39
          <name>conjunto</name>
40
          <type>Set</type>
41
          <mandatory>true</mandatory>
42
          <classOfItems>java.lang.String</classOfItems>
43
        </field>
44
      	<field>
45
          <name>lista</name>
46
          <type>List</type>
47
          <mandatory>true</mandatory>
48
          <classOfItems>java.lang.String</classOfItems>
49
        </field>
50
      	<field>
51
          <name>viewPort</name>
52
          <type>Object</type>
53
          <mandatory>true</mandatory>
54
          <classOfItems>org.gvsig.tools.persistence.case1.model.ViewPort</classOfItems>
55
        </field>
56
      </fields>
57
    </class>
58
  </classes>
59
</definitions>  
0 60

  
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.244/org.gvsig.tools.lib/src/test/resources/org/gvsig/tools/packageutils/package1.info
1
code=org.gvsig.myplugin
2
name=myplugin
3
description=Test
4
version=1.0.0
5
build=1
6
state=RC1
7
official=true
8
type=plugin
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.244/org.gvsig.tools.lib/src/test/resources/org/gvsig/tools/dynobject/attrBasedImportDynClassTest.xml
1
<?xml version="1.0"?>
2
<!--
3

  
4
    gvSIG. Desktop Geographic Information System.
5

  
6
    Copyright (C) 2007-2013 gvSIG Association.
7

  
8
    This program is free software; you can redistribute it and/or
9
    modify it under the terms of the GNU General Public License
10
    as published by the Free Software Foundation; either version 2
11
    of the License, or (at your option) any later version.
12

  
13
    This program is distributed in the hope that it will be useful,
14
    but WITHOUT ANY WARRANTY; without even the implied warranty of
15
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
    GNU General Public License for more details.
17

  
18
    You should have received a copy of the GNU General Public License
19
    along with this program; if not, write to the Free Software
20
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21
    MA  02110-1301, USA.
22

  
23
    For any additional information, do not hesitate to contact us
24
    at info AT gvsig.com, or visit our website www.gvsig.com.
25

  
26
-->
27
<definitions version="1.0.0">
28
  <classes>
29
    <class name="MyObjectBasicTypes">
30
      <description>MyObjectBasicTypes test definition</description>
31
      <fields>
32
        <field	name="a" type="integer" mandatory="true" persistent="true" 
33
        		minValue="0x0" maxValue="100" defaultValue="1"
34
          		group="Numbers" order="12">
35
        </field>
36
        <field	name="b" type="long" mandatory="true" persistent="true" 
37
        		defaultValue="2"
38
          		group="Numbers"/>
39
        <field	name="c" type="double" mandatory="false" persistent="true" 
40
        		defaultValue="1.1" minValue="0.0" maxValue="100.0" 
41
          		group="Numbers"/>
42
        <field	name="d" type="float" mandatory="false" 
43
        		minValue="0.0" maxValue="100.0" 
44
          		group="Numbers">
45
          <persistent>true</persistent>
46
          <defaultValue>1.2</defaultValue>
47
        </field>
48

  
49
        <field	name="e" type="boolean" mandatory="true"> 
50
          <persistent>false</persistent>
51
          <defaultValue>true</defaultValue>
52
          <availableValues>
53
            <value label="True">true</value>
54
            <value label="False">false</value>
55
          </availableValues>
56
        </field>
57

  
58
        <field name="f" type="string" mandatory="true" persistent="true" defaultValue="red">
59
          <availableValues>
60
            <value label="Red">red</value>
61
            <value label="Green">green</value>
62
            <value label="Blue">blue</value>
63
          </availableValues>
64
        </field>
65
        <field name="g" type="date" mandatory="true" persistent="true"/>
66
      </fields>
67
    </class>
68

  
69
    <class name="MyObjectBasicTypes2" namespace="test1">
70
      <extends>
71
        <class name="MyObjectBasicTypes"/>
72
      </extends>
73
      <fields>
74
      </fields>
75
    </class>
76

  
77
    <class name="MyObjectBasicTypes3">
78
      <extends>
79
        <class name="MyObjectBasicTypes2" namespace="test1"/>
80
      </extends>
81
      <fields>
82
      </fields>
83
    </class>
84

  
85
    <class name="MyObjectBasicTypes4">
86
      <extends>
87
        <class name="MyObjectBasicTypes2" namespace="test1"/>
88
      </extends>
89
      <fields>
90
        <field	name="obj" type="Object" classOfValue="org.gvsig.tools.evaluator.Evaluator"/>
91
        <field	name="objs" type="List" classOfItems="org.gvsig.tools.visitor.Visitor"/>
92
      </fields>
93
    </class>
94

  
95
  </classes>
96
</definitions>  
0 97

  
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.244/org.gvsig.tools.lib/src/test/resources/org/gvsig/tools/dynobject/tagBasedImportDynClassTest.xml
1
<?xml version="1.0" encoding="UTF-8" ?>
2
<!--
3

  
4
    gvSIG. Desktop Geographic Information System.
5

  
6
    Copyright (C) 2007-2013 gvSIG Association.
7

  
8
    This program is free software; you can redistribute it and/or
9
    modify it under the terms of the GNU General Public License
10
    as published by the Free Software Foundation; either version 2
11
    of the License, or (at your option) any later version.
12

  
13
    This program is distributed in the hope that it will be useful,
14
    but WITHOUT ANY WARRANTY; without even the implied warranty of
15
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
    GNU General Public License for more details.
17

  
18
    You should have received a copy of the GNU General Public License
19
    along with this program; if not, write to the Free Software
20
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21
    MA  02110-1301, USA.
22

  
23
    For any additional information, do not hesitate to contact us
24
    at info AT gvsig.com, or visit our website www.gvsig.com.
25

  
26
-->
27
<definitions>
28
  <version>1.0.0</version>
29
  <classes>
30
    <class>
31
      <name>MyObjectBasicTypes</name>
32
      <description>MyObjectBasicTypes test definition</description>
33
      <fields>
34
        <field>
35
          <name>a</name>
36
          <type>integer</type>
37
          <mandatory>true</mandatory>
38
          <persistent>true</persistent>
39
          <minValue>0</minValue>
40
          <maxValue>100</maxValue>
41
          <defaultValue>1</defaultValue>
42
          <group>Numbers</group>
43
          <order>12</order>
44
        </field>
45
        <field>
46
          <name>b</name>
47
          <type>long</type>
48
          <mandatory>true</mandatory>
49
          <persistent>true</persistent>
50
          <defaultValue>2</defaultValue>
51
          <group>Numbers</group>
52
        </field>
53
        <field>
54
          <name>c</name>
55
          <type>double</type>
56
          <mandatory>false</mandatory>
57
          <persistent>true</persistent>
58
          <minValue>0.0</minValue>
59
          <maxValue>100.0</maxValue>
60
          <defaultValue>1.1</defaultValue>
61
          <group>Numbers</group>
62
        </field>
63
        <field>
64
          <name>d</name>
65
          <type>float</type>
66
          <mandatory>false</mandatory>
67
          <persistent>true</persistent>
68
          <defaultValue>1.2</defaultValue>
69
          <group>Numbers</group>
70
        </field>
71
        <field>
72
          <name>e</name>
73
          <type>boolean</type>
74
          <mandatory>true</mandatory>
75
          <persistent>false</persistent>
76
          <defaultValue>true</defaultValue>
77
          <availableValues>
78
            <valueItem>
79
              <label>True</label>
80
              <value>true</value>
81
            </valueItem>
82
            <valueItem>
83
              <label>False</label>
84
              <value>false</value>
85
            </valueItem>
86
          </availableValues>
87
        </field>
88
        <field>
89
          <name>f</name>
90
          <type>string</type>
91
          <mandatory>true</mandatory>
92
          <persistent>true</persistent>
93
          <defaultValue>red</defaultValue>
94
          <availableValues>
95
            <valueItem>
96
              <label>Red</label>
97
              <value>red</value>
98
            </valueItem>
99
            <valueItem>
100
              <label>Green</label>
101
              <value>green</value>
102
            </valueItem>
103
            <valueItem>
104
              <label>Blue</label>
105
              <value>blue</value>
106
            </valueItem>
107
          </availableValues>
108
        </field>
109
        <field>
110
          <name>g</name>
111
          <type>date</type>
112
          <mandatory>true</mandatory>
113
          <persistent>true</persistent>
114
        </field>
115
      </fields>
116
    </class>
117

  
118

  
119
    <class name="MyObjectBasicTypes2" namespace="test1">
120
      <extends>
121
        <class>MyObjectBasicTypes</class>
122
      </extends>
123
      <fields>
124
      </fields>
125
    </class>
126

  
127
    <class name="MyObjectBasicTypes3">
128
      <extends>
129
        <class namespace="test1">MyObjectBasicTypes2</class> 
130
      </extends>
131
      <fields>
132
      </fields>
133
    </class>
134

  
135
    <class name="MyObjectBasicTypes4">
136
      <extends>
137
        <class name="MyObjectBasicTypes2" namespace="test1"/>
138
      </extends>
139
      <fields>
140
        <field>
141
          <name>obj</name>
142
          <type>Object</type>
143
          <classOfValue>org.gvsig.tools.evaluator.Evaluator</classOfValue>
144
        </field>
145
        <field>
146
          <name>objs</name>
147
          <type>List</type>
148
          <classOfItems>org.gvsig.tools.visitor.Visitor</classOfItems>
149
        </field>
150
      </fields>
151
    </class>
152

  
153

  
154
  </classes>
155
</definitions>
0 156

  
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.244/org.gvsig.tools.lib/src/test/resources/org/gvsig/tools/dynobject/DynClassTemplate.xml
1
<?xml version="1.0"?>
2
<!--
3

  
4
    gvSIG. Desktop Geographic Information System.
5

  
6
    Copyright (C) 2007-2013 gvSIG Association.
7

  
8
    This program is free software; you can redistribute it and/or
9
    modify it under the terms of the GNU General Public License
10
    as published by the Free Software Foundation; either version 2
11
    of the License, or (at your option) any later version.
12

  
13
    This program is distributed in the hope that it will be useful,
14
    but WITHOUT ANY WARRANTY; without even the implied warranty of
15
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
    GNU General Public License for more details.
17

  
18
    You should have received a copy of the GNU General Public License
19
    along with this program; if not, write to the Free Software
20
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21
    MA  02110-1301, USA.
22

  
23
    For any additional information, do not hesitate to contact us
24
    at info AT gvsig.com, or visit our website www.gvsig.com.
25

  
26
-->
27
<definitions>
28
  <version>1.0.0</version>
29
  <classes>
30
    <class>
31
      <name></name>
32
      <namespace></namespace>
33
      <description></description>
34
      <superClassNames>
35
        <superClassName></superClassName>
36
        <superClassName></superClassName>
37
      </superClassNames>
38
      <fields>
39
        <field>
40
          <name></name>
41
          <type></type>
42
          <subtype></subtype>
43
          <description></description>
44
          <isMandatory></isMandatory>
45
          <isPersistent></isPersistent>
46
          <minValue></minValue>
47
          <maxValue></maxValue>
48
          <classOfValue></classOfValue>
49
          <defaultValue></defaultValue>
50
          <group></group>
51
          <availableValues>
52
            <valueItem>
53
              <label></label>
54
              <value></value>
55
            </valueItem>
56
            <valueItem>
57
              <label></label>
58
              <value></value>
59
            </valueItem>
60
          </availableValues>
61
        </field>
62
      </fields>
63
    </class>
64
  </classes>
65
</definitions>  
0 66

  
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.244/org.gvsig.tools.lib/src/test/resources/README.txt
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
#set( $symbol_pound = '#' )
26
#set( $symbol_dollar = '$' )
27
#set( $symbol_escape = '\' )
28
Put into this folder the resources needed by your test classes.
29

  
30
This folder is added to the Tests classpath, so you can load any resources 
31
through the ClassLoader.
32

  
33
By default, in this folder you can find an example of log4j configuration,
34
prepared to log messages through the console, so logging works when you
35
run your tests classes.
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.244/org.gvsig.tools.lib/src/test/resources/log4j.xml
1
<?xml version="1.0" encoding="UTF-8" ?>
2
<!--
3

  
4
    gvSIG. Desktop Geographic Information System.
5

  
6
    Copyright (C) 2007-2013 gvSIG Association.
7

  
8
    This program is free software; you can redistribute it and/or
9
    modify it under the terms of the GNU General Public License
10
    as published by the Free Software Foundation; either version 2
11
    of the License, or (at your option) any later version.
12

  
13
    This program is distributed in the hope that it will be useful,
14
    but WITHOUT ANY WARRANTY; without even the implied warranty of
15
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
    GNU General Public License for more details.
17

  
18
    You should have received a copy of the GNU General Public License
19
    along with this program; if not, write to the Free Software
20
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21
    MA  02110-1301, USA.
22

  
23
    For any additional information, do not hesitate to contact us
24
    at info AT gvsig.com, or visit our website www.gvsig.com.
25

  
26
-->
27
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
28

  
29
<!-- 
30
Log4J configuration file for unit tests execution.
31
 -->
32
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
33

  
34
	<!-- Appender configuration to show logging messages through the console -->
35
	<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
36
		<layout class="org.apache.log4j.PatternLayout">
37
			<param name="ConversionPattern" value="%d{HH:mm:ss,SSS} %-5p [%c{2}.%M()]  %m%n" />
38
		</layout>
39
	</appender>
40

  
41
	<!-- 
42
	Activate logging messages of DEBUG level of higher only for the
43
	org.gvsig.tools packages.
44
	You can put full classes names or packages instead, to configure
45
	logging for all the classes and subpackages of the package.
46
	-->
47
	<category name="org.gvsig.tools">
48
		<priority value="TRACE" />
49
	</category>
50

  
51
	<!-- 
52
	By default, show only logging messages of INFO level or higher, 
53
	through the previously configured CONSOLE appender. 
54
	-->
55
	<root>
56
		<priority value="TRACE" />
57
		<appender-ref ref="CONSOLE" />
58
	</root>
59
</log4j:configuration>
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.244/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.244/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.244/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.Coercion;
32
import org.gvsig.tools.dataTypes.impl.coercion.CoerceToDate;
33
import org.gvsig.tools.dataTypes.impl.coercion.CoerceToTimestamp;
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
        CoerceToTimestamp coerce = new CoerceToTimestamp();
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.244/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.244/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.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.244/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.244/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.244/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.244/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.244/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.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.244/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.244/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.244/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.244/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
}
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff