1- package com .sap .ai .sdk .foundationmodels . openai ;
1+ package com .sap .ai .sdk .core . commons ;
22
33import static org .assertj .core .api .Assertions .assertThat ;
44import static org .assertj .core .api .Assertions .assertThatThrownBy ;
1818import java .nio .charset .StandardCharsets ;
1919import java .util .concurrent .atomic .AtomicInteger ;
2020import lombok .SneakyThrows ;
21+ import lombok .experimental .StandardException ;
2122import org .apache .hc .core5 .http .ContentType ;
2223import org .apache .hc .core5 .http .io .entity .InputStreamEntity ;
2324import org .junit .jupiter .api .DisplayName ;
@@ -33,7 +34,7 @@ void testLines() {
3334 final var inputStream = spy (new ByteArrayInputStream (input .getBytes (StandardCharsets .UTF_8 )));
3435 final var entity = new InputStreamEntity (inputStream , ContentType .TEXT_PLAIN );
3536
36- final var sut = IterableStreamConverter .lines (entity );
37+ final var sut = IterableStreamConverter .lines (entity , TestClientException :: new );
3738 verify (inputStream , never ()).read ();
3839 verify (inputStream , never ()).read (any ());
3940 verify (inputStream , never ()).read (any (), anyInt (), anyInt ());
@@ -69,7 +70,7 @@ void testLinesFindFirst() {
6970
7071 final var entity = new InputStreamEntity (inputStream , ContentType .TEXT_PLAIN );
7172
72- final var sut = IterableStreamConverter .lines (entity );
73+ final var sut = IterableStreamConverter .lines (entity , TestClientException :: new );
7374 assertThat (sut .findFirst ()).contains ("Foo Bar" );
7475 verify (inputStream , times (1 )).read (any (), anyInt (), anyInt ());
7576 verify (inputStream , never ()).close ();
@@ -93,14 +94,17 @@ void testLinesThrows() {
9394
9495 final var entity = new InputStreamEntity (inputStream , ContentType .TEXT_PLAIN );
9596
96- final var sut = IterableStreamConverter .lines (entity );
97+ final var sut = IterableStreamConverter .lines (entity , TestClientException :: new );
9798 assertThatThrownBy (sut ::count )
98- .isInstanceOf (OpenAiClientException .class )
99+ .isInstanceOf (TestClientException .class )
99100 .hasMessage ("Parsing response content was interrupted." )
100101 .cause ()
101102 .isInstanceOf (IOException .class )
102103 .hasMessage ("Ups!" );
103104 verify (inputStream , times (2 )).read (any (), anyInt (), anyInt ());
104105 verify (inputStream , times (1 )).close ();
105106 }
107+
108+ @ StandardException
109+ public static class TestClientException extends ClientException {}
106110}
0 commit comments