Skip to content

Commit

Permalink
[yegor256#1207] Remove StringUtils from Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pnatashap committed Feb 23, 2024
1 parent bcba48a commit 6db0b4e
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 45 deletions.
9 changes: 5 additions & 4 deletions src/test/java/com/rultor/agents/MailsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
import com.rultor.spi.Profile;
import com.rultor.spi.Talk;
import java.io.IOException;
import org.apache.commons.lang3.StringUtils;
import org.cactoos.text.Joined;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.Assertions;
Expand Down Expand Up @@ -107,17 +107,18 @@ void sendsToRecipients() {
* Profile for test.
* @return Profile
*/
private Profile.Fixed profile() {
private Profile.Fixed profile() throws Exception {
return new Profile.Fixed(
new XMLDocument(
StringUtils.join(
new Joined(
"",
"<p><entry key='release'>",
"<entry key='email'>",
"<item>test1@localhost</item>",
"<item>test2@localhost</item>",
"</entry>",
"</entry></p>"
)
).asString()
)
);
}
Expand Down
17 changes: 10 additions & 7 deletions src/test/java/com/rultor/agents/github/ClosePullRequestTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
import com.rultor.spi.Talk;
import java.io.IOException;
import java.util.Date;
import org.apache.commons.lang3.StringUtils;
import org.cactoos.text.Joined;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -66,11 +66,12 @@ void closesPullRequestForRebaseMode() throws Exception {
final Issue issue = repo.issues().create("", "");
final Profile profile = new Profile.Fixed(
new XMLDocument(
StringUtils.join(
new Joined(
"",
"<p><entry key='merge'>",
"<entry key='rebase'>true</entry>",
"</entry></p>"
)
).asString()
)
);
final Talk talk = ClosePullRequestTest.talk(repo, issue);
Expand All @@ -82,15 +83,16 @@ void closesPullRequestForRebaseMode() throws Exception {
MatcherAssert.assertThat(
new Comment.Smart(smart.comments().get(1)).body(),
Matchers.containsString(
StringUtils.join(
new Joined(
"",
"Rultor closed this pull request for you because your ",
".rultor.yml specified the use of rebasing before ",
"merging. GitHub does not mark rebased pull requests as ",
"merged, because rebasing entails a change in commit ",
"hashes. Nevertheless all your files have been merged ",
"exactly as they would have been merged without the ",
"rebase option set."
)
).asString()
)
);
}
Expand All @@ -105,11 +107,12 @@ void leavesPullRequestOpenWhenNoRebaseMode() throws Exception {
final Issue issue = repo.issues().create("", "");
final Profile profile = new Profile.Fixed(
new XMLDocument(
StringUtils.join(
new Joined(
"",
"<p> <entry key='merge'>",
" <entry key='rebase'>false</entry>",
"</entry> </p>"
)
).asString()
)
);
final Talk talk = ClosePullRequestTest.talk(repo, issue);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@
import java.security.SecureRandom;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.cactoos.io.TeeInput;
import org.cactoos.scalar.LengthOf;
import org.cactoos.text.Joined;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.Disabled;
Expand Down Expand Up @@ -87,11 +87,12 @@ void attachesBinaryToRelease(
repo.github(),
new Profile.Fixed(
new XMLDocument(
StringUtils.join(
new Joined(
"",
"<p><entry key='release'><entry key='artifacts'>",
String.format("%s/%s", target, name),
target, "/", name,
"</entry></entry></p>"
)
).asString()
)
)
).execute(talk);
Expand Down
16 changes: 8 additions & 8 deletions src/test/java/com/rultor/agents/github/qtn/QnAskedByTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
import com.rultor.agents.github.Question;
import com.rultor.spi.Profile;
import java.net.URI;
import org.apache.commons.lang3.StringUtils;
import org.cactoos.text.Joined;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -99,13 +99,13 @@ void includesArchitectsInListOfCommanders() throws Exception {
final QnAskedBy qab = new QnAskedBy(
new Profile.Fixed(
new XMLDocument(
String.format(
StringUtils.join(
"<p><entry key='architect'><item>%s</item>",
"<item>fooo</item></entry></p>"
),
repo.github().users().self().login()
)
new Joined(
"",
"<p><entry key='architect'><item>",
repo.github().users().self().login(),
"</item>",
"<item>fooo</item></entry></p>"
).asString()
)
),
String.format(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
import com.jcabi.matchers.XhtmlMatchers;
import com.rultor.agents.github.Req;
import java.net.URI;
import org.apache.commons.lang3.StringUtils;
import org.cactoos.text.Joined;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -129,12 +129,13 @@ void answerWhenMentioned() throws Exception {
MatcherAssert.assertThat(
new Comment.Smart(issue.comments().get(2)).body(),
Matchers.containsString(
StringUtils.join(
new Joined(
"",
"I see you're talking about me, but I don't",
" understand it. If you want to say something to me",
" directly, start a message with @",
login
)
).asString()
)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

import com.jcabi.xml.XMLDocument;
import com.rultor.spi.Profile;
import org.apache.commons.lang3.StringUtils;
import org.cactoos.text.Joined;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.Test;
Expand All @@ -45,11 +45,12 @@ final class ProfileDeprecationsTest {
/**
* The format of an profile that defines the docker image to use.
*/
private static final String PROFILE_FORMAT = StringUtils.join(
private static final String PROFILE_FORMAT = new Joined(
"",
"<p><entry key='docker'>",
"<entry key='image'>%s</entry>",
"</entry></p>"
);
).toString();

/**
* ProfileDeprecations can identify a deprecated profile.
Expand Down
26 changes: 15 additions & 11 deletions src/test/java/com/rultor/profiles/ProfilesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import com.jcabi.xml.XMLDocument;
import com.rultor.spi.Profile;
import java.util.List;
import org.apache.commons.lang3.StringUtils;
import org.cactoos.text.Joined;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.Assertions;
Expand Down Expand Up @@ -64,7 +64,8 @@ final class ProfilesTest {
/**
* Profile template.
*/
private static final String PROFILE = StringUtils.join(
private static final String PROFILE = new Joined(
"",
"<p><entry key='architect'><item>%s</item></entry>",
"<entry key='merge'>",
ProfilesTest.COMMANDERS,
Expand All @@ -74,7 +75,7 @@ final class ProfilesTest {
"</entry><entry key='release'>",
ProfilesTest.COMMANDERS,
"</entry></p>"
);
).toString();

/**
* Template for exception message.
Expand Down Expand Up @@ -203,19 +204,22 @@ void validationFailsOnCommandersMix() throws Exception {
final Profile merged = new Profile.Fixed(
new XMLDocument(
String.format(
StringUtils.join(
"<p><entry key='architect'><item>%s</item>",
new Joined(
"",
"<p><entry key='architect'><item>",
architect, "</item>",
"</entry><entry key='merge'>",
"<entry key='commanders'>",
"<item>%s</item><item>%s</item><item>%s</item>",
"<item>", first,
"</item><item>",
second,
"</item><item>",
second,
"</item>",
"</entry>",
ProfilesTest.SCRIPT,
"</entry> </p>"
),
architect,
first,
second,
second,
).asString(),
"do_another4"
)
)
Expand Down
12 changes: 7 additions & 5 deletions src/test/java/com/rultor/spi/ProfileTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

import com.jcabi.matchers.XhtmlMatchers;
import com.jcabi.xml.XMLDocument;
import org.apache.commons.lang3.StringUtils;
import org.cactoos.text.Joined;
import org.hamcrest.MatcherAssert;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
Expand All @@ -53,13 +53,14 @@ void acceptsValidXML() throws Exception {
MatcherAssert.assertThat(
new Profile.Fixed(
new XMLDocument(
StringUtils.join(
new Joined(
"",
"<p><entry key='deploy'>",
"<entry key='script'>this is a plain text</entry>",
"<entry key='&gt;'><item>hello</item></entry>",
"<entry key='abc'><entry key='a'>b</entry></entry>",
"</entry></p>"
)
).asString()
)
).read(),
XhtmlMatchers.hasXPaths(
Expand All @@ -79,10 +80,11 @@ void rejectsMixedEntriesAndItems() {
IllegalArgumentException.class,
() -> new Profile.Fixed(
new XMLDocument(
StringUtils.join(
new Joined(
"",
"<p><entry key='x'><entry key='test'>a</entry>",
"<item>b</item></entry></p>"
)
).asString()
)
)
);
Expand Down

0 comments on commit 6db0b4e

Please sign in to comment.