Skip to content

Commit

Permalink
Merge df00ade into 38f9551
Browse files Browse the repository at this point in the history
  • Loading branch information
amihaiemil committed Nov 19, 2017
2 parents 38f9551 + df00ade commit e4a0d93
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
7 changes: 4 additions & 3 deletions src/main/java/co/comdor/github/JsonMention.java
Expand Up @@ -40,8 +40,6 @@
* @author Mihai Andronache (amihaiemil@gmail.com)
* @version $Id$
* @since 0.0.1
* @todo #9:30min Implement method scripts(), which extracts the code
* to run from the comment, and write some unit tests for it.
*/
public abstract class JsonMention implements Mention {

Expand Down Expand Up @@ -104,7 +102,10 @@ public final String author() {

@Override
public final String scripts() {
return "echo 'hello world'";
final String body = this.json.getString("body");
final int start = body.indexOf("```") + 3;
final int end = body.lastIndexOf("```");
return body.substring(start, end);
}

@Override
Expand Down
2 changes: 0 additions & 2 deletions src/test/java/co/comdor/DockerTestCase.java
Expand Up @@ -25,8 +25,6 @@
*/
package co.comdor;

import com.spotify.docker.client.DockerClient;
import org.hamcrest.Matcher;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.Test;
Expand Down
10 changes: 5 additions & 5 deletions src/test/java/co/comdor/github/JsonMentionTestCase.java
Expand Up @@ -100,18 +100,18 @@ public void returnsJson() throws Exception {
}

/**
* JsonMention finds and returns the scripts from the comment's body.
* TODO: Adapt this unit test once JsonMention.scripts() is properly
* implemented.
* JsonMention finds and returns the scripts from the comment's body.* TODO: Adapt this unit test once JsonMention.scripts() is properly
* @throws Exception If something goes wrong.
*/
@Test
public void returnsTheScripts() throws Exception {
final JsonObject comment = Json.createObjectBuilder()
.add("body", "@comdor run ```cd src \ncloc .```").build();
final Mention mention = new MockConcrete(
Mockito.mock(JsonObject.class), Mockito.mock(Issue.class)
comment, Mockito.mock(Issue.class)
);
MatcherAssert.assertThat(
mention.scripts(), Matchers.equalTo("echo 'hello world'")
mention.scripts(), Matchers.equalTo("cd src \ncloc .")
);
}

Expand Down

0 comments on commit e4a0d93

Please sign in to comment.