Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#561 added languages tweets #761

Merged
merged 2 commits into from
Jan 28, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@
<dependency>
<groupId>com.jcabi</groupId>
<artifactId>jcabi-http</artifactId>
<version>1.10.2</version>
</dependency>
<dependency>
<groupId>com.jcabi</groupId>
Expand All @@ -278,7 +279,7 @@
<dependency>
<groupId>com.jcabi</groupId>
<artifactId>jcabi-github</artifactId>
<version>0.18.7</version>
<version>0.18.9</version>
</dependency>
<dependency>
<groupId>com.jcabi</groupId>
Expand Down
11 changes: 8 additions & 3 deletions src/main/java/com/rultor/agents/twitter/Tweets.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import com.jcabi.aspects.Tv;
import com.jcabi.github.Github;
import com.jcabi.github.Issue;
import com.jcabi.github.Language;
import com.jcabi.github.Repo;
import com.jcabi.log.Logger;
import com.jcabi.xml.XML;
Expand Down Expand Up @@ -107,6 +108,7 @@ public Iterable<Directive> process(final XML xml) throws IOException {
* @return Tweet text
* @throws IOException If fails
*/
@SuppressWarnings("PMD.InsufficientStringBufferDeclaration")
private static String tweet(final Repo.Smart repo, final String tag)
throws IOException {
final StringBuilder text = new StringBuilder(2 * Tv.HUNDRED);
Expand All @@ -120,10 +122,13 @@ private static String tweet(final Repo.Smart repo, final String tag)
)
);
}
return text.append(", ").append(tag)
text.append(", ").append(tag)
.append(" released https://github.com/")
.append(repo.coordinates())
.toString();
.append(repo.coordinates());
for (final Language lang : repo.languages()) {
text.append(String.format(" #%s", lang.name()));
}
return text.toString();
}

}
60 changes: 50 additions & 10 deletions src/test/java/com/rultor/agents/twitter/TweetsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,15 @@
*/
package com.rultor.agents.twitter;

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.Language;
import com.jcabi.github.Repo;
import com.jcabi.github.mock.MkGithub;
import com.rultor.spi.Agent;
import com.rultor.spi.Talk;
import org.junit.Ignore;
import java.io.IOException;
import org.junit.Test;
import org.mockito.Matchers;
import org.mockito.Mockito;
Expand All @@ -54,12 +57,53 @@ 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 = TweetsTest.talk(repo, repo.issues().create("", ""));
new Tweets(repo.github(), twitter).execute(talk);
Mockito.verify(twitter).post(
Matchers.contains("test")
);
}

/**
* Tweets can post a tweet with language tags.
* @throws Exception In case of error.
*/
@Test
public void postsTweetWithLanguages() throws Exception {
final Repo repo = new MkGithub().randomRepo();
final Twitter twitter = Mockito.mock(Twitter.class);
new Tweets(repo.github(), twitter).execute(
TweetsTest.talk(repo, repo.issues().create("", ""))
);
Mockito.verify(twitter).post(
Matchers.contains(
Joiner.on(' ').join(
Iterables.transform(
repo.languages(),
new Function<Language, String>() {
@Override
public String apply(final Language lang) {
return String.format("#%s", lang.name());
}
}
)
)
)
);
}

/**
* Creates a talk with repo and issue.
* @param repo Repo to use
* @param issue Issue to use
* @return Created Talk
* @throws IOException In case of error
*/
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")
Expand All @@ -73,10 +117,6 @@ public void postsTweet() throws Exception {
.add("type").set("release").up()
.add("args").add("arg").attr("name", "tag").set("1.7")
);
agent.execute(talk);
Mockito.verify(twitter).post(
Matchers.contains("test")
);
return talk;
}

}