2323
2424public final class ErrorTypeTest {
2525
26+ @ Test
27+ public void testNameMustBeCamelCase () throws Exception {
28+ assertThatThrownBy (() -> ErrorType .of (ErrorType .Code .FAILED_PRECONDITION , "foo" ))
29+ .isInstanceOf (IllegalArgumentException .class )
30+ .hasMessageStartingWith ("ErrorType names must be UpperCamelCase: foo" );
31+
32+ assertThatThrownBy (() -> ErrorType .custom ("foo" , 400 ))
33+ .isInstanceOf (IllegalArgumentException .class )
34+ .hasMessageStartingWith ("ErrorType names must be UpperCamelCase: foo" );
35+ assertThatThrownBy (() -> ErrorType .custom ("fooBar" , 400 ))
36+ .isInstanceOf (IllegalArgumentException .class )
37+ .hasMessageStartingWith ("ErrorType names must be UpperCamelCase: fooBar" );
38+ assertThatThrownBy (() -> ErrorType .custom ("" , 400 ))
39+ .isInstanceOf (IllegalArgumentException .class )
40+ .hasMessageStartingWith ("ErrorType names must be UpperCamelCase: " );
41+ }
42+
2643 @ Test
2744 public void testDefaultErrorTypeHttpErrorCodes () throws Exception {
2845 assertThat (ErrorType .UNKNOWN .httpErrorCode ()).isEqualTo (500 );
@@ -34,29 +51,29 @@ public void testDefaultErrorTypeHttpErrorCodes() throws Exception {
3451
3552 @ Test
3653 public void testCustomErrors () throws Exception {
37- ErrorType custom400 = ErrorType .custom ("myDesc " , 400 );
54+ ErrorType custom400 = ErrorType .custom ("MyDesc " , 400 );
3855 assertThat (custom400 .code ()).isEqualTo (ErrorType .Code .CUSTOM );
3956 assertThat (custom400 .httpErrorCode ()).isEqualTo (400 );
40- assertThat (custom400 .name ()).isEqualTo ("myDesc " );
57+ assertThat (custom400 .name ()).isEqualTo ("MyDesc " );
4158
42- ErrorType custom500 = ErrorType .custom ("myDesc " , 500 );
59+ ErrorType custom500 = ErrorType .custom ("MyDesc " , 500 );
4360 assertThat (custom500 .code ()).isEqualTo (ErrorType .Code .CUSTOM );
4461 assertThat (custom500 .httpErrorCode ()).isEqualTo (500 );
45- assertThat (custom500 .name ()).isEqualTo ("myDesc " );
62+ assertThat (custom500 .name ()).isEqualTo ("MyDesc " );
4663
47- assertThatThrownBy (() -> ErrorType .custom ("myDesc " , 403 ))
64+ assertThatThrownBy (() -> ErrorType .custom ("MyDesc " , 403 ))
4865 .isInstanceOf (IllegalArgumentException .class )
4966 .hasMessage ("CUSTOM ErrorTypes must have HTTP error code 400 or 500" );
5067 }
5168
5269 @ Test
5370 public void testCanCreateNewErrorTypes () throws Exception {
54- ErrorType error = ErrorType .of (ErrorType .Code .FAILED_PRECONDITION , "myDesc " );
71+ ErrorType error = ErrorType .of (ErrorType .Code .FAILED_PRECONDITION , "MyDesc " );
5572 assertThat (error .code ()).isEqualTo (ErrorType .Code .FAILED_PRECONDITION );
5673 assertThat (error .httpErrorCode ()).isEqualTo (400 );
57- assertThat (error .name ()).isEqualTo ("myDesc " );
74+ assertThat (error .name ()).isEqualTo ("MyDesc " );
5875
59- assertThatThrownBy (() -> ErrorType .of (ErrorType .Code .CUSTOM , "myDesc " ))
76+ assertThatThrownBy (() -> ErrorType .of (ErrorType .Code .CUSTOM , "MyDesc " ))
6077 .isInstanceOf (IllegalArgumentException .class )
6178 .hasMessage ("Use the custom() method to construct ErrorTypes with code CUSTOM" );
6279 }
0 commit comments