1 package org.geojson; 2 3 import org.junit.Test; 4 5 import java.util.Arrays; 6 7 import static org.junit.Assert.assertEquals; 8 9 public class ToStringTest { 10 11 @Test itShouldToStringCrs()12 public void itShouldToStringCrs() throws Exception { 13 assertEquals("Crs{type='name', properties={}}", new Crs().toString()); 14 } 15 16 @Test itShouldToStringFeature()17 public void itShouldToStringFeature() throws Exception { 18 assertEquals("Feature{properties={}, geometry=null, id='null'}", new Feature().toString()); 19 } 20 21 @Test itShouldToStringFeatureCollection()22 public void itShouldToStringFeatureCollection() throws Exception { 23 assertEquals("FeatureCollection{features=[]}", new FeatureCollection().toString()); 24 } 25 26 @Test itShouldToStringPoint()27 public void itShouldToStringPoint() throws Exception { 28 Point geometry = new Point(10, 20); 29 assertEquals( 30 "Point{coordinates=LngLatAlt{longitude=10.0, latitude=20.0, altitude=NaN}} GeoJsonObject{}", 31 geometry.toString()); 32 } 33 34 @Test itShouldToStringPointWithAdditionalElements()35 public void itShouldToStringPointWithAdditionalElements() { 36 Point geometry = new Point(10, 20, 30, 40D, 50D); 37 assertEquals( 38 "Point{coordinates=LngLatAlt{longitude=10.0, latitude=20.0, altitude=30.0, additionalElements=[40.0, 50.0]}} GeoJsonObject{}", 39 geometry.toString()); 40 } 41 42 @Test itShouldToStringPointWithAdditionalElementsAndIgnoreNulls()43 public void itShouldToStringPointWithAdditionalElementsAndIgnoreNulls() { 44 Point geometry = new Point(10, 20, 30, 40D, 50D); 45 assertEquals( 46 "Point{coordinates=LngLatAlt{longitude=10.0, latitude=20.0, altitude=30.0, additionalElements=[40.0, 50.0]}} GeoJsonObject{}", 47 geometry.toString()); 48 } 49 50 @Test itShouldToStringPolygon()51 public void itShouldToStringPolygon() throws Exception { 52 Polygon geometry = new Polygon(new LngLatAlt(10, 20), new LngLatAlt(30, 40), new LngLatAlt(10, 40), 53 new LngLatAlt(10, 20)); 54 assertEquals( 55 "Polygon{} Geometry{coordinates=[[LngLatAlt{longitude=10.0, latitude=20.0, altitude=NaN}, " 56 + "LngLatAlt{longitude=30.0, latitude=40.0, altitude=NaN}, LngLatAlt{longitude=10.0, latitude=40.0, altitude=NaN}, " 57 + "LngLatAlt{longitude=10.0, latitude=20.0, altitude=NaN}]]} GeoJsonObject{}", 58 geometry.toString()); 59 } 60 61 @Test itShouldToStringMultiPolygon()62 public void itShouldToStringMultiPolygon() throws Exception { 63 MultiPolygon geometry = new MultiPolygon(new Polygon(new LngLatAlt(10, 20), new LngLatAlt(30, 40), 64 new LngLatAlt(10, 40), new LngLatAlt(10, 20))); 65 geometry.add(new Polygon(new LngLatAlt(5, 20), new LngLatAlt(30, 40), new LngLatAlt(10, 40), new LngLatAlt(5, 66 20))); 67 assertEquals("MultiPolygon{} Geometry{coordinates=[[[LngLatAlt{longitude=10.0, latitude=20.0, altitude=NaN}, " 68 + "LngLatAlt{longitude=30.0, latitude=40.0, altitude=NaN}, " 69 + "LngLatAlt{longitude=10.0, latitude=40.0, altitude=NaN}, " 70 + "LngLatAlt{longitude=10.0, latitude=20.0, altitude=NaN}]], " 71 + "[[LngLatAlt{longitude=5.0, latitude=20.0, altitude=NaN}, " 72 + "LngLatAlt{longitude=30.0, latitude=40.0, altitude=NaN}, " 73 + "LngLatAlt{longitude=10.0, latitude=40.0, altitude=NaN}, " 74 + "LngLatAlt{longitude=5.0, latitude=20.0, altitude=NaN}]]]} GeoJsonObject{}", 75 geometry.toString()); 76 } 77 78 @Test itShouldToStringLineString()79 public void itShouldToStringLineString() throws Exception { 80 LineString geometry = new LineString(new LngLatAlt(49, 9), new LngLatAlt(41, 1)); 81 assertEquals("LineString{} MultiPoint{} Geometry{coordinates=[" 82 + "LngLatAlt{longitude=49.0, latitude=9.0, altitude=NaN}, " 83 + "LngLatAlt{longitude=41.0, latitude=1.0, altitude=NaN}]} GeoJsonObject{}", 84 geometry.toString()); 85 } 86 87 @Test itShouldToStringMultiLineString()88 public void itShouldToStringMultiLineString() throws Exception { 89 MultiLineString geometry = new MultiLineString(Arrays.asList(new LngLatAlt(49, 9), new LngLatAlt(41, 1))); 90 geometry.add(Arrays.asList(new LngLatAlt(10, 20), new LngLatAlt(30, 40))); 91 assertEquals("MultiLineString{} Geometry{coordinates=[[LngLatAlt{longitude=49.0, latitude=9.0, altitude=NaN}, " 92 + "LngLatAlt{longitude=41.0, latitude=1.0, altitude=NaN}], " 93 + "[LngLatAlt{longitude=10.0, latitude=20.0, altitude=NaN}, " 94 + "LngLatAlt{longitude=30.0, latitude=40.0, altitude=NaN}]]} GeoJsonObject{}", 95 geometry.toString()); 96 } 97 } 98