/** Given the history is empty, when I remove tags, then nothing happens. */ @Test public void testRemoveTagsFromEmptyHistory() { tagHistory = new TagHistoryView(context); tagHistory.getAdapter().registerAdapterDataObserver(observer); for (int i = 0; i < 3; i++) { tagHistory.pop(); } assertEquals("No tags are removed from an empty history", 0, observer.itemRemovedCount); }
/** * Given the history contains several tags, when I remove some, then I am notified for each one * and the history has the correct views. */ @Test public void testRemoveTags() { tagHistory = new TagHistoryView(context); for (int i = 0; i < 5; i++) { Tag tag = new Tag(String.valueOf(i), String.valueOf(i * 2)); tagHistory.push(tag); } tagHistory.getAdapter().registerAdapterDataObserver(observer); for (int i = 5; i > 2; i--) { tagHistory.pop(); } assertEquals( "The history has the correct number of tags", 2, tagHistory.getAdapter().getItemCount()); assertEquals("The correct number of tags are removed", 3, observer.itemRemovedCount); }