|
11 | 11 | * %% |
12 | 12 | * Redistribution and use in source and binary forms, with or without modification, |
13 | 13 | * are permitted provided that the following conditions are met: |
14 | | - * |
| 14 | + * |
15 | 15 | * 1. Redistributions of source code must retain the above copyright notice, this |
16 | 16 | * list of conditions and the following disclaimer. |
17 | | - * |
| 17 | + * |
18 | 18 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
19 | 19 | * this list of conditions and the following disclaimer in the documentation |
20 | 20 | * and/or other materials provided with the distribution. |
21 | | - * |
| 21 | + * |
22 | 22 | * 3. Neither the name of the nanohttpd nor the names of its contributors |
23 | 23 | * may be used to endorse or promote products derived from this software without |
24 | 24 | * specific prior written permission. |
25 | | - * |
| 25 | + * |
26 | 26 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
27 | 27 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
28 | 28 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
|
43 | 43 |
|
44 | 44 | public class StatusTest { |
45 | 45 |
|
46 | | - @Test |
47 | | - public void testMessages() { |
48 | | - // These are values where the name of the enum does not match the status code description. |
49 | | - // By default you should not need to add any new values to this map if you |
50 | | - // make the name of the enum name match the status code description. |
51 | | - Map<Status, String> overrideValues = new HashMap<Status, String>(); |
52 | | - overrideValues.put(Status.INTERNAL_ERROR, "500 Internal Server Error"); |
53 | | - overrideValues.put(Status.SWITCH_PROTOCOL, "101 Switching Protocols"); |
54 | | - overrideValues.put(Status.OK, "200 OK"); |
55 | | - overrideValues.put(Status.MULTI_STATUS, "207 Multi-Status"); |
56 | | - overrideValues.put(Status.REDIRECT, "301 Moved Permanently"); |
57 | | - overrideValues.put(Status.REDIRECT_SEE_OTHER, "303 See Other"); |
58 | | - overrideValues.put(Status.RANGE_NOT_SATISFIABLE, "416 Requested Range Not Satisfiable"); |
59 | | - overrideValues.put(Status.UNSUPPORTED_HTTP_VERSION, "505 HTTP Version Not Supported"); |
| 46 | + @Test |
| 47 | + public void testMessages() { |
| 48 | + // These are values where the name of the enum does not match the status |
| 49 | + // code description. |
| 50 | + // By default you should not need to add any new values to this map if |
| 51 | + // you |
| 52 | + // make the name of the enum name match the status code description. |
| 53 | + Map<Status, String> overrideValues = new HashMap<Status, String>(); |
| 54 | + overrideValues.put(Status.INTERNAL_ERROR, "500 Internal Server Error"); |
| 55 | + overrideValues.put(Status.SWITCH_PROTOCOL, "101 Switching Protocols"); |
| 56 | + overrideValues.put(Status.OK, "200 OK"); |
| 57 | + overrideValues.put(Status.MULTI_STATUS, "207 Multi-Status"); |
| 58 | + overrideValues.put(Status.REDIRECT, "301 Moved Permanently"); |
| 59 | + overrideValues.put(Status.REDIRECT_SEE_OTHER, "303 See Other"); |
| 60 | + overrideValues.put(Status.RANGE_NOT_SATISFIABLE, "416 Requested Range Not Satisfiable"); |
| 61 | + overrideValues.put(Status.UNSUPPORTED_HTTP_VERSION, "505 HTTP Version Not Supported"); |
60 | 62 |
|
61 | | - for(Status status : Status.values()) { |
62 | | - if (overrideValues.containsKey(status)) { |
63 | | - Assert.assertEquals(overrideValues.get(status), status.getDescription()); |
64 | | - } else { |
65 | | - Assert.assertEquals(getExpectedMessage(status), status.getDescription()); |
66 | | - } |
67 | | - } |
68 | | - } |
| 63 | + for (Status status : Status.values()) { |
| 64 | + if (overrideValues.containsKey(status)) { |
| 65 | + Assert.assertEquals(overrideValues.get(status), status.getDescription()); |
| 66 | + } else { |
| 67 | + Assert.assertEquals(getExpectedMessage(status), status.getDescription()); |
| 68 | + } |
| 69 | + } |
| 70 | + } |
69 | 71 |
|
70 | | - private String getExpectedMessage(Status status) { |
71 | | - String name = status.name().toLowerCase(); |
72 | | - String[] words = name.split("_"); |
73 | | - StringBuilder builder = new StringBuilder(); |
74 | | - builder.append(status.getRequestStatus()); |
75 | | - builder.append(' '); |
| 72 | + private String getExpectedMessage(Status status) { |
| 73 | + String name = status.name().toLowerCase(); |
| 74 | + String[] words = name.split("_"); |
| 75 | + StringBuilder builder = new StringBuilder(); |
| 76 | + builder.append(status.getRequestStatus()); |
| 77 | + builder.append(' '); |
76 | 78 |
|
77 | | - for(int i = 0; i < words.length; i++) { |
78 | | - builder.append(Character.toUpperCase(words[i].charAt(0))); |
79 | | - builder.append(words[i].substring(1)); |
80 | | - builder.append(' '); |
81 | | - } |
| 79 | + for (int i = 0; i < words.length; i++) { |
| 80 | + builder.append(Character.toUpperCase(words[i].charAt(0))); |
| 81 | + builder.append(words[i].substring(1)); |
| 82 | + builder.append(' '); |
| 83 | + } |
82 | 84 |
|
83 | | - return builder.toString().trim(); |
84 | | - } |
| 85 | + return builder.toString().trim(); |
| 86 | + } |
85 | 87 |
|
86 | 88 | @Test |
87 | 89 | public void testLookup() throws Exception { |
|
0 commit comments