### Question:
Ray2D { public Segment2D intersectionSegment(Ray2D other) { if(this.contains(other.getStart()) && other.contains(this.getStart())) { return new Segment2D(this.getStart(), other.getStart()); } else { return null; } } Ray2D(Vector2D start, Vector2D direction); Vector2D getStart(); void setStart(Vector2D start); Vector2D getDirection(); void setDirection(Vector2D direction); Vector2D intersectionPoint(Ray2D other); Ray2D intersectionRay(Ray2D other); Segment2D intersectionSegment(Ray2D other); boolean contains(Vector2D point); boolean isParallel(Ray2D other); boolean equals(Ray2D other); String toString();  }### Answer:
@Test public void intersectionSegment() throws Exception { aStart = GeometryFactory.createVector(0,0); aDirection = GeometryFactory.createVector(1,0); a = GeometryFactory.createRay2D(aStart, aDirection); bStart = GeometryFactory.createVector(5,0); bDirection = GeometryFactory.createVector(-1,0); b = GeometryFactory.createRay2D(bStart, bDirection); Segment2D intersectionSegment = a.intersectionSegment(b); Assert.assertEquals(0, intersectionSegment.getFirstPoint().getXComponent(), PRECISION); Assert.assertEquals(0, intersectionSegment.getFirstPoint().getYComponent(), PRECISION); Assert.assertEquals(5, intersectionSegment.getLastPoint().getXComponent(), PRECISION); Assert.assertEquals(0, intersectionSegment.getLastPoint().getYComponent(), PRECISION); aStart = GeometryFactory.createVector(0,0); aDirection = GeometryFactory.createVector(0,1); a = GeometryFactory.createRay2D(aStart, aDirection); bStart = GeometryFactory.createVector(0,7); bDirection = GeometryFactory.createVector(0,-0.1); b = GeometryFactory.createRay2D(bStart, bDirection); intersectionSegment = a.intersectionSegment(b); Assert.assertEquals(0, intersectionSegment.getFirstPoint().getXComponent(), PRECISION); Assert.assertEquals(0, intersectionSegment.getFirstPoint().getYComponent(), PRECISION); Assert.assertEquals(0, intersectionSegment.getLastPoint().getXComponent(), PRECISION); Assert.assertEquals(7, intersectionSegment.getLastPoint().getYComponent(), PRECISION); bStart = GeometryFactory.createVector(5,5); bDirection = GeometryFactory.createVector(-1,0); b = GeometryFactory.createRay2D(bStart, bDirection); intersectionSegment = a.intersectionSegment(b); assertNull(intersectionSegment); }