@Test public void testRepresent() throws ResourceException, IOException { final Variant variant = context.mock(Variant.class); context.checking(new Expectations() { { oneOf(mapper).findTop10PublicFeeds(); will(returnValue(listOfFRC)); oneOf(feedReaderCount).getFeedTitle(); oneOf(feedReaderCount).getUrl(); oneOf(feedReaderCount).getCount(); } }); sut.init(restContext, request, response); Representation actual = sut.represent(variant); assertEquals("MediaType should be application/json", MediaType.APPLICATION_JSON, actual.getMediaType()); context.assertIsSatisfied(); }
@Override public Representation represent(final Variant variant) throws ResourceException { try { List<FeedReaderUrlCount> feedReader = entityMapper.findTop10PublicFeeds(); String stringRep = ""; JSONArray jsonArray = new JSONArray(); for (FeedReaderUrlCount fr : feedReader) { jsonArray.add(convertFeedCountToJSON((FeedReaderUrlCount) fr)); } stringRep += jsonArray.toString(); Representation rep = new StringRepresentation(stringRep, MediaType.APPLICATION_JSON); rep.setExpirationDate(new Date(0L)); return rep; } catch (Exception e) { logger.error("Error when retrieving top 10 public feeds", e); throw new ResourceException(Status.SERVER_ERROR_INTERNAL, "Error when retrieving top 10 public feeds"); } }
FeedReaderCollectionResource extends FeedReaderResource { @Override public Representation represent(final Variant variant) throws ResourceException { try { List<FeedReaderUrlCount> feedReader = entityMapper.findTop10PublicFeeds(); String stringRep = ""; JSONArray jsonArray = new JSONArray(); for (FeedReaderUrlCount fr : feedReader) { jsonArray.add(convertFeedCountToJSON((FeedReaderUrlCount) fr)); } stringRep += jsonArray.toString(); Representation rep = new StringRepresentation(stringRep, MediaType.APPLICATION_JSON); rep.setExpirationDate(new Date(0L)); return rep; } catch (Exception e) { logger.error("Error when retrieving top 10 public feeds", e); throw new ResourceException(Status.SERVER_ERROR_INTERNAL, "Error when retrieving top 10 public feeds"); } } }
FeedReaderCollectionResource extends FeedReaderResource { @Override public Representation represent(final Variant variant) throws ResourceException { try { List<FeedReaderUrlCount> feedReader = entityMapper.findTop10PublicFeeds(); String stringRep = ""; JSONArray jsonArray = new JSONArray(); for (FeedReaderUrlCount fr : feedReader) { jsonArray.add(convertFeedCountToJSON((FeedReaderUrlCount) fr)); } stringRep += jsonArray.toString(); Representation rep = new StringRepresentation(stringRep, MediaType.APPLICATION_JSON); rep.setExpirationDate(new Date(0L)); return rep; } catch (Exception e) { logger.error("Error when retrieving top 10 public feeds", e); throw new ResourceException(Status.SERVER_ERROR_INTERNAL, "Error when retrieving top 10 public feeds"); } } protected  FeedReaderCollectionResource(); }
FeedReaderCollectionResource extends FeedReaderResource { @Override public Representation represent(final Variant variant) throws ResourceException { try { List<FeedReaderUrlCount> feedReader = entityMapper.findTop10PublicFeeds(); String stringRep = ""; JSONArray jsonArray = new JSONArray(); for (FeedReaderUrlCount fr : feedReader) { jsonArray.add(convertFeedCountToJSON((FeedReaderUrlCount) fr)); } stringRep += jsonArray.toString(); Representation rep = new StringRepresentation(stringRep, MediaType.APPLICATION_JSON); rep.setExpirationDate(new Date(0L)); return rep; } catch (Exception e) { logger.error("Error when retrieving top 10 public feeds", e); throw new ResourceException(Status.SERVER_ERROR_INTERNAL, "Error when retrieving top 10 public feeds"); } } protected  FeedReaderCollectionResource(); @Override Representation represent(final Variant variant); @Override void acceptRepresentation(final Representation entity); }
FeedReaderCollectionResource extends FeedReaderResource { @Override public Representation represent(final Variant variant) throws ResourceException { try { List<FeedReaderUrlCount> feedReader = entityMapper.findTop10PublicFeeds(); String stringRep = ""; JSONArray jsonArray = new JSONArray(); for (FeedReaderUrlCount fr : feedReader) { jsonArray.add(convertFeedCountToJSON((FeedReaderUrlCount) fr)); } stringRep += jsonArray.toString(); Representation rep = new StringRepresentation(stringRep, MediaType.APPLICATION_JSON); rep.setExpirationDate(new Date(0L)); return rep; } catch (Exception e) { logger.error("Error when retrieving top 10 public feeds", e); throw new ResourceException(Status.SERVER_ERROR_INTERNAL, "Error when retrieving top 10 public feeds"); } } protected  FeedReaderCollectionResource(); @Override Representation represent(final Variant variant); @Override void acceptRepresentation(final Representation entity);  }