Skip to content

Commit 5ea5a69

Browse files
committed
feat(spec): Add HttpMethod enum
1 parent 103cc03 commit 5ea5a69

2 files changed

Lines changed: 47 additions & 0 deletions

File tree

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.retailsvc.http.spec;
2+
3+
import java.util.Locale;
4+
5+
public enum HttpMethod {
6+
GET,
7+
POST,
8+
PUT,
9+
DELETE,
10+
PATCH,
11+
HEAD,
12+
OPTIONS,
13+
TRACE,
14+
CONNECT;
15+
16+
public static HttpMethod parse(String s) {
17+
return HttpMethod.valueOf(s.toUpperCase(Locale.ROOT));
18+
}
19+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.retailsvc.http.spec;
2+
3+
import static org.assertj.core.api.Assertions.assertThat;
4+
5+
import org.junit.jupiter.api.Test;
6+
7+
class HttpMethodTest {
8+
@Test
9+
void parsesUppercase() {
10+
assertThat(HttpMethod.parse("GET")).isEqualTo(HttpMethod.GET);
11+
}
12+
13+
@Test
14+
void parsesLowercase() {
15+
assertThat(HttpMethod.parse("get")).isEqualTo(HttpMethod.GET);
16+
}
17+
18+
@Test
19+
void parsesMixed() {
20+
assertThat(HttpMethod.parse("PaTcH")).isEqualTo(HttpMethod.PATCH);
21+
}
22+
23+
@Test
24+
void unknownThrows() {
25+
org.junit.jupiter.api.Assertions.assertThrows(
26+
IllegalArgumentException.class, () -> HttpMethod.parse("foo"));
27+
}
28+
}

0 commit comments

Comments
 (0)