Skip to content

Commit

Permalink
Fix missing assertion in test and reduce the amount of duplication be…
Browse files Browse the repository at this point in the history
…tween MultiResource and MultiResourceUni
  • Loading branch information
cescoffier committed Mar 11, 2021
1 parent 30da80a commit 24ebf3a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,16 @@ public MultiResource(Supplier<? extends R> resourceSupplier,
* @return the multi
*/
public Multi<I> withFinalizer(Consumer<? super R> finalizer) {
Function<? super R, Uni<Void>> actual = getUniFunction(finalizer);
return withFinalizer(actual, (r, ignored) -> actual.apply(r), actual);
}

static <R> Function<? super R, Uni<Void>> getUniFunction(Consumer<? super R> finalizer) {
Consumer<? super R> callback = Infrastructure.decorate(ParameterValidation.nonNull(finalizer, "finalizer"));
Function<? super R, Uni<Void>> actual = r -> {
return r -> {
callback.accept(r);
return Uni.createFrom().voidItem();
};
return withFinalizer(actual, (r, ignored) -> actual.apply(r), actual);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.smallrye.mutiny.groups;

import static io.smallrye.mutiny.groups.MultiResource.getUniFunction;

import java.util.function.BiFunction;
import java.util.function.Consumer;
import java.util.function.Function;
Expand Down Expand Up @@ -41,11 +43,7 @@ public MultiResourceUni(Supplier<Uni<R>> resourceSupplier,
* @return the multi
*/
public Multi<I> withFinalizer(Consumer<? super R> finalizer) {
Consumer<? super R> callback = Infrastructure.decorate(ParameterValidation.nonNull(finalizer, "finalizer"));
Function<? super R, Uni<Void>> actual = r -> {
callback.accept(r);
return Uni.createFrom().voidItem();
};
Function<? super R, Uni<Void>> actual = getUniFunction(finalizer);
return withFinalizer(actual, (r, ignored) -> actual.apply(r), actual);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public void testThatEmitterIsDisposed() {

subscriber.assertCompleted();
assertThat(reference.get()).isInstanceOf(DefaultUniEmitter.class)
.satisfies(e -> ((DefaultUniEmitter<? super Void>) e).isTerminated());
.satisfies(e -> assertThat(((DefaultUniEmitter<? super Void>) e).isTerminated()).isTrue());
}

@Test
Expand Down

0 comments on commit 24ebf3a

Please sign in to comment.