forked from rsocket/rsocket-java
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rsocket#1077 type safe discard element consumer
- Loading branch information
Lukasz wycisk
committed
Dec 1, 2022
1 parent
e31038f
commit 8a30105
Showing
4 changed files
with
82 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
rsocket-core/src/test/java/io/rsocket/core/SendUtilsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package io.rsocket.core; | ||
|
||
import io.netty.util.ReferenceCounted; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.function.Consumer; | ||
|
||
import static org.mockito.Mockito.*; | ||
|
||
class SendUtilsTest { | ||
|
||
@Test | ||
void droppedElementsConsumerShouldAcceptOtherTypesThanReferenceCounted() { | ||
Consumer value = extractDroppedElementConsumer(); | ||
value.accept(new Object()); | ||
} | ||
|
||
@Test | ||
void droppedElementsConsumerReleaseReference() { | ||
ReferenceCounted referenceCounted = mock(ReferenceCounted.class); | ||
when(referenceCounted.release()).thenReturn(true); | ||
|
||
Consumer value = extractDroppedElementConsumer(); | ||
value.accept(referenceCounted); | ||
|
||
verify(referenceCounted).release(); | ||
} | ||
|
||
private static Consumer<?> extractDroppedElementConsumer() { | ||
return (Consumer<?>) SendUtils.DISCARD_CONTEXT.stream().findAny().get().getValue(); | ||
} | ||
} |