Commit 07b33199 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

common code refactored

parent bd04c4d5
Pipeline #10422 failed with stage
in 2 minutes and 35 seconds
......@@ -21,7 +21,8 @@ import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OrderColumn;
import org.apache.logging.log4j.*;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;
import org.hibernate.annotations.Type;
......@@ -123,7 +124,7 @@ public class PolylineData implements Serializable, Drawable {
}
/**
* Constructor that creates object initialized by the param line.
* Constructor that creates object initialized by the parameter object.
*
* @param param
* parameter used for data initialization
......@@ -159,10 +160,7 @@ public class PolylineData implements Serializable, Drawable {
* point to add
*/
public void addPoint(Point2D point) {
if (!pt.isValidPoint(point)) {
throw new InvalidArgumentException("Invalid coordinates: " + point);
}
points.add(point);
addPoint(points.size(), point);
}
/**
......@@ -241,11 +239,7 @@ public class PolylineData implements Serializable, Drawable {
* new value of the last point in the line
*/
public void setEndPoint(Point2D point) {
if (!pt.isValidPoint(point)) {
throw new InvalidArgumentException("Invalid coordinates (NaN is not accepted): " + point);
}
points.set(points.size() - 1, point);
setPoint(points.size() - 1, point);
}
/**
......@@ -364,10 +358,7 @@ public class PolylineData implements Serializable, Drawable {
* new first point in the line
*/
public void setStartPoint(Point2D point) {
if (!pt.isValidPoint(point)) {
throw new InvalidArgumentException("Invalid coordinates: " + point);
}
points.set(0, point);
setPoint(0, point);
}
/**
......
......@@ -457,4 +457,31 @@ public class PolylineDataTest {
}
}
@Test
public void testAddInvalidPoint() throws Exception {
try {
PolylineData pd = new PolylineData();
pd.addPoint(new Point2D.Double(Double.NEGATIVE_INFINITY, -10));
fail("Exception expected");
} catch (InvalidArgumentException e) {
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testAddPointOrder() throws Exception {
try {
PolylineData pd = new PolylineData();
pd.addPoint(new Point2D.Double(10, 10));
pd.addPoint(new Point2D.Double(20, 20));
assertEquals(new Point2D.Double(10, 10), pd.getPoints().get(0));
assertEquals(new Point2D.Double(20, 20), pd.getPoints().get(1));
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment