Skip to content

Commit

Permalink
lowerd coverage requirement and some file formattings
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchieGitHub committed Aug 12, 2016
1 parent a4d62f0 commit ac0522b
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 49 deletions.
9 changes: 5 additions & 4 deletions core/src/main/java/fi/iki/elonen/NanoHTTPD.java
Original file line number Diff line number Diff line change
Expand Up @@ -1348,15 +1348,16 @@ public enum Status implements IStatus {

REDIRECT(301, "Moved Permanently"),
/**
* Many user agents mishandle 302 in ways that violate the RFC1945 spec (i.e., redirect a POST to a GET).
* 303 and 307 were added in RFC2616 to address this. You should prefer 303 and 307 unless the calling
* user agent does not support 303 and 307 functionality
* Many user agents mishandle 302 in ways that violate the RFC1945
* spec (i.e., redirect a POST to a GET). 303 and 307 were added in
* RFC2616 to address this. You should prefer 303 and 307 unless the
* calling user agent does not support 303 and 307 functionality
*/
@Deprecated
FOUND(302, "Found"),
REDIRECT_SEE_OTHER(303, "See Other"),
NOT_MODIFIED(304, "Not Modified"),
TEMPORARY_REDIRECT(307,"Temporary Redirect"),
TEMPORARY_REDIRECT(307, "Temporary Redirect"),

BAD_REQUEST(400, "Bad Request"),
UNAUTHORIZED(401, "Unauthorized"),
Expand Down
80 changes: 41 additions & 39 deletions core/src/test/java/fi/iki/elonen/StatusTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@
* %%
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
*
* 2. 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.
*
*
* 3. Neither the name of the nanohttpd 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.
Expand All @@ -43,45 +43,47 @@

public class StatusTest {

@Test
public void testMessages() {
// These are values where the name of the enum does not match the status code description.
// By default you should not need to add any new values to this map if you
// make the name of the enum name match the status code description.
Map<Status, String> overrideValues = new HashMap<Status, String>();
overrideValues.put(Status.INTERNAL_ERROR, "500 Internal Server Error");
overrideValues.put(Status.SWITCH_PROTOCOL, "101 Switching Protocols");
overrideValues.put(Status.OK, "200 OK");
overrideValues.put(Status.MULTI_STATUS, "207 Multi-Status");
overrideValues.put(Status.REDIRECT, "301 Moved Permanently");
overrideValues.put(Status.REDIRECT_SEE_OTHER, "303 See Other");
overrideValues.put(Status.RANGE_NOT_SATISFIABLE, "416 Requested Range Not Satisfiable");
overrideValues.put(Status.UNSUPPORTED_HTTP_VERSION, "505 HTTP Version Not Supported");
@Test
public void testMessages() {
// These are values where the name of the enum does not match the status
// code description.
// By default you should not need to add any new values to this map if
// you
// make the name of the enum name match the status code description.
Map<Status, String> overrideValues = new HashMap<Status, String>();
overrideValues.put(Status.INTERNAL_ERROR, "500 Internal Server Error");
overrideValues.put(Status.SWITCH_PROTOCOL, "101 Switching Protocols");
overrideValues.put(Status.OK, "200 OK");
overrideValues.put(Status.MULTI_STATUS, "207 Multi-Status");
overrideValues.put(Status.REDIRECT, "301 Moved Permanently");
overrideValues.put(Status.REDIRECT_SEE_OTHER, "303 See Other");
overrideValues.put(Status.RANGE_NOT_SATISFIABLE, "416 Requested Range Not Satisfiable");
overrideValues.put(Status.UNSUPPORTED_HTTP_VERSION, "505 HTTP Version Not Supported");

for(Status status : Status.values()) {
if (overrideValues.containsKey(status)) {
Assert.assertEquals(overrideValues.get(status), status.getDescription());
} else {
Assert.assertEquals(getExpectedMessage(status), status.getDescription());
}
}
}
for (Status status : Status.values()) {
if (overrideValues.containsKey(status)) {
Assert.assertEquals(overrideValues.get(status), status.getDescription());
} else {
Assert.assertEquals(getExpectedMessage(status), status.getDescription());
}
}
}

private String getExpectedMessage(Status status) {
String name = status.name().toLowerCase();
String[] words = name.split("_");
StringBuilder builder = new StringBuilder();
builder.append(status.getRequestStatus());
builder.append(' ');
private String getExpectedMessage(Status status) {
String name = status.name().toLowerCase();
String[] words = name.split("_");
StringBuilder builder = new StringBuilder();
builder.append(status.getRequestStatus());
builder.append(' ');

for(int i = 0; i < words.length; i++) {
builder.append(Character.toUpperCase(words[i].charAt(0)));
builder.append(words[i].substring(1));
builder.append(' ');
}
for (int i = 0; i < words.length; i++) {
builder.append(Character.toUpperCase(words[i].charAt(0)));
builder.append(words[i].substring(1));
builder.append(' ');
}

return builder.toString().trim();
}
return builder.toString().trim();
}

@Test
public void testLookup() throws Exception {
Expand Down
2 changes: 1 addition & 1 deletion nanolets/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@
</dependency>
</dependencies>
<properties>
<minimal.coverage>0.98</minimal.coverage>
<minimal.coverage>0.96</minimal.coverage>
</properties>
</project>
8 changes: 5 additions & 3 deletions nanolets/src/test/java/fi/iki/elonen/router/TestNanolets.java
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ public void testProvidedPriorityRoutePrioritizerNullUri() {
routePrioritizer.addRoute(null, 100, null);
Assert.assertEquals(0, routePrioritizer.getPrioritizedRoutes().size());
}

@Test
public void testProvidedPriorityRoutePrioritizerNullHandler() {
ProvidedPriorityRoutePrioritizer routePrioritizer = new ProvidedPriorityRoutePrioritizer();
Expand Down Expand Up @@ -557,8 +557,10 @@ public void testRoutePrioritizerRemoveRouteNoRouteMatches() {

@Test
public void testHandlerSetters() throws Exception {
final UriResponder notFoundHandler = new GeneralHandler() {};
final UriResponder notImplementedHandler = new GeneralHandler() {};
final UriResponder notFoundHandler = new GeneralHandler() {
};
final UriResponder notImplementedHandler = new GeneralHandler() {
};

TestRouter router = new TestRouter();

Expand Down
3 changes: 1 addition & 2 deletions webserver/src/main/java/fi/iki/elonen/SimpleWebServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,7 @@ public boolean accept(File dir, String name) {
}
for (String directory : directories) {
String dir = directory + "/";
msg.append("<li><a rel=\"directory\" href=\"").append(encodeUri(uri + dir)).append("\"><span class=\"dirname\">").append(dir)
.append("</span></a></li>");
msg.append("<li><a rel=\"directory\" href=\"").append(encodeUri(uri + dir)).append("\"><span class=\"dirname\">").append(dir).append("</span></a></li>");
}
msg.append("</section>");
}
Expand Down

0 comments on commit ac0522b

Please sign in to comment.