|
| 1 | +package ucar.nc2.ft2.simpgeometry; |
| 2 | + |
| 3 | +import static org.mockito.BDDMockito.given; |
| 4 | +import static org.mockito.Mockito.mock; |
| 5 | +import static ucar.nc2.ft2.simpgeometry.GeometryType.LINE; |
| 6 | +import static ucar.nc2.ft2.simpgeometry.GeometryType.POINT; |
| 7 | +import static ucar.nc2.ft2.simpgeometry.GeometryType.POLYGON; |
| 8 | + |
| 9 | +import java.io.IOException; |
| 10 | +import java.util.ArrayList; |
| 11 | +import java.util.List; |
| 12 | +import org.junit.Assert; |
| 13 | +import org.junit.Test; |
| 14 | +import ucar.ma2.DataType; |
| 15 | +import ucar.ma2.InvalidRangeException; |
| 16 | +import ucar.nc2.Attribute; |
| 17 | +import ucar.nc2.ft2.simpgeometry.adapter.SimpleGeometryCS; |
| 18 | + |
| 19 | +public class TestSimpleGeometryFeature { |
| 20 | + |
| 21 | + private String name = "name"; |
| 22 | + private DataType dt; |
| 23 | + private List<Attribute> att = new ArrayList<Attribute>(); |
| 24 | + private String coordSysName = "coordsysname"; |
| 25 | + private String units = "units"; |
| 26 | + private String description = "desc"; |
| 27 | + private Object user; |
| 28 | + private GeometryType geometry; |
| 29 | + |
| 30 | + |
| 31 | + |
| 32 | + @Test (expected = RuntimeException.class) |
| 33 | + public void testSetCoordSysNull() { |
| 34 | + SimpleGeometryFeature cov = new SimpleGeometryFeature(name, dt, att, coordSysName, units, description, user, geometry); |
| 35 | + SimpleGeometryCS cs = mock(SimpleGeometryCS.class); |
| 36 | + cov.setCoordSys(cs); |
| 37 | + cov.setCoordSys(cov.getCoordSys()); |
| 38 | + } |
| 39 | + |
| 40 | + @Test |
| 41 | + public void testReadPoint() throws IOException, InvalidRangeException { |
| 42 | + |
| 43 | + int index = 1; |
| 44 | + SimpleGeometryCS cs = mock(SimpleGeometryCS.class); |
| 45 | + |
| 46 | + Point point = mock(CFPoint.class); |
| 47 | + given(cs.getPoint(name, index)).willReturn(point); |
| 48 | + SimpleGeometryFeature cov = new SimpleGeometryFeature(name, dt, att, coordSysName, units, description, user, POINT); |
| 49 | + cov.setCoordSys(cs); |
| 50 | + Assert.assertEquals(cov.readGeometry(index), cs.getPoint(name, index)); |
| 51 | + } |
| 52 | + |
| 53 | + @Test |
| 54 | + public void testReadLine() throws IOException, InvalidRangeException { |
| 55 | + |
| 56 | + int index = 1; |
| 57 | + SimpleGeometryCS cs = mock(SimpleGeometryCS.class); |
| 58 | + |
| 59 | + Line line = mock(CFLine.class); |
| 60 | + given(cs.getLine(name, index)).willReturn(line); |
| 61 | + SimpleGeometryFeature cov = new SimpleGeometryFeature(name, dt, att, coordSysName, units, description, user, LINE); |
| 62 | + cov.setCoordSys(cs); |
| 63 | + Assert.assertEquals(cov.readGeometry(index), cs.getLine(name, index)); |
| 64 | + |
| 65 | + } |
| 66 | + |
| 67 | + @Test |
| 68 | + public void testReadPolygon() throws IOException, InvalidRangeException { |
| 69 | + |
| 70 | + int index = 1; |
| 71 | + SimpleGeometryCS cs = mock(SimpleGeometryCS.class); |
| 72 | + |
| 73 | + Polygon polygon = mock(CFPolygon.class); |
| 74 | + given(cs.getPolygon(name, index)).willReturn(polygon); |
| 75 | + SimpleGeometryFeature cov = new SimpleGeometryFeature(name, dt, att, coordSysName, units, description, user, POLYGON); |
| 76 | + cov.setCoordSys(cs); |
| 77 | + Assert.assertEquals(cov.readGeometry(index), cs.getPolygon(name, index)); |
| 78 | + |
| 79 | + } |
| 80 | + |
| 81 | + |
| 82 | + |
| 83 | +} |
0 commit comments