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

(#1088) Improve test coverage #1094

Merged
merged 8 commits into from
Nov 15, 2021
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
10 changes: 5 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,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 @@ -489,12 +489,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 @@ -504,12 +504,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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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