Skip to content

Commit

Permalink
Merge branch '__rultor'
Browse files Browse the repository at this point in the history
  • Loading branch information
rultor committed Nov 15, 2021
2 parents ae3c15c + 3bea758 commit c031d76
Show file tree
Hide file tree
Showing 6 changed files with 177 additions and 13 deletions.
10 changes: 5 additions & 5 deletions pom.xml
Expand Up @@ -469,7 +469,7 @@ SOFTWARE.
<goal>report</goal>
</goals>
<!--
@todo #1067:30m This limits are set according to
@todo #1088:30m This limits are set according to
current metrics. Improve test coverage and
increase a limit, than update this task.
Remove this task when 0.99 is reached for each metric.
Expand All @@ -482,12 +482,12 @@ SOFTWARE.
<limit>
<counter>INSTRUCTION</counter>
<value>COVEREDRATIO</value>
<minimum>0.54</minimum>
<minimum>0.67</minimum>
</limit>
<limit>
<counter>LINE</counter>
<value>COVEREDRATIO</value>
<minimum>0.70</minimum>
<minimum>0.76</minimum>
</limit>
<limit>
<counter>BRANCH</counter>
Expand All @@ -497,12 +497,12 @@ SOFTWARE.
<limit>
<counter>COMPLEXITY</counter>
<value>COVEREDRATIO</value>
<minimum>0.40</minimum>
<minimum>0.52</minimum>
</limit>
<limit>
<counter>METHOD</counter>
<value>COVEREDRATIO</value>
<minimum>0.57</minimum>
<minimum>0.70</minimum>
</limit>
</limits>
</rule>
Expand Down
6 changes: 0 additions & 6 deletions src/main/java/org/takes/rs/xe/XeWhen.java
Expand Up @@ -53,12 +53,6 @@ public XeWhen(final boolean condition, final XeSource source) {
public XeSource value() {
return source;
}
},
new Scalar<XeSource>() {
@Override
public XeSource value() throws IOException {
return XeSource.EMPTY;
}
}
);
}
Expand Down
11 changes: 11 additions & 0 deletions src/test/java/org/takes/facets/fork/FkRegexTest.java
Expand Up @@ -23,6 +23,7 @@
*/
package org.takes.facets.fork;

import java.util.regex.Pattern;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.Test;
Expand All @@ -34,6 +35,7 @@
* Test case for {@link FkRegex}.
* @since 0.4
*/
@SuppressWarnings("PMD.AvoidDuplicateLiterals")
final class FkRegexTest {

/**
Expand All @@ -53,6 +55,15 @@ void matchesByRegularExpression() throws Exception {
).has(),
Matchers.is(true)
);
MatcherAssert.assertThat(
new FkRegex(
Pattern.compile("/h[a-z]{2}"),
new TkEmpty()
).route(
new RqFake("GET", "/hel?a=1")
).has(),
Matchers.is(true)
);
MatcherAssert.assertThat(
new FkRegex("/", new TkEmpty()).route(
new RqFake("PUT", "/?test")
Expand Down
25 changes: 23 additions & 2 deletions src/test/java/org/takes/rs/xe/XeWhenTest.java
Expand Up @@ -28,13 +28,17 @@
import java.nio.charset.StandardCharsets;
import org.apache.commons.io.IOUtils;
import org.cactoos.Scalar;
import org.cactoos.text.TextOf;
import org.hamcrest.MatcherAssert;
import org.junit.jupiter.api.Test;
import org.llorllale.cactoos.matchers.Assertion;

/**
* Test case for {@link XeWhen}.
* @since 0.13
* @checkstyle ClassDataAbstractionCouplingCheck (500 lines)
*/
@SuppressWarnings("PMD.AvoidDuplicateLiterals")
final class XeWhenTest {

/**
Expand Down Expand Up @@ -93,10 +97,10 @@ void buildsXmlResponseFromPositiveCondition() throws IOException {
/**
* XeWhen can build XML response with negative condition.
*
* @throws IOException If some problem inside
* @throws Exception If some problem inside
*/
@Test
void buildsXmlResponseFromNegativeCondition() throws IOException {
void buildsXmlResponseFromNegativeCondition() throws Exception {
MatcherAssert.assertThat(
IOUtils.toString(
new RsXembly(
Expand Down Expand Up @@ -124,6 +128,23 @@ public XeSource value() throws IOException {
"/negative/memory"
)
);
new Assertion<>(
"Must be empty when negative condition without negative source",
new TextOf(
new RsXembly(
new XeAppend(
"negative",
new XeWhen(
false,
new XeDate()
)
)
).body()
).asString(),
XhtmlMatchers.hasXPaths(
"/negative"
)
).affirm();
}

}
69 changes: 69 additions & 0 deletions src/test/java/org/takes/tk/TkHtmlTest.java
Expand Up @@ -23,6 +23,8 @@
*/
package org.takes.tk;

import java.io.InputStream;
import org.cactoos.io.InputStreamOf;
import org.cactoos.text.Joined;
import org.hamcrest.MatcherAssert;
import org.junit.jupiter.api.Test;
Expand All @@ -36,6 +38,7 @@
* Test case for {@link TkHtml}.
* @since 0.10
*/
@SuppressWarnings("PMD.AvoidDuplicateLiterals")
final class TkHtmlTest {

/**
Expand All @@ -60,6 +63,72 @@ void createsTextResponse() throws Exception {
);
}

/**
* TkHTML can create a text from {@link Scalar}.
* @throws Exception If some problem inside
*/
@Test
void createsTextResponseFromScalar() throws Exception {
final String body = "<html>hello, world!</html>";
MatcherAssert.assertThat(
new RsPrint(new TkHtml(() -> body).act(new RqFake())),
new TextIs(
new Joined(
"\r\n",
"HTTP/1.1 200 OK",
String.format("Content-Length: %s", body.length()),
"Content-Type: text/html",
"",
body
)
)
);
}

/**
* TkHTML can create a text from byte array.
* @throws Exception If some problem inside
*/
@Test
void createsTextResponseFromByteArray() throws Exception {
final String body = "<html>hello, world!</html>";
MatcherAssert.assertThat(
new RsPrint(new TkHtml(body.getBytes()).act(new RqFake())),
new TextIs(
new Joined(
"\r\n",
"HTTP/1.1 200 OK",
String.format("Content-Length: %s", body.length()),
"Content-Type: text/html",
"",
body
)
)
);
}

/**
* TkHTML can create a text from {@link InputStream}.
* @throws Exception If some problem inside
*/
@Test
void createsTextResponseFromInputStream() throws Exception {
final String body = "<html>hello, world!</html>";
MatcherAssert.assertThat(
new RsPrint(new TkHtml(new InputStreamOf(body)).act(new RqFake())),
new TextIs(
new Joined(
"\r\n",
"HTTP/1.1 200 OK",
String.format("Content-Length: %s", body.length()),
"Content-Type: text/html",
"",
body
)
)
);
}

/**
* TkHTML can print multiple times.
* @throws Exception If some problem inside
Expand Down
69 changes: 69 additions & 0 deletions src/test/java/org/takes/tk/TkTextTest.java
Expand Up @@ -23,6 +23,8 @@
*/
package org.takes.tk;

import java.io.InputStream;
import org.cactoos.io.InputStreamOf;
import org.cactoos.text.Joined;
import org.hamcrest.MatcherAssert;
import org.junit.jupiter.api.Test;
Expand All @@ -36,6 +38,7 @@
* Test case for {@link TkText}.
* @since 0.4
*/
@SuppressWarnings("PMD.AvoidDuplicateLiterals")
final class TkTextTest {

/**
Expand All @@ -60,6 +63,72 @@ void createsTextResponse() throws Exception {
);
}

/**
* TkText can create a text from {@link Scalar}.
* @throws Exception If some problem inside
*/
@Test
void createsTextResponseFromScalar() throws Exception {
final String body = "hello, world!";
MatcherAssert.assertThat(
new RsPrint(new TkText(() -> body).act(new RqFake())),
new TextIs(
new Joined(
"\r\n",
"HTTP/1.1 200 OK",
String.format("Content-Length: %s", body.length()),
"Content-Type: text/plain",
"",
body
)
)
);
}

/**
* TkText can create a text from byte array.
* @throws Exception If some problem inside
*/
@Test
void createsTextResponseFromByteArray() throws Exception {
final String body = "hello, world!";
MatcherAssert.assertThat(
new RsPrint(new TkText(body.getBytes()).act(new RqFake())),
new TextIs(
new Joined(
"\r\n",
"HTTP/1.1 200 OK",
String.format("Content-Length: %s", body.length()),
"Content-Type: text/plain",
"",
body
)
)
);
}

/**
* TkText can create a text from {@link InputStream}.
* @throws Exception If some problem inside
*/
@Test
void createsTextResponseFromInputStream() throws Exception {
final String body = "hello, world!";
MatcherAssert.assertThat(
new RsPrint(new TkText(new InputStreamOf(body)).act(new RqFake())),
new TextIs(
new Joined(
"\r\n",
"HTTP/1.1 200 OK",
String.format("Content-Length: %s", body.length()),
"Content-Type: text/plain",
"",
body
)
)
);
}

/**
* TkText can print multiple times.
* @throws Exception If some problem inside
Expand Down

1 comment on commit c031d76

@0pdd
Copy link
Collaborator

@0pdd 0pdd commented on c031d76 Nov 15, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 1067-ac9afd75 disappeared from pom.xml, that's why I closed #1088. Please, remember that the puzzle was not necessarily removed in this particular commit. Maybe it happened earlier, but we discovered this fact only now.

Please sign in to comment.