1717package io.github.nstdio.http.ext
1818
1919import io.github.nstdio.http.ext.Assertions.assertThat
20+ import io.kotest.matchers.nulls.shouldBeNull
21+ import io.kotest.matchers.shouldBe
2022import org.assertj.core.api.Assertions.assertThat
2123import org.junit.jupiter.api.Assertions.assertFalse
2224import org.junit.jupiter.api.Assertions.assertTrue
2325import org.junit.jupiter.api.Test
2426import org.mockito.Mockito
27+ import org.mockito.Mockito.mock
2528import org.mockito.Mockito.verify
29+ import org.mockito.Mockito.verifyNoInteractions
2630import org.mockito.Mockito.verifyNoMoreInteractions
2731import java.util.function.Consumer
2832import java.util.function.ToIntFunction
@@ -180,7 +184,7 @@ class LruMultimapTest {
180184
181185 // then
182186 assertThat(map).isEmpty
183- Mockito . verifyNoInteractions(mockEl)
187+ verifyNoInteractions(mockEl)
184188 }
185189
186190 @Test
@@ -217,7 +221,7 @@ class LruMultimapTest {
217221 }
218222
219223 @Suppress(" UNCHECKED_CAST" )
220- private fun mockConsumer () = Mockito . mock(Consumer ::class .java) as Consumer <String ?>
224+ private fun mockConsumer () = mock(Consumer ::class .java) as Consumer <String ?>
221225
222226 @Test
223227 fun shouldEvictAllForNonExistingKey () {
@@ -232,6 +236,27 @@ class LruMultimapTest {
232236
233237 // then
234238 assertThat(map).hasMapSize(1 ).hasSize(2 )
235- Mockito .verifyNoInteractions(mockEl)
239+ verifyNoInteractions(mockEl)
240+ }
241+
242+ @Test
243+ fun `Should remove` () {
244+ // given
245+ val map = LruMultimap <String , String >(8 , null )
246+ val nonExistingKeyFn = mock(ToIntFunction ::class .java) as ToIntFunction <List <String >>
247+
248+ // when
249+ map.putSingle(" a" , " 1" , addFn)
250+ map.putSingle(" a" , " 2" , addFn)
251+ map.putSingle(" b" , " 2" , addFn)
252+
253+
254+ // then
255+ map.remove(" a" ) { 2 }.shouldBeNull()
256+ map.remove(" a" ) { - 1 }.shouldBeNull()
257+ map.remove(" a" ) { 0 }.shouldBe(" 2" )
258+ map.remove(" b" ) { 0 }.shouldBe(" 2" )
259+ map.remove(" c" , nonExistingKeyFn).shouldBeNull()
260+ verifyNoInteractions(nonExistingKeyFn)
236261 }
237262}
0 commit comments