Skip to content

Commit b7f39a9

Browse files
committed
Improve test coverage
1 parent 67cf08e commit b7f39a9

24 files changed

+409
-9
lines changed

src/main/java/org/geometrycommands/App.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
/**
1313
* The command line application
14-
*
1514
* @author Jared Erickson
1615
*/
1716
public class App {

src/main/java/org/geometrycommands/GetEndPointCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public GetEndPointOptions getOptions() {
5353
@Override
5454
protected void processGeometry(Geometry geometry, GetEndPointOptions options, Reader reader, Writer writer) throws Exception {
5555
if (!(geometry instanceof Lineal)) {
56-
throw new IllegalArgumentException("The input geometry a LineString or a MultiLineString!");
56+
throw new IllegalArgumentException("The input geometry must be a LineString or a MultiLineString!");
5757
}
5858
LineString lineString;
5959
if (geometry instanceof MultiLineString) {

src/main/java/org/geometrycommands/GetStartPointCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public GetStartPointOptions getOptions() {
5353
@Override
5454
protected void processGeometry(Geometry geometry, GetStartPointOptions options, Reader reader, Writer writer) throws Exception {
5555
if (!(geometry instanceof Lineal)) {
56-
throw new IllegalArgumentException("The input geometry a LineString or a MultiLineString!");
56+
throw new IllegalArgumentException("The input geometry must be a LineString or a MultiLineString!");
5757
}
5858
LineString lineString;
5959
if (geometry instanceof MultiLineString) {

src/main/java/org/geometrycommands/InterpolatePointCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public InterpolatePointOptions getOptions() {
5757
@Override
5858
protected void processGeometry(Geometry geometry, InterpolatePointOptions options, Reader reader, Writer writer) throws Exception {
5959
if (!(geometry instanceof Lineal)) {
60-
throw new IllegalArgumentException("The input geometry a LineString or a MultiLineString!");
60+
throw new IllegalArgumentException("The input geometry must be a LineString or a MultiLineString!");
6161
}
6262
LengthIndexedLine indexedLine = new LengthIndexedLine(geometry);
6363
double length = geometry.getLength();

src/main/java/org/geometrycommands/IsClosedCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public IsClosedOptions getOptions() {
5252
@Override
5353
protected void processGeometry(Geometry geometry, IsClosedOptions options, Reader reader, Writer writer) throws Exception {
5454
if (!(geometry instanceof Lineal)) {
55-
throw new IllegalArgumentException("Input geometry must be a LineString or a MultiLineString!");
55+
throw new IllegalArgumentException("The input geometry must be a LineString or a MultiLineString!");
5656
}
5757
boolean closed = false;
5858
if (geometry instanceof LineString) {

src/main/java/org/geometrycommands/IsRingCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public IsRingOptions getOptions() {
5050
@Override
5151
protected void processGeometry(Geometry geometry, IsRingOptions options, Reader reader, Writer writer) throws Exception {
5252
if (!(geometry instanceof LineString)) {
53-
throw new IllegalArgumentException("Input geometry must be a LineString!");
53+
throw new IllegalArgumentException("The input geometry must be a LineString!");
5454
}
5555
boolean isRing = ((LineString) geometry).isRing();
5656
writer.write(String.valueOf(isRing));

src/main/java/org/geometrycommands/LocatePointCommand.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,13 @@ protected void processGeometries(Geometry geometry, Geometry other, LocatePointO
5858

5959
if (geometry instanceof Point) {
6060
point = (Point)geometry;
61-
}else if (other instanceof Point) {
61+
} else if (other instanceof Point) {
6262
point = (Point)other;
6363
}
64+
6465
if (geometry instanceof Lineal) {
6566
line = geometry;
66-
}else if (other instanceof Lineal) {
67+
} else if (other instanceof Lineal) {
6768
line = other;
6869
}
6970

src/test/java/org/geometrycommands/AppTest.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,26 @@ public void testHelp() {
6262
+ " -g (--geometry) VAL : The input geometry", values.get("out"));
6363
}
6464

65+
@Test
66+
public void testHelpWhenRequiredArgsNotPresent() {
67+
CaptureOutput capture = CaptureOutput.createAndStart();
68+
try {
69+
App.main(new String[]{
70+
"buffer", "--help"
71+
});
72+
} catch (OverrideExitException ex) {
73+
}
74+
Map<String, String> values = capture.stop();
75+
assertEquals("geom buffer: Buffer a geometry by a distance." + NEW_LINE +
76+
" --help : Print help message" + NEW_LINE +
77+
" -c (--endCapStyle) VAL : The end cap style (round, flat/butt, square)" + NEW_LINE +
78+
" -d (--distance) N : The buffer distance" + NEW_LINE +
79+
" -g (--geometry) VAL : The input geometry" + NEW_LINE +
80+
" -q (--quadrantSegments) N : The number of quadrant segments" + NEW_LINE +
81+
" -s (--singleSided) : The flag for whether the buffer should be single" + NEW_LINE +
82+
" sided", values.get("out"));
83+
}
84+
6585
@Test
6686
public void testArgumentError() {
6787
CaptureOutput capture = CaptureOutput.createAndStart();

src/test/java/org/geometrycommands/ArcCommandTest.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public void execute() throws Exception {
2424
options.setWidth(50);
2525
options.setHeight(50);
2626
options.setNumberOfPoints(10);
27+
options.setDegrees(false);
2728

2829
Reader reader = new StringReader(inputGeometry);
2930
StringWriter writer = new StringWriter();
@@ -85,6 +86,23 @@ public void run() throws Exception {
8586
+ "148.2299398518295 115.76041697475566, "
8687
+ "148.7342558247792 132.8539862772947, "
8788
+ "138.13304972044324 146.27258811335295)", result);
89+
90+
// Radians
91+
result = runApp(new String[]{
92+
"arc",
93+
"-a", "45",
94+
"-e", "90",
95+
"-w", "50",
96+
"-h", "50",
97+
"-p", "10",
98+
"-d"
99+
}, "POINT (100 100)");
100+
assertEquals("LINESTRING (142.6776695296637 142.6776695296637, " +
101+
"139.33941090877616 145.4788011072248, 135.56545654351748 147.65769467591625, " +
102+
"131.47047612756302 149.1481456572267, 127.17889356869145 149.90486745229364, " +
103+
"122.82110643130855 149.90486745229364, 118.52952387243698 149.1481456572267, " +
104+
"114.43454345648252 147.65769467591625, 110.66058909122384 145.4788011072248, " +
105+
"107.32233047033631 142.6776695296637)", result);
88106
}
89107

90108
}

src/test/java/org/geometrycommands/ArcPolygonCommandTest.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public void execute() throws Exception {
2424
options.setWidth(50);
2525
options.setHeight(50);
2626
options.setNumberOfPoints(10);
27+
options.setDegrees(false);
2728

2829
Reader reader = new StringReader(inputGeometry);
2930
StringWriter writer = new StringWriter();
@@ -89,6 +90,22 @@ public void run() throws Exception {
8990
+ "148.7342558247792 132.8539862772947, "
9091
+ "138.13304972044324 146.27258811335295, "
9192
+ "125 125))", result);
93+
94+
// Degrees
95+
result = runApp(new String[]{
96+
"arcpoly",
97+
"-a", "45",
98+
"-e", "90",
99+
"-w", "50",
100+
"-h", "50",
101+
"-p", "10",
102+
"-d"
103+
}, "POINT (100 100)");
104+
assertEquals("POLYGON ((125 125, 142.6776695296637 142.6776695296637, 139.33941090877616 145.4788011072248, " +
105+
"135.56545654351748 147.65769467591625, 131.47047612756302 149.1481456572267, " +
106+
"127.17889356869145 149.90486745229364, 122.82110643130855 149.90486745229364, " +
107+
"118.52952387243698 149.1481456572267, 114.43454345648252 147.65769467591625, " +
108+
"110.66058909122384 145.4788011072248, 107.32233047033631 142.6776695296637, 125 125))", result);
92109
}
93110

94111
}

0 commit comments

Comments
 (0)