11package me .proxer .library .api ;
22
33import me .proxer .library .ProxerTest ;
4+ import me .proxer .library .api .ProxerException .ErrorType ;
5+ import me .proxer .library .api .ProxerException .ServerErrorType ;
46import me .proxer .library .entitiy .notifications .NewsArticle ;
57import okhttp3 .mockwebserver .MockResponse ;
68import okhttp3 .mockwebserver .SocketPolicy ;
@@ -25,7 +27,7 @@ public void testTimeoutError() throws IOException {
2527 .setSocketPolicy (SocketPolicy .NO_RESPONSE ));
2628
2729 assertThatExceptionOfType (ProxerException .class ).isThrownBy (() -> api .notifications ().news ().build ().execute ())
28- .has (new Condition <Throwable >(e -> ((ProxerException ) e ).getErrorType () == ProxerException . ErrorType .TIMEOUT ,
30+ .has (new Condition <Throwable >(e -> ((ProxerException ) e ).getErrorType () == ErrorType .TIMEOUT ,
2931 "TIMEOUT ErrorType" ));
3032 }
3133
@@ -34,7 +36,7 @@ public void testIOError() throws IOException {
3436 server .enqueue (new MockResponse ().setBody (fromResource ("news.json" )).setResponseCode (404 ));
3537
3638 assertThatExceptionOfType (ProxerException .class ).isThrownBy (() -> api .notifications ().news ().build ().execute ())
37- .has (new Condition <Throwable >(e -> ((ProxerException ) e ).getErrorType () == ProxerException . ErrorType .IO ,
39+ .has (new Condition <Throwable >(e -> ((ProxerException ) e ).getErrorType () == ErrorType .IO ,
3840 "IO ErrorType" ));
3941 }
4042
@@ -43,7 +45,7 @@ public void testInvalidEncodingError() throws IOException {
4345 server .enqueue (new MockResponse ().setBody (fromResource ("news.json" ).replace (":" , "invalid" )));
4446
4547 assertThatExceptionOfType (ProxerException .class ).isThrownBy (() -> api .notifications ().news ().build ().execute ())
46- .has (new Condition <Throwable >(e -> ((ProxerException ) e ).getErrorType () == ProxerException . ErrorType .IO ,
48+ .has (new Condition <Throwable >(e -> ((ProxerException ) e ).getErrorType () == ErrorType .IO ,
4749 "IO ErrorType" ));
4850 }
4951
@@ -52,10 +54,23 @@ public void testInvalidDataError() throws IOException {
5254 server .enqueue (new MockResponse ().setBody (fromResource ("news.json" ).replace ("256" , "invalid" )));
5355
5456 assertThatExceptionOfType (ProxerException .class ).isThrownBy (() -> api .notifications ().news ().build ().execute ())
55- .has (new Condition <Throwable >(e -> ((ProxerException ) e ).getErrorType () == ProxerException . ErrorType .PARSING ,
57+ .has (new Condition <Throwable >(e -> ((ProxerException ) e ).getErrorType () == ErrorType .PARSING ,
5658 "PARSING ErrorType" ));
5759 }
5860
61+ @ Test
62+ public void testServerError () throws Exception {
63+ server .enqueue (new MockResponse ().setBody (fromResource ("conferences_error.json" )));
64+
65+ assertThatExceptionOfType (ProxerException .class ).isThrownBy (() -> api .messenger ().conferences ().build ().execute ())
66+ .has (new Condition <Throwable >(e -> ((ProxerException ) e ).getErrorType () == ErrorType .SERVER ,
67+ "SERVER ErrorType" ))
68+ .has (new Condition <Throwable >(e -> ((ProxerException ) e ).getServerErrorType () == ServerErrorType .MESSAGES_LOGIN_REQUIRED ,
69+ "MESSAGES_LOGIN_REQUIRED ServerErrorType" ))
70+ .has (new Condition <Throwable >(e -> e .getMessage ().equals ("Du bist nicht eingeloggt." ),
71+ "Message is equal" ));
72+ }
73+
5974 @ Test (timeout = 1000L )
6075 public void testEnqueue () throws IOException , InterruptedException {
6176 final CountDownLatch lock = new CountDownLatch (1 );
@@ -80,7 +95,7 @@ public void testEnqueueError() throws IOException, InterruptedException {
8095 // Failed. The lock will never be counted down and timeout.
8196 },
8297 exception -> {
83- if (exception .getErrorType () == ProxerException . ErrorType .IO ) {
98+ if (exception .getErrorType () == ErrorType .IO ) {
8499 lock .countDown ();
85100 }
86101
@@ -112,7 +127,7 @@ public void testCancel() throws IOException, InterruptedException {
112127 call .enqueue (result -> {
113128 // Failed. The lock will never be counted down and timeout.
114129 }, exception -> {
115- if (exception .getErrorType () == ProxerException . ErrorType .IO ) {
130+ if (exception .getErrorType () == ErrorType .IO ) {
116131 lock .countDown ();
117132 }
118133
0 commit comments