Skip to content

Commit 588b12f

Browse files
committed
More command line tests
1 parent 4c32306 commit 588b12f

File tree

8 files changed

+176
-9
lines changed

8 files changed

+176
-9
lines changed

src/test/java/org/geometrycommands/EllipseCommandTest.java

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* The EllipseCommand UnitTest
1111
* @author Jared Erickson
1212
*/
13-
public class EllipseCommandTest {
13+
public class EllipseCommandTest extends BaseTest {
1414

1515
@Test
1616
public void execute() throws Exception {
@@ -37,4 +37,40 @@ public void execute() throws Exception {
3737
+ "145.22542485937367 108.24429495415053, 150 120))",
3838
writer.getBuffer().toString());
3939
}
40+
41+
@Test
42+
public void run() throws Exception {
43+
// Geometry from options
44+
String result = runApp(new String[]{
45+
"ellipse",
46+
"-g", "POINT (100 100)",
47+
"-w", "50",
48+
"-h", "40",
49+
"-p", "10"
50+
}, null);
51+
assertEquals("POLYGON ((150 120, 145.22542485937367 131.75570504584945, "
52+
+ "132.72542485937367 139.02113032590307, "
53+
+ "117.27457514062631 139.02113032590307, "
54+
+ "104.77457514062633 131.75570504584945, "
55+
+ "100 120, 104.77457514062631 108.24429495415055, "
56+
+ "117.27457514062631 100.97886967409693, "
57+
+ "132.72542485937367 100.97886967409693, "
58+
+ "145.22542485937367 108.24429495415053, 150 120))", result);
59+
60+
// Geometry from input stream
61+
result = runApp(new String[]{
62+
"ellipse",
63+
"-w", "50",
64+
"-h", "40",
65+
"-p", "10"
66+
}, "POINT (100 100)");
67+
assertEquals("POLYGON ((150 120, 145.22542485937367 131.75570504584945, "
68+
+ "132.72542485937367 139.02113032590307, "
69+
+ "117.27457514062631 139.02113032590307, "
70+
+ "104.77457514062633 131.75570504584945, "
71+
+ "100 120, 104.77457514062631 108.24429495415055, "
72+
+ "117.27457514062631 100.97886967409693, "
73+
+ "132.72542485937367 100.97886967409693, "
74+
+ "145.22542485937367 108.24429495415053, 150 120))", result);
75+
}
4076
}

src/test/java/org/geometrycommands/EnvelopeCommandTest.java

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* The EnvelopeCommand UnitTest
1212
* @author Jared Erickson
1313
*/
14-
public class EnvelopeCommandTest {
14+
public class EnvelopeCommandTest extends BaseTest {
1515

1616
@Test
1717
public void execute() throws Exception {
@@ -43,5 +43,22 @@ public void executeWithExpandBy() throws Exception {
4343
command.execute(options, reader, writer);
4444
assertEquals("POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0))", writer.getBuffer().toString());
4545
}
46-
46+
47+
@Test
48+
public void run() throws Exception {
49+
// Geometry from options
50+
String result = runApp(new String[]{
51+
"envelope",
52+
"-g", "POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0))"
53+
}, null);
54+
assertEquals("POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0))", result);
55+
56+
// Geometry from input stream
57+
result = runApp(new String[]{
58+
"envelope",
59+
"-e", "5"
60+
}, "POINT (5 5)");
61+
assertEquals("POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0))", result);
62+
}
63+
4764
}

src/test/java/org/geometrycommands/EqualsCommandTest.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@
66
import java.io.StringWriter;
77
import org.junit.Test;
88
import static org.junit.Assert.assertEquals;
9+
import static org.junit.Assert.assertFalse;
10+
import static org.junit.Assert.assertTrue;
911

1012
/**
1113
* The EqualsCommand UnitTest
1214
* @author Jared Erickson
1315
*/
14-
public class EqualsCommandTest {
16+
public class EqualsCommandTest extends BaseTest {
1517

1618
@Test
1719
public void execute() throws Exception {
@@ -44,4 +46,22 @@ public void execute() throws Exception {
4446
command.execute(options, reader, writer);
4547
assertEquals("false", writer.getBuffer().toString());
4648
}
49+
50+
@Test
51+
public void run() throws Exception {
52+
// Geometry from options
53+
String result = runApp(new String[]{
54+
"equals",
55+
"-g", "POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0))",
56+
"-o", "POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0))"
57+
}, null);
58+
assertTrue(Boolean.parseBoolean(result));
59+
60+
// Geometry from input stream
61+
result = runApp(new String[]{
62+
"equals",
63+
"-o", "POLYGON ((1 1, 1 10, 10 10, 10 1, 1 1))"
64+
}, "POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0))");
65+
assertFalse(Boolean.parseBoolean(result));
66+
}
4767
}

src/test/java/org/geometrycommands/GeometryTypeCommandTest.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* The GeometryTypeCommand UnitTest
1111
* @author Jared Erickson
1212
*/
13-
public class GeometryTypeCommandTest {
13+
public class GeometryTypeCommandTest extends BaseTest {
1414

1515
@Test
1616
public void execute() throws Exception {
@@ -39,4 +39,20 @@ public void execute() throws Exception {
3939
command.execute(options, reader, writer);
4040
assertEquals("Point", writer.getBuffer().toString());
4141
}
42+
43+
@Test
44+
public void run() throws Exception {
45+
// Geometry from options
46+
String result = runApp(new String[]{
47+
"type",
48+
"-g", "POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0))"
49+
}, null);
50+
assertEquals("Polygon", result);
51+
52+
// Geometry from input stream
53+
result = runApp(new String[]{
54+
"type"
55+
}, "POINT (5 5)");
56+
assertEquals("Point", result);
57+
}
4258
}

src/test/java/org/geometrycommands/GetEndPointCommandTest.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* The GetEndPointCommand UnitTest
1111
* @author Jared Erickson
1212
*/
13-
public class GetEndPointCommandTest {
13+
public class GetEndPointCommandTest extends BaseTest {
1414

1515
@Test
1616
public void execute() throws Exception {
@@ -36,4 +36,20 @@ public void execute() throws Exception {
3636
command.execute(options, reader, writer);
3737
assertEquals("POINT (40 40)", writer.getBuffer().toString());
3838
}
39+
40+
@Test
41+
public void run() throws Exception {
42+
// Geometry from options
43+
String result = runApp(new String[]{
44+
"endpoint",
45+
"-g", "LINESTRING (1 1, 5 5, 10 10)"
46+
}, null);
47+
assertEquals("POINT (10 10)", result);
48+
49+
// Geometry from input stream
50+
result = runApp(new String[]{
51+
"endpoint"
52+
}, "MULTILINESTRING ((1 1, 5 5, 10 10), (20 20, 30 30, 40 40))");
53+
assertEquals("POINT (40 40)", result);
54+
}
3955
}

src/test/java/org/geometrycommands/GetGeometryCommandTest.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* The GetGeometryCommand UnitTest
1212
* @author Jared Erickson
1313
*/
14-
public class GetGeometryCommandTest {
14+
public class GetGeometryCommandTest extends BaseTest {
1515

1616
@Test
1717
public void execute() throws Exception {
@@ -40,4 +40,22 @@ public void execute() throws Exception {
4040
command.execute(options, reader, writer);
4141
assertEquals("POINT (10 10)", writer.getBuffer().toString());
4242
}
43+
44+
@Test
45+
public void run() throws Exception {
46+
// Geometry from options
47+
String result = runApp(new String[]{
48+
"get",
49+
"-g", "MULTIPOINT ((0 0), (0 10), (10 10), (10 0))",
50+
"-n", "0"
51+
}, null);
52+
assertEquals("POINT (0 0)", result);
53+
54+
// Geometry from input stream
55+
result = runApp(new String[]{
56+
"get",
57+
"-n", "2"
58+
}, "MULTIPOINT ((0 0), (0 10), (10 10), (10 0))");
59+
assertEquals("POINT (10 10)", result);
60+
}
4361
}

src/test/java/org/geometrycommands/GetStartPointCommandTest.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* The GetStartPointCommand UnitTest
1111
* @author Jared Erickson
1212
*/
13-
public class GetStartPointCommandTest {
13+
public class GetStartPointCommandTest extends BaseTest {
1414

1515
@Test
1616
public void execute() throws Exception {
@@ -36,4 +36,20 @@ public void execute() throws Exception {
3636
command.execute(options, reader, writer);
3737
assertEquals("POINT (1 1)", writer.getBuffer().toString());
3838
}
39+
40+
@Test
41+
public void run() throws Exception {
42+
// Geometry from options
43+
String result = runApp(new String[]{
44+
"startpoint",
45+
"-g", "LINESTRING (1 1, 5 5, 10 10)"
46+
}, null);
47+
assertEquals("POINT (1 1)", result);
48+
49+
// Geometry from input stream
50+
result = runApp(new String[]{
51+
"startpoint"
52+
}, "MULTILINESTRING ((1 1, 5 5, 10 10), (20 20, 30 30, 40 40))");
53+
assertEquals("POINT (1 1)", result);
54+
}
3955
}

src/test/java/org/geometrycommands/GridCommandTest.java

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* The GridCommand UnitTest
1212
* @author Jared Erickson
1313
*/
14-
public class GridCommandTest {
14+
public class GridCommandTest extends BaseTest {
1515

1616
@Test
1717
public void execute() throws Exception {
@@ -33,4 +33,32 @@ public void execute() throws Exception {
3333
+ "POLYGON ((5 5, 5 10, 10 10, 10 5, 5 5)))",
3434
writer.getBuffer().toString());
3535
}
36+
37+
@Test
38+
public void run() throws Exception {
39+
// Geometry from options
40+
String result = runApp(new String[]{
41+
"grid",
42+
"-g", "POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0))",
43+
"-c", "2",
44+
"-r", "2"
45+
}, null);
46+
assertEquals("GEOMETRYCOLLECTION ("
47+
+ "POLYGON ((0 0, 0 5, 5 5, 5 0, 0 0)), "
48+
+ "POLYGON ((5 0, 5 5, 10 5, 10 0, 5 0)), "
49+
+ "POLYGON ((0 5, 0 10, 5 10, 5 5, 0 5)), "
50+
+ "POLYGON ((5 5, 5 10, 10 10, 10 5, 5 5)))", result);
51+
52+
// Geometry from input stream
53+
result = runApp(new String[]{
54+
"grid",
55+
"-c", "2",
56+
"-r", "2"
57+
}, "POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0))");
58+
assertEquals("GEOMETRYCOLLECTION ("
59+
+ "POLYGON ((0 0, 0 5, 5 5, 5 0, 0 0)), "
60+
+ "POLYGON ((5 0, 5 5, 10 5, 10 0, 5 0)), "
61+
+ "POLYGON ((0 5, 0 10, 5 10, 5 5, 0 5)), "
62+
+ "POLYGON ((5 5, 5 10, 10 10, 10 5, 5 5)))", result);
63+
}
3664
}

0 commit comments

Comments
 (0)