Moved from Gradle to bld
This commit is contained in:
parent
84cfe6098d
commit
68975a497b
58 changed files with 632 additions and 2393 deletions
128
src/bld/java/net/thauvin/erik/httpstatus/HttpStatusBuild.java
Normal file
128
src/bld/java/net/thauvin/erik/httpstatus/HttpStatusBuild.java
Normal file
|
@ -0,0 +1,128 @@
|
|||
/*
|
||||
* HttpStatusBuild.java
|
||||
*
|
||||
* Copyright 2023 sErik C. Thauvin (erik@thauvin.net)
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* Neither the name of this project nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software without
|
||||
* specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package net.thauvin.erik.httpstatus;
|
||||
|
||||
import rife.bld.BuildCommand;
|
||||
import rife.bld.Project;
|
||||
import rife.bld.dependencies.Dependency;
|
||||
import rife.bld.extension.PmdOperation;
|
||||
import rife.bld.publish.PublishDeveloper;
|
||||
import rife.bld.publish.PublishInfo;
|
||||
import rife.bld.publish.PublishLicense;
|
||||
import rife.bld.publish.PublishScm;
|
||||
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
import java.util.List;
|
||||
|
||||
import static rife.bld.dependencies.Repository.*;
|
||||
import static rife.bld.dependencies.Scope.compile;
|
||||
import static rife.bld.dependencies.Scope.test;
|
||||
import static rife.bld.operations.JavadocOptions.DocLinkOption.NO_MISSING;
|
||||
|
||||
public class HttpStatusBuild extends Project {
|
||||
public HttpStatusBuild() {
|
||||
pkg = "net.thauvin.erik.httpstatus";
|
||||
name = "HttpStatus";
|
||||
version = version(1, 1, 0, "SNAPSHOT");
|
||||
|
||||
var description = "HttpStatus JSP Tag Library";
|
||||
var url = "https://github.com/ethauvin/HttpStatus";
|
||||
|
||||
mainClass = "net.thauvin.erik.httpstatus.Reasons";
|
||||
|
||||
javaRelease = 17;
|
||||
|
||||
downloadSources = true;
|
||||
repositories = List.of(MAVEN_LOCAL, MAVEN_CENTRAL, SONATYPE_SNAPSHOTS);
|
||||
|
||||
scope(compile)
|
||||
.include(dependency("jakarta.servlet", "jakarta.servlet-api", version(6, 0, 0)))
|
||||
.include(dependency("jakarta.servlet.jsp", "jakarta.servlet.jsp-api", version(3, 1, 1)))
|
||||
.include(dependency("jakarta.el", "jakarta.el-api", version(5, 0, 1)));
|
||||
scope(test)
|
||||
.include(dependency("org.assertj", "assertj-joda-time", version(2, 2, 0)))
|
||||
.include(dependency("org.junit.jupiter", "junit-jupiter", version(5, 9, 3)))
|
||||
.include(dependency("org.junit.platform", "junit-platform-console-standalone", version(1, 9, 3)));
|
||||
|
||||
javadocOperation().javadocOptions()
|
||||
.docTitle(description + ' ' + version.toString())
|
||||
.docLint(NO_MISSING)
|
||||
.link("https://jakarta.ee/specifications/platform/9/apidocs/");
|
||||
|
||||
publishOperation()
|
||||
.repository(version.isSnapshot() ? repository(SONATYPE_SNAPSHOTS_LEGACY.location())
|
||||
.withCredentials(property("sonatype.user"), property("sonatype.password"))
|
||||
: repository(SONATYPE_RELEASES.location())
|
||||
.withCredentials(property("sonatype.user"), property("sonatype.password")))
|
||||
.repository(MAVEN_LOCAL)
|
||||
.info(new PublishInfo()
|
||||
.groupId(pkg)
|
||||
.artifactId(name.toLowerCase())
|
||||
.name(name)
|
||||
.description(description)
|
||||
.url(url)
|
||||
.developer(new PublishDeveloper().id("ethauvin").name("Erik C. Thauvin").email("erik@thauvin.net")
|
||||
.url("https://erik.thauvin.net/"))
|
||||
.license(new PublishLicense().name("The BSD 3-Clause License")
|
||||
.url("http://opensource.org/licenses/BSD-3-Clause"))
|
||||
.scm(new PublishScm().connection("scm:git:" + url + ".git")
|
||||
.developerConnection("scm:git:git@github.com:ethauvin/" + name + ".git")
|
||||
.url(url))
|
||||
.signKey(property("sign.key"))
|
||||
.signPassphrase(property("sign.passphrase")));
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
new HttpStatusBuild().start(args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void publish() throws Exception {
|
||||
super.publish();
|
||||
var pomPath = Path.of(MAVEN_LOCAL.getArtifactLocation(new Dependency(pkg, name.toLowerCase(), version)),
|
||||
version.toString(),
|
||||
name.toLowerCase() + '-' + version + ".pom");
|
||||
Files.copy(pomPath, Path.of(workDirectory.getAbsolutePath(), "pom.xml"), StandardCopyOption.REPLACE_EXISTING);
|
||||
}
|
||||
|
||||
@BuildCommand(summary = "Runs PMD analysis")
|
||||
public void pmd() throws Exception {
|
||||
new PmdOperation()
|
||||
.fromProject(this)
|
||||
.failOnViolation(true)
|
||||
.ruleSets("config/pmd.xml")
|
||||
.execute();
|
||||
}
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* Reasons.java
|
||||
*
|
||||
* Copyright (c) 2015-2022, Erik C. Thauvin (erik@thauvin.net)
|
||||
* Copyright 2023 sErik C. Thauvin (erik@thauvin.net)
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* StatusCode.java
|
||||
*
|
||||
* Copyright (c) 2015-2022, Erik C. Thauvin (erik@thauvin.net)
|
||||
* Copyright 2023 sErik C. Thauvin (erik@thauvin.net)
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
@ -32,6 +32,7 @@
|
|||
|
||||
package net.thauvin.erik.httpstatus;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
|
@ -40,6 +41,7 @@ import java.io.Serializable;
|
|||
* @author <a href="mailto:erik@thauvin.net">Erik C. Thauvin</a>
|
||||
*/
|
||||
public class StatusCode implements Serializable {
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
private int code;
|
||||
|
||||
|
@ -49,7 +51,7 @@ public class StatusCode implements Serializable {
|
|||
public StatusCode() {
|
||||
// Default constructor.
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new StatusCode object.
|
||||
*
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* Utils.java
|
||||
*
|
||||
* Copyright (c) 2015-2022, Erik C. Thauvin (erik@thauvin.net)
|
||||
* Copyright 2023 sErik C. Thauvin (erik@thauvin.net)
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
@ -66,24 +66,12 @@ public final class Utils {
|
|||
for (int i = 0; i < value.length(); i++) {
|
||||
final char c = value.charAt(i);
|
||||
switch (c) {
|
||||
case '<':
|
||||
escaped.append("<");
|
||||
break;
|
||||
case '>':
|
||||
escaped.append(">");
|
||||
break;
|
||||
case '&':
|
||||
escaped.append("&");
|
||||
break;
|
||||
case '\'':
|
||||
escaped.append("'");
|
||||
break;
|
||||
case '"':
|
||||
escaped.append(""");
|
||||
break;
|
||||
default:
|
||||
escaped.append(c);
|
||||
break;
|
||||
case '<' -> escaped.append("<");
|
||||
case '>' -> escaped.append(">");
|
||||
case '&' -> escaped.append("&");
|
||||
case '\'' -> escaped.append("'");
|
||||
case '"' -> escaped.append(""");
|
||||
default -> escaped.append(c);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* CauseTag.java
|
||||
*
|
||||
* Copyright (c) 2015-2022, Erik C. Thauvin (erik@thauvin.net)
|
||||
* Copyright 2023 sErik C. Thauvin (erik@thauvin.net)
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* CodeTag.java
|
||||
*
|
||||
* Copyright (c) 2015-2022, Erik C. Thauvin (erik@thauvin.net)
|
||||
* Copyright 2023 sErik C. Thauvin (erik@thauvin.net)
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* CauseTag.java
|
||||
* MessageTag.java
|
||||
*
|
||||
* Copyright (c) 2015-2022, Erik C. Thauvin (erik@thauvin.net)
|
||||
* Copyright 2023 sErik C. Thauvin (erik@thauvin.net)
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* ReasonTag.java
|
||||
*
|
||||
* Copyright (c) 2015-2022, Erik C. Thauvin (erik@thauvin.net)
|
||||
* Copyright 2023 sErik C. Thauvin (erik@thauvin.net)
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
@ -65,7 +65,7 @@ public class ReasonTag extends XmlSupport {
|
|||
Utils.outWrite(out, Reasons.getReasonPhrase(pageContext.getErrorData().getStatusCode()), defaultValue,
|
||||
escapeXml);
|
||||
}
|
||||
} catch (IOException ignore) {
|
||||
} catch (IOException ignored) {
|
||||
// Ignore.
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* XmlSupport.java
|
||||
*
|
||||
* Copyright (c) 2015-2022, Erik C. Thauvin (erik@thauvin.net)
|
||||
* Copyright 2023 sErik C. Thauvin (erik@thauvin.net)
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<!--
|
||||
~ httpstatus.tld
|
||||
~
|
||||
~ Copyright (c) 2015-2020, Erik C. Thauvin (erik@thauvin.net)
|
||||
~ Copyright 2023 sErik C. Thauvin (erik@thauvin.net)
|
||||
~ All rights reserved.
|
||||
~
|
||||
~ Redistribution and use in source and binary forms, with or without
|
||||
|
|
|
@ -1,3 +1,35 @@
|
|||
#
|
||||
# reasons.properties
|
||||
#
|
||||
# Copyright 2023 sErik C. Thauvin (erik@thauvin.net)
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions are met:
|
||||
#
|
||||
# Redistributions of source code must retain the above copyright notice, this
|
||||
# list of conditions and the following disclaimer.
|
||||
#
|
||||
# Redistributions in binary form must reproduce the above copyright notice,
|
||||
# this list of conditions and the following disclaimer in the documentation
|
||||
# and/or other materials provided with the distribution.
|
||||
#
|
||||
# Neither the name of this project nor the names of its contributors may be
|
||||
# used to endorse or promote products derived from this software without
|
||||
# specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#
|
||||
|
||||
100=Continue
|
||||
101=Switching Protocols
|
||||
102=Processing
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* ReasonsMainTest.java
|
||||
*
|
||||
* Copyright (c) 2015-2022, Erik C. Thauvin (erik@thauvin.net)
|
||||
* Copyright 2023 sErik C. Thauvin (erik@thauvin.net)
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
@ -32,17 +32,15 @@
|
|||
|
||||
package net.thauvin.erik.httpstatus;
|
||||
|
||||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
||||
import org.testng.annotations.AfterTest;
|
||||
import org.testng.annotations.BeforeMethod;
|
||||
import org.testng.annotations.BeforeTest;
|
||||
import org.testng.annotations.Test;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.PrintStream;
|
||||
|
||||
import static org.testng.Assert.assertFalse;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Main Class Tests.
|
||||
|
@ -51,51 +49,50 @@ import static org.testng.Assert.assertTrue;
|
|||
* @created 2019-05-06
|
||||
* @since 1.0
|
||||
*/
|
||||
@SuppressFBWarnings({"DM_DEFAULT_ENCODING", "ITU_INAPPROPRIATE_TOSTRING_USE"})
|
||||
public class ReasonsMainTest {
|
||||
private final PrintStream originalOut = System.out;
|
||||
private final ByteArrayOutputStream outContent = new ByteArrayOutputStream();
|
||||
class ReasonsMainTest {
|
||||
private final static PrintStream originalOut = System.out;
|
||||
private final static ByteArrayOutputStream outContent = new ByteArrayOutputStream();
|
||||
|
||||
@AfterTest
|
||||
public void restoreStreams() {
|
||||
@AfterAll
|
||||
public static void restoreStreams() {
|
||||
System.setOut(originalOut);
|
||||
}
|
||||
|
||||
@BeforeTest
|
||||
public void setUpStreams() {
|
||||
@BeforeAll
|
||||
public static void setUpStreams() {
|
||||
System.setOut(new PrintStream(outContent));
|
||||
}
|
||||
|
||||
@BeforeMethod
|
||||
@BeforeEach
|
||||
public void resetStreams() {
|
||||
outContent.reset();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMain() {
|
||||
void testMain() {
|
||||
Reasons.main("401");
|
||||
assertTrue(outContent.toString().contains(Reasons.getReasonPhrase("401")), "401");
|
||||
assertFalse(outContent.toString().contains("500"), "401 no 500");
|
||||
assertThat(outContent.toString().contains(Reasons.getReasonPhrase("401"))).as("401").isTrue();
|
||||
assertThat(outContent.toString().contains("500")).as("401 no 500").isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMainAll() {
|
||||
void testMainAll() {
|
||||
Reasons.main();
|
||||
assertTrue(outContent.toString().contains(Reasons.getReasonPhrase(301)), "301");
|
||||
assertTrue(outContent.toString().contains(Reasons.getReasonPhrase(404)), "404");
|
||||
assertThat(outContent.toString().contains(Reasons.getReasonPhrase(301))).as("301").isTrue();
|
||||
assertThat(outContent.toString().contains(Reasons.getReasonPhrase(404))).as("404").isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMainArgs() {
|
||||
void testMainArgs() {
|
||||
Reasons.main("500", "302");
|
||||
assertTrue(outContent.toString().contains(Reasons.getReasonPhrase("500")), "500 (302)");
|
||||
assertTrue(outContent.toString().contains(Reasons.getReasonPhrase("302")), "(500) 302");
|
||||
assertFalse(outContent.toString().contains("404"), "500/302 not 404");
|
||||
assertThat(outContent.toString().contains(Reasons.getReasonPhrase("500"))).as("500 (302)").isTrue();
|
||||
assertThat(outContent.toString().contains(Reasons.getReasonPhrase("302"))).as("(500) 302").isTrue();
|
||||
assertThat(outContent.toString().contains("404")).as("500/302 not 404").isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMainInvalid() {
|
||||
void testMainInvalid() {
|
||||
Reasons.main("aaa");
|
||||
assertTrue(outContent.toString().isEmpty(), "invalid argument: aaa");
|
||||
assertThat(outContent.toString().isEmpty()).as("invalid argument: aaa").isTrue();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* ReasonsTest.java
|
||||
*
|
||||
* Copyright (c) 2015-2022, Erik C. Thauvin (erik@thauvin.net)
|
||||
* Copyright 2023 sErik C. Thauvin (erik@thauvin.net)
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
@ -32,11 +32,12 @@
|
|||
|
||||
package net.thauvin.erik.httpstatus;
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
|
||||
/**
|
||||
* Reasons Tests.
|
||||
|
@ -45,14 +46,14 @@ import static org.testng.Assert.assertEquals;
|
|||
* @created 2015-12-03
|
||||
* @since 1.0
|
||||
*/
|
||||
public class ReasonsTest {
|
||||
class ReasonsTest {
|
||||
@Test
|
||||
public void testGetReasonPhrase() {
|
||||
void testGetReasonPhrase() {
|
||||
final ResourceBundle bundle = ResourceBundle.getBundle(Reasons.BUNDLE_BASENAME);
|
||||
for (final String key : bundle.keySet()) {
|
||||
assertEquals(bundle.getString(key), Reasons.getReasonPhrase(key), "getReasonPhrase(" + key + ')');
|
||||
assertEquals(bundle.getString(key), Reasons.getReasonPhrase(Integer.parseInt(key)),
|
||||
"getReasonPhrase(int: " + key + ')');
|
||||
assertThat(Reasons.getReasonPhrase(key)).as("getReasonPhrase(" + key + ')').isEqualTo(bundle.getString(key));
|
||||
assertThat(Reasons.getReasonPhrase(Integer.parseInt(key)))
|
||||
.as("getReasonPhrase(int: " + key + ')').isEqualTo(bundle.getString(key));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* StatusCodeTest.java
|
||||
*
|
||||
* Copyright (c) 2015-2022, Erik C. Thauvin (erik@thauvin.net)
|
||||
* Copyright 2023 sErik C. Thauvin (erik@thauvin.net)
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
@ -32,20 +32,18 @@
|
|||
|
||||
package net.thauvin.erik.httpstatus;
|
||||
|
||||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
||||
import org.testng.annotations.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
import static org.testng.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* StatusCode Tests.
|
||||
*
|
||||
* @author <a href="mailto:erik@thauvin.net">Erik C. Thauvin</a>
|
||||
*/
|
||||
@SuppressFBWarnings("CE_CLASS_ENVY")
|
||||
public class StatusCodeTest {
|
||||
class StatusCodeTest {
|
||||
@Test
|
||||
void testStatusCode() {
|
||||
final ResourceBundle bundle = ResourceBundle.getBundle(Reasons.BUNDLE_BASENAME);
|
||||
|
@ -53,33 +51,34 @@ public class StatusCodeTest {
|
|||
for (final String key : bundle.keySet()) {
|
||||
final int code = Integer.parseInt(key);
|
||||
statusCode.setCode(code);
|
||||
assertEquals(statusCode.getCode(), code, "is not " + code);
|
||||
assertEquals(statusCode.isInfo(), code >= 100 && code < 200, code + " is info");
|
||||
assertEquals(statusCode.isSuccess(), code >= 200 && code < 300, code + " is ok");
|
||||
assertEquals(statusCode.isRedirect(), code >= 300 && code < 400, code + " is redirect");
|
||||
assertEquals(statusCode.isClientError(), code >= 400 && code < 500, code + " is client error");
|
||||
assertEquals(statusCode.isServerError(), code >= 500 && code < 600, code + " is server error");
|
||||
assertEquals(statusCode.isError(), code >= 400 && code < 600, code + " is error");
|
||||
assertTrue(statusCode.isValid(), code + "is valid");
|
||||
assertThat(statusCode.getCode()).as("is not " + code).isEqualTo(code);
|
||||
assertThat(statusCode.isInfo()).as(code + " is info").isEqualTo(code >= 100 && code < 200);
|
||||
assertThat(statusCode.isSuccess()).as(code + " is ok").isEqualTo(code >= 200 && code < 300);
|
||||
assertThat(statusCode.isRedirect()).as(code + " is redirect").isEqualTo(code >= 300 && code < 400);
|
||||
assertThat(statusCode.isClientError()).as(code + " is client error").isEqualTo(code >= 400 && code < 500);
|
||||
assertThat(statusCode.isServerError()).as(code + " is server error").isEqualTo(code >= 500 && code < 600);
|
||||
assertThat(statusCode.isError()).as(code + " is error").isEqualTo(code >= 400 && code < 600);
|
||||
assertThat(statusCode.isValid()).as(code + "is valid").isTrue();
|
||||
|
||||
assertEquals(statusCode.getReason(), Reasons.getReasonPhrase(code), code + "reason phrase is not valid");
|
||||
assertThat(statusCode.getReason()).as(code + "reason phrase is not valid")
|
||||
.isEqualTo(Reasons.getReasonPhrase(code));
|
||||
}
|
||||
|
||||
final int[] unknowns = {0, 99, 600};
|
||||
for (final int code : unknowns) {
|
||||
statusCode.setCode(code);
|
||||
assertEquals(statusCode.getCode(), code, "is not " + code);
|
||||
assertFalse(statusCode.isInfo(), code + " is info");
|
||||
assertFalse(statusCode.isSuccess(), code + " is ok");
|
||||
assertFalse(statusCode.isRedirect(), code + " is redirect");
|
||||
assertFalse(statusCode.isClientError(), code + " is client error");
|
||||
assertFalse(statusCode.isServerError(), code + " is server error");
|
||||
assertFalse(statusCode.isError(), code + " is error");
|
||||
assertFalse(statusCode.isValid(), "600 is invalid");
|
||||
assertNull(statusCode.getReason(), code + "reason phrase is not null.");
|
||||
assertThat(statusCode.getCode()).as("is not " + code).isEqualTo(code);
|
||||
assertThat(statusCode.isInfo()).as(code + " is info").isFalse();
|
||||
assertThat(statusCode.isSuccess()).as(code + " is ok").isFalse();
|
||||
assertThat(statusCode.isRedirect()).as(code + " is redirect").isFalse();
|
||||
assertThat(statusCode.isClientError()).as(code + " is client error").isFalse();
|
||||
assertThat(statusCode.isServerError()).as(code + " is server error").isFalse();
|
||||
assertThat(statusCode.isError()).as(code + " is error").isFalse();
|
||||
assertThat(statusCode.isValid()).as("600 is invalid").isFalse();
|
||||
assertThat(statusCode.getReason()).as(code + "reason phrase is not null.").isNull();
|
||||
}
|
||||
|
||||
statusCode = new StatusCode(900);
|
||||
assertEquals(statusCode.getCode(), 900, "is not 900");
|
||||
assertThat(statusCode.getCode()).as("is not 900").isEqualTo(900);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* UtilsTest.java
|
||||
*
|
||||
* Copyright (c) 2015-2022, Erik C. Thauvin (erik@thauvin.net)
|
||||
* Copyright 2023 sErik C. Thauvin (erik@thauvin.net)
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
@ -32,13 +32,13 @@
|
|||
|
||||
package net.thauvin.erik.httpstatus;
|
||||
|
||||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
||||
import org.testng.annotations.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
|
||||
/**
|
||||
* Utils Tests.
|
||||
|
@ -47,55 +47,54 @@ import static org.testng.Assert.assertEquals;
|
|||
* @created 2015-12-03
|
||||
* @since 1.0
|
||||
*/
|
||||
public class UtilsTest {
|
||||
class UtilsTest {
|
||||
@Test
|
||||
public void testEscapeXml() {
|
||||
assertEquals(Utils.escapeXml(
|
||||
void testEscapeXml() {
|
||||
assertThat(Utils.escapeXml(
|
||||
"This is a test. We wan't to make sure that everything is <encoded> according the \"encoding\" "
|
||||
+ "parameter & value."),
|
||||
"This is a test. We wan't to make sure that everything is <encoded> according the "
|
||||
+ ""encoding" parameter & value.");
|
||||
+ "parameter & value."))
|
||||
.isEqualTo("This is a test. We wan't to make sure that everything is <encoded> " +
|
||||
"according the "encoding" parameter & value.");
|
||||
}
|
||||
|
||||
@SuppressWarnings("PMD.AvoidDuplicateLiterals")
|
||||
@SuppressFBWarnings("CE_CLASS_ENVY")
|
||||
@Test
|
||||
public void testOutWrite() throws IOException {
|
||||
void testOutWrite() throws IOException {
|
||||
try (StringWriter sw = new StringWriter()) {
|
||||
Utils.outWrite(sw, null, "default", false);
|
||||
assertEquals(sw.toString(), "default", "outWrite(default)");
|
||||
assertThat(sw.toString()).isEqualTo("default").as("outWrite(default)");
|
||||
|
||||
sw.getBuffer().setLength(0);
|
||||
Utils.outWrite(sw, "", "default", false);
|
||||
assertEquals(sw.toString(), "", "outWrite(value empty)");
|
||||
assertThat(sw.toString()).isEqualTo("").as("outWrite(value empty)");
|
||||
|
||||
sw.getBuffer().setLength(0);
|
||||
Utils.outWrite(sw, null, null, true);
|
||||
assertEquals(sw.toString(), "", "outWrite(null)");
|
||||
assertThat(sw.toString()).isEqualTo("").as("outWrite(null)");
|
||||
|
||||
sw.getBuffer().setLength(0);
|
||||
Utils.outWrite(sw, "value", "default", false);
|
||||
assertEquals(sw.toString(), "value", "outWrite(value)");
|
||||
assertThat(sw.toString()).isEqualTo("value").as("outWrite(value)");
|
||||
|
||||
sw.getBuffer().setLength(0);
|
||||
Utils.outWrite(sw, "wan't", "default", true);
|
||||
assertEquals(sw.toString(), "wan't", "outWrite(wan't)");
|
||||
assertThat(sw.toString()).isEqualTo("wan't").as("outWrite(wan't)");
|
||||
|
||||
sw.getBuffer().setLength(0);
|
||||
Utils.outWrite(sw, null, "1 & 1", true);
|
||||
assertEquals(sw.toString(), "1 & 1", "outWrite(1 & 1)");
|
||||
assertThat(sw.toString()).isEqualTo("1 & 1").as("outWrite(1 & 1)");
|
||||
|
||||
sw.getBuffer().setLength(0);
|
||||
Utils.outWrite(sw, "", "default", true);
|
||||
assertEquals(sw.toString(), "", "outWrite(value empty, xml)");
|
||||
assertThat(sw.toString()).isEqualTo("").as("outWrite(value empty).as(xml)");
|
||||
|
||||
sw.getBuffer().setLength(0);
|
||||
Utils.outWrite(sw, null, "", true);
|
||||
assertEquals(sw.toString(), "", "outWrite(default empty)");
|
||||
assertThat(sw.toString()).isEqualTo("").as("outWrite(default empty)");
|
||||
|
||||
sw.getBuffer().setLength(0);
|
||||
Utils.outWrite(sw, null, null, true);
|
||||
assertEquals(sw.toString(), "", "outWrite(null, xml)");
|
||||
assertThat(sw.toString()).isEqualTo("").as("outWrite(null).as(xml)");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue