TopicList { public List<String> getTopicNames() { final List<String> topicNames = new ArrayList<>(); for (final TopicListing topicListing: getTopics()) { topicNames.add(topicListing.getName()); } return Collections.unmodifiableList(topicNames); } TopicList(final List<TopicListing> topics); List<TopicListing> getTopics(); List<String> getTopicNames(); TopicList filterByTopicName(final String search); @Override String toString();  }
@Test public void testListingIsSorted() { final String topic1 = "TopicA"; final String topic2 = "AnotherTopic"; final String topic3 = "123Topic"; final List<TopicListing> topicListingList = new ArrayList<>(); topicListingList.add(new TopicListing(topic1, false)); topicListingList.add(new TopicListing(topic2, false)); topicListingList.add(new TopicListing(topic3, false)); final TopicList topicList = new TopicList(topicListingList); final List<String> results = topicList.getTopicNames(); assertEquals(topic3, results.get(0)); assertEquals(topic2, results.get(1)); assertEquals(topic1, results.get(2)); }
@Test public void testGetTopicNamesReturnsImmutable() { final List<TopicListing> topicListingList = new ArrayList<>(); topicListingList.add(new TopicListing("A", false)); topicListingList.add(new TopicListing("B", false)); topicListingList.add(new TopicListing("C", false)); final TopicList topicList = new TopicList(topicListingList); final List<String> results = topicList.getTopicNames(); expectedException.expect(UnsupportedOperationException.class); results.remove(1); }