From d8a0e386131f5b2b456088b518439089a093a0ec Mon Sep 17 00:00:00 2001 From: krzyk Date: Wed, 28 Jan 2015 07:23:25 +0100 Subject: [PATCH] #561 upgrade of jcab-github --- pom.xml | 3 +- .../com/rultor/agents/twitter/Tweets.java | 2 +- .../com/rultor/agents/twitter/TweetsTest.java | 104 ++++-------------- 3 files changed, 25 insertions(+), 84 deletions(-) diff --git a/pom.xml b/pom.xml index a4257d9c78..88e29f51df 100644 --- a/pom.xml +++ b/pom.xml @@ -260,6 +260,7 @@ com.jcabi jcabi-http + 1.10.2 com.jcabi @@ -278,7 +279,7 @@ com.jcabi jcabi-github - 0.18.7 + 0.18.9 com.jcabi diff --git a/src/main/java/com/rultor/agents/twitter/Tweets.java b/src/main/java/com/rultor/agents/twitter/Tweets.java index 82a5cbbb1a..12060512a6 100644 --- a/src/main/java/com/rultor/agents/twitter/Tweets.java +++ b/src/main/java/com/rultor/agents/twitter/Tweets.java @@ -126,7 +126,7 @@ private static String tweet(final Repo.Smart repo, final String tag) .append(" released https://github.com/") .append(repo.coordinates()); for (final Language lang : repo.languages()) { - text.append(String.format(" #%s", lang)); + text.append(String.format(" #%s", lang.name())); } return text.toString(); } diff --git a/src/test/java/com/rultor/agents/twitter/TweetsTest.java b/src/test/java/com/rultor/agents/twitter/TweetsTest.java index 2e8c44ecdb..7654364ff1 100644 --- a/src/test/java/com/rultor/agents/twitter/TweetsTest.java +++ b/src/test/java/com/rultor/agents/twitter/TweetsTest.java @@ -29,22 +29,15 @@ */ package com.rultor.agents.twitter; -import com.google.common.collect.Lists; -import com.jcabi.github.Coordinates; -import com.jcabi.github.Github; +import com.google.common.base.Function; +import com.google.common.base.Joiner; +import com.google.common.collect.Iterables; import com.jcabi.github.Issue; -import com.jcabi.github.Issues; import com.jcabi.github.Language; import com.jcabi.github.Repo; -import com.jcabi.github.Repos; import com.jcabi.github.mock.MkGithub; -import com.rultor.spi.Agent; import com.rultor.spi.Talk; import java.io.IOException; -import java.util.List; -import javax.json.Json; -import javax.json.JsonObject; -import org.junit.Ignore; import org.junit.Test; import org.mockito.Matchers; import org.mockito.Mockito; @@ -56,10 +49,6 @@ * @author Yegor Bugayenko (yegor@tpc2.com) * @version $Id$ * @since 1.30 - * @todo #561 When all the puzzles from - * https://github.com/jcabi/jcabi-github/issues/923 are implemented, remove - * repo, issue, lang methods, and use MkGithub family in all the tests. Also - * enable postsTweet method. */ public final class TweetsTest { @@ -68,14 +57,11 @@ public final class TweetsTest { * @throws Exception In case of error. */ @Test - @Ignore public void postsTweet() throws Exception { final Repo repo = new MkGithub().randomRepo(); - final Issue issue = repo.issues().create("", ""); final Twitter twitter = Mockito.mock(Twitter.class); - final Agent agent = new Tweets(repo.github(), twitter); - final Talk talk = this.talk(repo, issue); - agent.execute(talk); + final Talk talk = TweetsTest.talk(repo, repo.issues().create("", "")); + new Tweets(repo.github(), twitter).execute(talk); Mockito.verify(twitter).post( Matchers.contains("test") ); @@ -87,57 +73,28 @@ public void postsTweet() throws Exception { */ @Test public void postsTweetWithLanguages() throws Exception { - final Repo repo = this.repo(); - final List langs = Lists.newArrayList( - this.lang("Java"), this.lang("Python") - ); - Mockito.when(repo.languages()).thenReturn(langs); + final Repo repo = new MkGithub().randomRepo(); final Twitter twitter = Mockito.mock(Twitter.class); - final Agent agent = new Tweets(repo.github(), twitter); - final Talk talk = this.talk(repo, this.issue(repo)); - agent.execute(talk); + new Tweets(repo.github(), twitter).execute( + TweetsTest.talk(repo, repo.issues().create("", "")) + ); Mockito.verify(twitter).post( Matchers.contains( - String.format("#%s #%s", langs.get(0), langs.get(1)) + Joiner.on(' ').join( + Iterables.transform( + repo.languages(), + new Function() { + @Override + public String apply(final Language lang) { + return String.format("#%s", lang.name()); + } + } + ) + ) ) ); } - /** - * Create mock issue. - * @param repo Repo to use - * @return Mocked issue. - */ - private Issue issue(final Repo repo) { - final Issues issues = Mockito.mock(Issues.class); - final Issue issue = Mockito.mock(Issue.class); - Mockito.when(issue.repo()).thenReturn(repo); - Mockito.when(issues.get(Mockito.anyInt())).thenReturn(issue); - Mockito.when(repo.issues()).thenReturn(issues); - return issue; - } - - /** - * Create mock repo. - * @return Mocked repo - * @throws IOException In case of error - */ - private Repo repo() throws IOException { - final Github github = Mockito.mock(Github.class); - final Repo repo = Mockito.mock(Repo.class); - final JsonObject rjson = Json.createObjectBuilder() - .add("description", "something").build(); - Mockito.when(repo.json()).thenReturn(rjson); - Mockito.when(repo.github()).thenReturn(github); - final Repos repos = Mockito.mock(Repos.class); - Mockito.when(github.repos()).thenReturn(repos); - final Coordinates coords = new Coordinates.Simple("foo/bar"); - Mockito.when(repo.coordinates()).thenReturn(coords); - Mockito.when(repos.get(Mockito.any(Coordinates.class))) - .thenReturn(repo); - return repo; - } - /** * Creates a talk with repo and issue. * @param repo Repo to use @@ -145,7 +102,8 @@ private Repo repo() throws IOException { * @return Created Talk * @throws IOException In case of error */ - private Talk talk(final Repo repo, final Issue issue) throws IOException { + private static Talk talk(final Repo repo, final Issue issue) + throws IOException { final Talk talk = new Talk.InFile(); talk.modify( new Directives().xpath("/talk").add("wire") @@ -161,22 +119,4 @@ private Talk talk(final Repo repo, final Issue issue) throws IOException { ); return talk; } - - /** - * Create mock language. - * @param name Name of the language - * @return Language created. - */ - private Language lang(final String name) { - return new Language() { - @Override - public String name() { - return name; - } - @Override - public long bytes() { - return 0; - } - }; - } }