package ucar.nc2.ft2.simpgeometry;

import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
import static ucar.nc2.ft2.simpgeometry.GeometryType.LINE;
import static ucar.nc2.ft2.simpgeometry.GeometryType.POINT;
import static ucar.nc2.ft2.simpgeometry.GeometryType.POLYGON;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.junit.Assert;
import org.junit.Test;
import ucar.ma2.DataType;
import ucar.ma2.InvalidRangeException;
import ucar.nc2.Attribute;
import ucar.nc2.ft2.simpgeometry.adapter.SimpleGeometryCS;

public class TestSimpleGeometryFeature {

  private String name = "name";
  private DataType dt;
  private List<Attribute> att = new ArrayList<Attribute>();
  private String coordSysName = "coordsysname";
  private String units = "units";
  private String description = "desc";
  private Object user;
  private GeometryType geometry;



  @Test(expected = RuntimeException.class)
  public void testSetCoordSysNull() {
    SimpleGeometryFeature cov =
        new SimpleGeometryFeature(name, dt, att, coordSysName, units, description, user, geometry);
    SimpleGeometryCS cs = mock(SimpleGeometryCS.class);
    cov.setCoordSys(cs);
    cov.setCoordSys(cov.getCoordSys());
  }

  @Test
  public void testReadPoint() throws IOException, InvalidRangeException {

    int index = 1;
    SimpleGeometryCS cs = mock(SimpleGeometryCS.class);

    Point point = mock(CFPoint.class);
    given(cs.getPoint(name, index)).willReturn(point);
    SimpleGeometryFeature cov = new SimpleGeometryFeature(name, dt, att, coordSysName, units, description, user, POINT);
    cov.setCoordSys(cs);
    Assert.assertEquals(cov.readGeometry(index), cs.getPoint(name, index));
  }

  @Test
  public void testReadLine() throws IOException, InvalidRangeException {

    int index = 1;
    SimpleGeometryCS cs = mock(SimpleGeometryCS.class);

    Line line = mock(CFLine.class);
    given(cs.getLine(name, index)).willReturn(line);
    SimpleGeometryFeature cov = new SimpleGeometryFeature(name, dt, att, coordSysName, units, description, user, LINE);
    cov.setCoordSys(cs);
    Assert.assertEquals(cov.readGeometry(index), cs.getLine(name, index));

  }

  @Test
  public void testReadPolygon() throws IOException, InvalidRangeException {

    int index = 1;
    SimpleGeometryCS cs = mock(SimpleGeometryCS.class);

    Polygon polygon = mock(CFPolygon.class);
    given(cs.getPolygon(name, index)).willReturn(polygon);
    SimpleGeometryFeature cov =
        new SimpleGeometryFeature(name, dt, att, coordSysName, units, description, user, POLYGON);
    cov.setCoordSys(cs);
    Assert.assertEquals(cov.readGeometry(index), cs.getPolygon(name, index));

  }



}

@@ -326,59 +326,8 @@
 on;%0A
-import java.util.ArrayList;%0Aimport java.util.List;%0A
 impo
@@ -347,16 +347,16 @@
 Assert;%0A
+
 import o
@@ -460,16 +460,68 @@
 ttribute
+Container;%0Aimport ucar.nc2.AttributeContainerMutable
 ;%0Aimport
@@ -681,21 +681,16 @@
 private 
-List%3C
 Attribut
@@ -690,17 +690,25 @@
 ttribute
-%3E
+Container
  att = n
@@ -715,28 +715,39 @@
 ew A
-rrayList%3CAttribute%3E(
+ttributeContainerMutable(%22name%22
 );%0A 
@@ -889,16 +889,16 @@
 t user;%0A
+
   privat
@@ -923,18 +923,16 @@
 metry;%0A%0A
-%0A%0A
   @Test(
@@ -2719,13 +2719,10 @@
 );%0A%0A  %7D%0A
-%0A%0A%0A
 %7D%0A

fix test