Skip to content

Commit c08f63b

Browse files
committed
refactor(errordoc): seal ErrorDocument and make class testable. #2
1 parent a8f5a76 commit c08f63b

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

src/main/java/org/swordapp/server/ErrorDocument.java

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@
2020
import java.util.HashMap;
2121
import java.util.Map;
2222

23-
public class ErrorDocument {
24-
private String errorUri = null;
25-
private static final Map<String, Integer> ERROR_CODES = new HashMap<>();
26-
private String summary = null;
27-
private String verboseDescription = null;
28-
private int status;
23+
public final class ErrorDocument {
24+
private final String errorUri;
25+
// package private to be accessible in tests
26+
static final Map<String, Integer> ERROR_CODES = new HashMap<>();
27+
private final String dateUpdated = DateTimeFormatter.ISO_INSTANT.format(ZonedDateTime.now().truncatedTo(ChronoUnit.SECONDS));
28+
private final String summary;
29+
private final String verboseDescription;
30+
private final int status;
2931

3032
static {
3133
// set up the error codes mapping
@@ -72,6 +74,11 @@ public int getStatus() {
7274
return HttpServletResponse.SC_BAD_REQUEST; // bad request
7375
}
7476
}
77+
78+
// test use only
79+
String getDateUpdated() {
80+
return dateUpdated;
81+
}
7582

7683
public void writeTo(final Writer out, final SwordConfiguration config) throws SwordServerException {
7784

@@ -96,7 +103,7 @@ public void writeTo(final Writer out, final SwordConfiguration config) throws Sw
96103

97104
// <sword:error><updated>
98105
Element updated = doc.createElementNS(UriRegistry.ATOM_NAMESPACE, "updated");
99-
updated.setTextContent(DateTimeFormatter.ISO_INSTANT.format(ZonedDateTime.now().truncatedTo(ChronoUnit.SECONDS)));
106+
updated.setTextContent(this.dateUpdated);
100107
swordError.appendChild(updated);
101108

102109
// <sword:error><generator>

0 commit comments

Comments
 (0)