### Question:
SimilarityToItem extends AbstractALSResource { @GET @Path("{toItemID}/{itemID : .+}") @Produces({MediaType.TEXT_PLAIN, "text/csv", MediaType.APPLICATION_JSON}) public List<Double> get( @PathParam("toItemID") String toItemID, @PathParam("itemID") List<PathSegment> pathSegmentsList) throws OryxServingException { ALSServingModel alsServingModel = getALSServingModel(); float[] toItemFeatures = alsServingModel.getItemVector(toItemID); checkExists(toItemFeatures != null, toItemID); double toItemFeaturesNorm = VectorMath.norm(toItemFeatures); return pathSegmentsList.stream().map(item -> { float[] itemFeatures = alsServingModel.getItemVector(item.getPath()); if (itemFeatures == null) { return 0.0; } else { double value = VectorMath.cosineSimilarity(itemFeatures, toItemFeatures, toItemFeaturesNorm); Preconditions.checkState(!(Double.isInfinite(value) || Double.isNaN(value)), "Bad similarity"); return value; } }).collect(Collectors.toList()); }  @GET @Path("{toItemID}/{itemID : .+}") @Produces({MediaType.TEXT_PLAIN, "text/csv", MediaType.APPLICATION_JSON}) List<Double> get(
      @PathParam("toItemID") String toItemID,
      @PathParam("itemID") List<PathSegment> pathSegmentsList);  }### Answer:
@Test(expected = NotFoundException.class) public void testNoArg() { target("/similarityToItem").request().get(String.class); }
@Test public void testSimilarityToItem() { List<Double> items = target("/similarityToItem/I0/I1/I2").request() .accept(MediaType.APPLICATION_JSON_TYPE).get(LIST_DOUBLE_TYPE); Assert.assertEquals(2, items.size()); Assert.assertEquals(0.9042603f, items.get(0), FLOAT_EPSILON); Assert.assertEquals(-0.26486862f, items.get(1), FLOAT_EPSILON); }
@Test public void testSimilarityToItemCSV() { String response = target("/similarityToItem/I0/I1/I2").request().get(String.class); testCSVScores(2, response); }
@Test public void testZeroSimilarityToItem() { List<Double> items = target("/similarityToItem/I1/I10").request() .accept(MediaType.APPLICATION_JSON_TYPE).get(LIST_DOUBLE_TYPE); Assert.assertEquals(1, items.size()); Assert.assertEquals(0.0f, items.get(0), FLOAT_EPSILON); }