package org.geometrycommands;

import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.io.WKTReader;
import org.geometrycommands.RandomCommand.RandomOptions;
import java.io.Reader;
import java.io.StringReader;
import java.io.StringWriter;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

/**
 * The RandomCommand UnitTest
 * @author Jared Erickson
 */
public class RandomCommandTest extends BaseTest {

    @Test
    public void execute() throws Exception {

        String inputGeometry = "POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0))";
        RandomOptions options = new RandomOptions();
        options.setGeometry(inputGeometry);
        options.setNumber(10);

        Reader reader = new StringReader(inputGeometry);
        StringWriter writer = new StringWriter();

        RandomCommand command = new RandomCommand();
        command.execute(options, reader, writer);
        String output = writer.getBuffer().toString();
        Geometry geometry = new WKTReader().read(output);
        assertEquals("MultiPoint", geometry.getGeometryType());
        assertEquals(10, geometry.getNumGeometries());
    }

    @Test
    public void run() throws Exception {
        // Geometry from options
        String result = runApp(new String[]{
                "random",
                "-g", "POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0))",
                "-n", "10"
        }, null);
        Geometry geometry = new WKTReader().read(result);
        assertEquals("MultiPoint", geometry.getGeometryType());
        assertEquals(10, geometry.getNumGeometries());

        // Geometry from input stream
        result = runApp(new String[]{
                "random",
                "-n", "10"
        }, "POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0))");
        geometry = new WKTReader().read(result);
        assertEquals("MultiPoint", geometry.getGeometryType());
        assertEquals(10, geometry.getNumGeometries());
    }
}

@@ -1231,16 +1231,763 @@
 %0A    %7D%0A%0A
+    @Test%0A    public void executeGriddedWithLineString() throws Exception %7B%0A        String inputGeometry = %22LINESTRING (0 0, 10 10)%22;%0A        RandomOptions options = new RandomOptions();%0A        options.setGeometry(inputGeometry);%0A        options.setGridded(true);%0A        options.setNumber(10);%0A%0A        Reader reader = new StringReader(inputGeometry);%0A        StringWriter writer = new StringWriter();%0A%0A        RandomCommand command = new RandomCommand();%0A        command.execute(options, reader, writer);%0A        String output = writer.getBuffer().toString();%0A        Geometry geometry = new WKTReader().read(output);%0A        assertEquals(%22MultiPoint%22, geometry.getGeometryType());%0A        assertEquals(16, geometry.getNumGeometries());%0A    %7D%0A%0A
     @Tes

Increase test coverage of random command