@@ -37,7 +37,6 @@ import org.mockito.Mockito.verify
3737import org.mockito.Mockito.verifyNoMoreInteractions
3838import org.mockito.junit.jupiter.MockitoExtension
3939import java.io.ByteArrayInputStream
40- import java.io.IOException
4140import java.io.InputStream
4241import java.net.http.HttpHeaders
4342import java.net.http.HttpResponse.BodyHandler
@@ -118,9 +117,6 @@ internal class DecompressingBodyHandlerTest {
118117
119118 @ParameterizedTest
120119 @ValueSource(strings = [" gzip" , " x-gzip" ])
121- @Throws(
122- IOException ::class
123- )
124120 fun shouldReturnGzipInputStream (directive : String? ) {
125121 val gzipContent = ByteArrayInputStream (Compression .gzip(" abc" ))
126122
@@ -153,8 +149,7 @@ internal class DecompressingBodyHandlerTest {
153149 fun shouldThrowUnsupportedOperationException (directive : String? ) {
154150 // given
155151 val handler = BodyHandlers .decompressingBuilder()
156- .failOnUnsupportedDirectives(true )
157- .failOnUnknownDirectives(true )
152+ .lenient(false )
158153 .build(mockHandler) as DecompressingBodyHandler
159154
160155 // when + then
@@ -167,8 +162,7 @@ internal class DecompressingBodyHandlerTest {
167162 @ValueSource(strings = [" " , " abc" , " gz" , " a" ])
168163 fun shouldThrowIllegalArgumentException (directive : String? ) {
169164 val handler = BodyHandlers .decompressingBuilder()
170- .failOnUnsupportedDirectives(true )
171- .failOnUnknownDirectives(true )
165+ .lenient(false )
172166 .build(mockHandler) as DecompressingBodyHandler
173167 // when + then
174168 assertThatIllegalArgumentException()
@@ -178,8 +172,7 @@ internal class DecompressingBodyHandlerTest {
178172
179173 @ParameterizedTest
180174 @ValueSource(strings = [" compress" , " br" ])
181- @DisplayName(" Should not throw exception when 'failOnUnsupportedDirectives' is 'false'" )
182- fun shouldNotThrowUnsupportedOperationException (directive : String? ) {
175+ fun `Should not throw exception when 'failOnUnsupportedDirectives' is 'false'` (directive : String? ) {
183176 // given
184177 val handler = BodyHandlers .decompressingBuilder()
185178 .failOnUnsupportedDirectives(false )
@@ -213,5 +206,22 @@ internal class DecompressingBodyHandlerTest {
213206 // then
214207 actual shouldBeSameInstanceAs s
215208 }
209+
210+ @ParameterizedTest
211+ @ValueSource(strings = [" " , " abc" , " gz" , " a" ])
212+ fun `Should not throw exception in lenient mode` (directive : String? ) {
213+ // given
214+ val handler = BodyHandlers .decompressingBuilder()
215+ .lenient(true )
216+ .build(mockHandler) as DecompressingBodyHandler
217+ val s = InputStream .nullInputStream()
218+
219+ // when
220+ val fn = handler.decompressionFn(directive)
221+ val actual = fn.apply (s)
222+
223+ // then
224+ actual shouldBeSameInstanceAs s
225+ }
216226 }
217227}
0 commit comments