Skip to content

Commit cbf98b6

Browse files
committed
Add unauthorized response
1 parent 2e18964 commit cbf98b6

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package httpserver.response;
2+
3+
import httpserver.Header;
4+
5+
public class UnauthorizedResponse implements Response {
6+
@Override
7+
public int getStatusCode() {
8+
return 401;
9+
}
10+
11+
@Override
12+
public byte[] getPayload() {
13+
return new byte[0];
14+
}
15+
16+
@Override
17+
public Header[] getHeaders() {
18+
return new Header[0];
19+
}
20+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package httpserver.response;
2+
3+
import httpserver.Header;
4+
import org.junit.Test;
5+
6+
import java.util.Arrays;
7+
8+
import static org.junit.Assert.*;
9+
10+
public class UnauthorizedResponseTest {
11+
private final UnauthorizedResponse unauthorizedResponse;
12+
13+
public UnauthorizedResponseTest() {
14+
unauthorizedResponse = new UnauthorizedResponse();
15+
}
16+
17+
@Test
18+
public void hasStatusCode405() throws Exception {
19+
assertEquals(401, unauthorizedResponse.getStatusCode());
20+
}
21+
22+
@Test
23+
public void hasEmptyPayload() throws Exception {
24+
assertTrue(Arrays.equals(new byte[0], unauthorizedResponse.getPayload()));
25+
}
26+
27+
@Test
28+
public void hasNoHeaders() throws Exception {
29+
assertTrue(Arrays.equals(new Header[0], unauthorizedResponse.getHeaders()));
30+
}
31+
}

0 commit comments

Comments
 (0)