Skip to content

Commit 31753a6

Browse files
committed
feat(http): Add NotFoundException and MethodNotAllowedException
1 parent 1539616 commit 31753a6

3 files changed

Lines changed: 46 additions & 0 deletions

File tree

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.retailsvc.http;
2+
3+
import com.retailsvc.http.spec.HttpMethod;
4+
import java.util.Set;
5+
6+
public final class MethodNotAllowedException extends RuntimeException {
7+
private final Set<HttpMethod> allowed;
8+
9+
public MethodNotAllowedException(Set<HttpMethod> allowed) {
10+
super("method not allowed; allowed=" + allowed);
11+
this.allowed = Set.copyOf(allowed);
12+
}
13+
14+
public Set<HttpMethod> allowed() {
15+
return allowed;
16+
}
17+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.retailsvc.http;
2+
3+
public final class NotFoundException extends RuntimeException {
4+
public NotFoundException(String message) {
5+
super(message);
6+
}
7+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.retailsvc.http;
2+
3+
import static org.assertj.core.api.Assertions.assertThat;
4+
5+
import com.retailsvc.http.spec.HttpMethod;
6+
import java.util.Set;
7+
import org.junit.jupiter.api.Test;
8+
9+
class HttpExceptionsTest {
10+
@Test
11+
void notFoundCarriesPath() {
12+
NotFoundException e = new NotFoundException("GET /missing");
13+
assertThat(e.getMessage()).isEqualTo("GET /missing");
14+
}
15+
16+
@Test
17+
void methodNotAllowedCarriesAllowedSet() {
18+
MethodNotAllowedException e =
19+
new MethodNotAllowedException(Set.of(HttpMethod.GET, HttpMethod.POST));
20+
assertThat(e.allowed()).containsExactlyInAnyOrder(HttpMethod.GET, HttpMethod.POST);
21+
}
22+
}

0 commit comments

Comments
 (0)