dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #06529
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 2088: Fix testing of orgunit coordinates
------------------------------------------------------------
revno: 2088
committer: Lars <larshelg@larshelg-laptop>
branch nick: trunk
timestamp: Mon 2010-07-05 19:05:39 +0200
message:
Fix testing of orgunit coordinates
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnit.java
dhis-2/dhis-api/src/test/java/org/hisp/dhis/organisationunit/OrganisationUnitTest.java
--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk
Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnit.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnit.java 2010-06-30 23:49:01 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnit.java 2010-07-05 17:05:39 +0000
@@ -49,7 +49,7 @@
{
private static final Pattern JSON_COORDINATE_PATTERN = Pattern.compile( "(\\[{3}.*?\\]{3})" );
- private static final Pattern GML_COORDINATE_PATTERN = Pattern.compile("[\\-0-9.]+,[\\-0-9.]+");
+ private static final Pattern GML_COORDINATE_PATTERN = Pattern.compile("([\\-0-9.]+,[\\-0-9.]+)");
private Set<OrganisationUnit> children = new HashSet<OrganisationUnit>();
@@ -186,11 +186,11 @@
{
builder.append( "[[" );
- Matcher matcher = GML_COORDINATE_PATTERN.matcher(c);
+ Matcher matcher = GML_COORDINATE_PATTERN.matcher( c );
- while(matcher.find())
+ while ( matcher.find() )
{
- builder.append("[" + c.subSequence( matcher.start(), matcher.end()) + "]," );
+ builder.append( "[" + matcher.group() + "]," );
}
builder.deleteCharAt( builder.lastIndexOf( "," ) );
=== modified file 'dhis-2/dhis-api/src/test/java/org/hisp/dhis/organisationunit/OrganisationUnitTest.java'
--- dhis-2/dhis-api/src/test/java/org/hisp/dhis/organisationunit/OrganisationUnitTest.java 2010-06-30 23:49:01 +0000
+++ dhis-2/dhis-api/src/test/java/org/hisp/dhis/organisationunit/OrganisationUnitTest.java 2010-07-05 17:05:39 +0000
@@ -35,7 +35,6 @@
import java.util.List;
import org.junit.Before;
-import org.junit.Ignore;
import org.junit.Test;
/**
@@ -43,23 +42,32 @@
*/
public class OrganisationUnitTest
{
- private List<String> coordinatesCollection = new ArrayList<String>();
+ private List<String> dirtyCoordinatesCollection = new ArrayList<String>();
+ private List<String> cleanCoordinatesCollection = new ArrayList<String>();
private String coordinates = "[[[[11.11,22.22],[33.33,44.44],[55.55,66.66]]],[[[77.77,88.88],[99.99,11.11],[22.22,33.33]]],[[[44.44,55.55],[66.66,77.77],[88.88,99.99]]]]";
@Before
public void before()
{
- coordinatesCollection.add( "11.11,22.22 33.33,44.44 55.55,66.66" ); // extra space between coords
- coordinatesCollection.add( "77.77,88.88 99.99,11.11\n22.22,33.33" ); // newline between coords
- coordinatesCollection.add( " 44.44,55.55 66.66,77.77 88.88,99.99 " ); // leading and trailing space
- }
-
-
+ dirtyCoordinatesCollection.add( "11.11,22.22 33.33,44.44 55.55,66.66" ); // Extra space between coords
+ dirtyCoordinatesCollection.add( "77.77,88.88 99.99,11.11\n22.22,33.33" ); // Newline between coords
+ dirtyCoordinatesCollection.add( " 44.44,55.55 66.66,77.77 88.88,99.99 " ); // Leading and trailing space
+
+ cleanCoordinatesCollection.add( "11.11,22.22 33.33,44.44 55.55,66.66" ); // Testing on string since we control the output format
+ cleanCoordinatesCollection.add( "77.77,88.88 99.99,11.11 22.22,33.33" );
+ cleanCoordinatesCollection.add( "44.44,55.55 66.66,77.77 88.88,99.99" );
+ }
+
+ @Test
+ public void testSetCoordinatesFromCollection()
+ {
+ OrganisationUnit unit = new OrganisationUnit();
+ unit.setCoordinatesFromCollection( dirtyCoordinatesCollection );
+
+ assertEquals( coordinates, unit.getCoordinates() );
+ }
- // ignore this test as it depends on literal strings being equal rather than containing the same points
- // TODO: create a new test
- @Ignore
@Test
public void testGetCoordinatesAsCollection()
{
@@ -69,17 +77,8 @@
Collection<String> actual = unit.getCoordinatesAsCollection();
assertEquals( 3, actual.size() );
- assertTrue( actual.contains( coordinatesCollection.get( 0 ) ) );
- assertTrue( actual.contains( coordinatesCollection.get( 1 ) ) );
- assertTrue( actual.contains( coordinatesCollection.get( 2 ) ) );
- }
-
- @Test
- public void testSetCoordinatesFromCollection()
- {
- OrganisationUnit unit = new OrganisationUnit();
- unit.setCoordinatesFromCollection( coordinatesCollection );
-
- assertEquals( coordinates, unit.getCoordinates() );
- }
+ assertTrue( actual.contains( cleanCoordinatesCollection.get( 0 ) ) );
+ assertTrue( actual.contains( cleanCoordinatesCollection.get( 1 ) ) );
+ assertTrue( actual.contains( cleanCoordinatesCollection.get( 2 ) ) );
+ }
}