### Question:
Line2d { public List<? extends Vector2d> getSegmentIntersection(Vector2d ptA, Vector2d ptB) { List<Vector2d> intersections; Vector2d aDir = ptA.subtract(myPoint); Vector2d bDir = ptB.subtract(myPoint); double aDot = aDir.dot(myNormal); double bDot = bDir.dot(myNormal); if (MathUtil.isZero(aDot)) { if (ptA.equals(ptB)) { throw new IllegalArgumentException("Line segment has zero length."); } else if (MathUtil.isZero(bDot)) { intersections = Arrays.asList(ptA, ptB); } else { intersections = Collections.singletonList(ptA); } } else if (MathUtil.isZero(bDot)) { intersections = Collections.singletonList(ptB); } else if (!MathUtil.sameSign(aDot, bDot)) { Vector2d intersection = getIntersection(ptA, ptB); intersections = intersection == null ? Collections.<Vector2d>emptyList() : Collections.singletonList(intersection); } else { intersections = Collections.emptyList(); } return intersections; } Line2d(Vector2d point, Vector2d normal); double distance(Vector2d pos); double getDistance(Ray2d ray); Vector2d getIntersection(Ray2d ray, boolean allowNegative); Vector2d getIntersection(Vector2d ptA, Vector2d ptB); Vector2d getNormal(); Vector2d getPoint(); List<? extends Vector2d> getSegmentIntersection(Vector2d ptA, Vector2d ptB); boolean hasIntersection(Vector2d ptA, Vector2d ptB); boolean isInFront(Vector2d position, double distance); boolean onSameSide(Vector2d ptA, Vector2d ptB); Vector2d project(Vector2d pos);  }### Answer:
@Test public void testGetSegmentIntersection() { Line2d line = new Line2d(new Vector2d(0., 0.), new Vector2d(0., 2.)); Assert.assertEquals(Arrays.asList(new Vector2d(0., 0.), new Vector2d(2., 0.)), line.getSegmentIntersection(new Vector2d(0., 0.), new Vector2d(2., 0.))); Assert.assertEquals(Collections.singletonList(new Vector2d(0., 0.)), line.getSegmentIntersection(new Vector2d(0., 0.), new Vector2d(0., 2.))); Assert.assertEquals(Collections.singletonList(new Vector2d(1., 0.)), line.getSegmentIntersection(new Vector2d(1., 0.), new Vector2d(1., 2.))); Assert.assertTrue(line.getSegmentIntersection(new Vector2d(0., 2.), new Vector2d(1., 2.)).isEmpty()); Assert.assertEquals(Collections.singletonList(new Vector2d(1., 0.)), line.getSegmentIntersection(new Vector2d(1., -1.), new Vector2d(1., 1.))); }
@Test(expected = IllegalArgumentException.class) public void testGetSegmentIntersectionBadArgument() { Line2d line = new Line2d(new Vector2d(0., 0.), new Vector2d(0., 2.)); line.getSegmentIntersection(new Vector2d(0., 0.), new Vector2d(0., 0.)); }