Created
October 21, 2011 13:05
-
-
Save giorgiosironi/1303801 to your computer and use it in GitHub Desktop.
Diff for a unit test freed from the Test Double for an external Adapter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/test/it/polimi/hermes/LinkedInGroupAdapterTest.java b/test/it/polimi/hermes/LinkedInGroupAdapterTest.java | |
index c769aff..f4142c5 100644 | |
--- a/test/it/polimi/hermes/LinkedInGroupAdapterTest.java | |
+++ b/test/it/polimi/hermes/LinkedInGroupAdapterTest.java | |
@@ -1,44 +1,45 @@ | |
package it.polimi.hermes; | |
import static org.junit.Assert.assertEquals; | |
- | |
+import static org.mockito.Mockito.*; | |
import java.util.List; | |
import org.junit.Test; | |
+import org.mockito.ArgumentMatcher; | |
public class LinkedInGroupAdapterTest { | |
@Test | |
public void shouldParseTheXmlAndReturnTheNewPosts() { | |
- PostsSource adapter = new LinkedInGroupAdapter(42, new LinkedInServiceStub()); | |
- List<Post> posts = adapter.getPosts(1, 1080000000 * 1000); | |
- assertEquals(1, posts.size()); | |
- assertEquals("I am looking for research...", posts.get(0).getTitle()); | |
- assertEquals("BCLhiVr0o2", posts.get(0).getCreatorId()); | |
+ PostsAnalyzer analyzer = mock(PostsAnalyzer.class); | |
+ LinkedInGroupAdapter adapter = new LinkedInGroupAdapter(analyzer); | |
+ adapter.acceptXmlResponse(lastPostsResponse()); | |
+ verify(analyzer).newPosts((List<Post>) argThat(new ContainsTheCannedPost())); | |
} | |
- class LinkedInServiceStub implements LinkedInScraper { | |
- public String getLastPostsResponse(int groupId, int numberOfPosts, | |
- long timestampToStartFrom) { | |
- assertEquals(42, groupId); | |
- assertEquals(1, numberOfPosts); | |
- assertEquals(1080000000 * 1000, timestampToStartFrom); | |
- return "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" | |
- + "<posts total=\"196\" count=\"1\" start=\"0\">" | |
- + "<post>" | |
- + "<id>g-43875-S-74373991</id>" | |
- + "<creator>" | |
- + "<id>BCLhiVr0o2</id>" | |
- + "<first-name>Umesh</first-name>" | |
- + "<last-name>J.</last-name>" | |
- + "<headline>OpenSource Specialist at Spark Technologies</headline>" | |
- + "</creator>" | |
- + "<title>I am looking for research...</title>" | |
- + "</post>" | |
- + "</posts>"; | |
- | |
- | |
+ class ContainsTheCannedPost extends ArgumentMatcher { | |
+ @Override | |
+ public boolean matches(Object argument) { | |
+ List<Post> posts = (List<Post>) argument; | |
+ return 1 == posts.size() | |
+ && posts.get(0).getTitle().equals("I am looking for research...") | |
+ && posts.get(0).getCreatorId().equals("BCLhiVr0o2"); | |
} | |
- | |
+ } | |
+ | |
+ public String lastPostsResponse() { | |
+ return "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" | |
+ + "<posts total=\"196\" count=\"1\" start=\"0\">" | |
+ + "<post>" | |
+ + "<id>g-43875-S-74373991</id>" | |
+ + "<creator>" | |
+ + "<id>BCLhiVr0o2</id>" | |
+ + "<first-name>Umesh</first-name>" | |
+ + "<last-name>J.</last-name>" | |
+ + "<headline>OpenSource Specialist at Spark Technologies</headline>" | |
+ + "</creator>" | |
+ + "<title>I am looking for research...</title>" | |
+ + "</post>" | |
+ + "</posts>"; | |
} | |
} | |
\ No newline at end of file |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment