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

Fixed bug in QnByArchitect.java + unit test #1106

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ _site
/.project
.settings
Gemfile.lock

bin/
5 changes: 0 additions & 5 deletions src/main/java/com/rultor/agents/github/qtn/QnByArchitect.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import com.google.common.collect.Lists;
import com.jcabi.aspects.Immutable;
import com.jcabi.github.Comment;
import com.jcabi.github.Issue;
import com.rultor.agents.github.Answer;
import com.rultor.agents.github.Question;
import com.rultor.agents.github.Req;
Expand Down Expand Up @@ -96,7 +95,6 @@ public QnByArchitect(final Profile prof, final String path,
public Req understand(final Comment.Smart comment,
final URI home) throws IOException {
final Req req;
final Issue.Smart issue = new Issue.Smart(comment.issue());
final List<String> logins = Lists.transform(
this.profile.read().xpath(this.xpath),
new Function<String, String>() {
Expand All @@ -109,9 +107,6 @@ public String apply(final String input) {
final boolean legal = logins.isEmpty()
|| logins.contains(
comment.author().login().toLowerCase(Locale.ENGLISH)
)
|| logins.contains(
issue.author().login().toLowerCase(Locale.ENGLISH)
);
if (legal) {
req = this.origin.understand(comment, home);
Expand Down
38 changes: 35 additions & 3 deletions src/test/java/com/rultor/agents/github/qtn/QnByArchitectTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import com.jcabi.github.Issue;
import com.jcabi.github.Repo;
import com.jcabi.github.mock.MkGithub;
import com.jcabi.github.mock.MkStorage;
import com.jcabi.xml.XMLDocument;
import com.rultor.agents.github.Question;
import com.rultor.spi.Profile;
Expand All @@ -49,6 +50,7 @@
* @author Yegor Bugayenko (yegor@teamed.io)
* @version $Id$
* @since 1.45
* @checkstyle ClassDataAbstractionCouplingCheck (500 lines)
*/
public final class QnByArchitectTest {

Expand Down Expand Up @@ -78,6 +80,36 @@ public void rejectsIfNotArchitect() throws Exception {
);
}

/**
* QnByArchitect can reject command if comment author not an architect,
* but issue author is.
* @throws Exception In case of error.
*/
@Test
public void rejectsIfNotArchitectWithArchitectAuthor() throws Exception {
final MkStorage storage = new MkStorage.Synced(new MkStorage.InFile());
final Repo repoJeff = new MkGithub(storage, "jeff").randomRepo();
final Issue issue = repoJeff.issues().create("", "");
final Comment.Smart mihaiComm = new Comment.Smart(
new MkGithub(storage, "amihaiemil").repos()
.get(repoJeff.coordinates()).issues().get(issue.number())
.comments().post("command")
);
final Question question = Mockito.mock(Question.class);
final URI home = new URI("#1");
new QnByArchitect(
new Profile.Fixed(
new XMLDocument("<p><entry key='b'>jeff</entry></p>")
),
"/p/entry[@key='b']/text()", question
).understand(mihaiComm, home);
Mockito.verify(question, Mockito.never()).understand(mihaiComm, home);
MatcherAssert.assertThat(
issue.comments().iterate(),
Matchers.<Comment>iterableWithSize(2)
);
}

/**
* QnByArchitect can accept if an architect.
* @throws Exception In case of error.
Expand All @@ -90,19 +122,19 @@ public void acceptsIfArchitect() throws Exception {
issue.comments().post("release")
);
final Question question = Mockito.mock(Question.class);
final URI home = new URI("#1");
final URI home = new URI("#2");
new QnByArchitect(
new Profile.Fixed(
new XMLDocument(
String.format(
"<p><entry key='b'>%s</entry></p>",
"<p><entry key='c'>%s</entry></p>",
repo.github().users().self().login().toUpperCase(
Locale.ENGLISH
)
)
)
),
"/p/entry[@key='b']/text()", question
"/p/entry[@key='c']/text()", question
).understand(comment, home);
Mockito.verify(question).understand(comment, home);
}
Expand Down