Skip to content

Commit

Permalink
style: reformat test files
Browse files Browse the repository at this point in the history
  • Loading branch information
jponge committed Nov 19, 2024
1 parent 7bf5dc4 commit 066db16
Showing 1 changed file with 43 additions and 42 deletions.
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
package io.smallrye.mutiny.tcktests;

import io.smallrye.mutiny.Multi;
import io.smallrye.mutiny.helpers.Subscriptions;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;
import java.util.concurrent.Flow;

import org.testng.Assert;
import org.testng.annotations.Test;

import io.smallrye.mutiny.Multi;
import io.smallrye.mutiny.helpers.Subscriptions;

public class MultiSelectDistinctByKeyTckTest extends AbstractPublisherTck<MultiSelectDistinctByKeyTckTest.KeyTester> {
@Test
public void distinctStageShouldReturnDistinctElements() {
Expand All @@ -32,7 +34,7 @@ public void distinctStageShouldReturnDistinctElements() {
@Test
public void distinctStageShouldReturnAnEmptyStreamWhenCalledOnEmptyStreams() {
Assert.assertEquals(
Await.await(Multi.createFrom().<KeyTester>empty()
Await.await(Multi.createFrom().<KeyTester> empty()
.select().distinct(kt -> kt.id)
.collect().asList()
.subscribeAsCompletionStage()),
Expand All @@ -43,47 +45,46 @@ public void distinctStageShouldReturnAnEmptyStreamWhenCalledOnEmptyStreams() {
public void distinctStageShouldPropagateUpstreamExceptions() {
Assert.assertThrows(QuietRuntimeException.class,
() -> Await.await(
Multi.createFrom().<KeyTester>failure(new QuietRuntimeException("failed"))
Multi.createFrom().<KeyTester> failure(new QuietRuntimeException("failed"))
.select().distinct(kt -> kt.id)
.collect().asList()
.subscribeAsCompletionStage()));
}

@Test
public void distinctStageShouldPropagateExceptionsThrownByKeyEquals() {
Assert.assertThrows(
QuietRuntimeException.class,
() -> {
CompletableFuture<Void> cancelled = new CompletableFuture<>();
class ObjectThatThrowsFromKeyEquals {

Key key = new Key();

class Key {
@Override
public int hashCode() {
return 1;
}

@Override
public boolean equals(Object obj) {
throw new QuietRuntimeException("failed");
}
}
}
CompletionStage<List<ObjectThatThrowsFromKeyEquals>> result =
Multi.createFrom()
.items(new ObjectThatThrowsFromKeyEquals(), new ObjectThatThrowsFromKeyEquals())
.onTermination()
.invoke(() -> cancelled.complete(null))
.select()
.distinct(o -> o.key)
.collect()
.asList()
.subscribeAsCompletionStage();
Await.await(cancelled);
Await.await(result);
});
Assert.assertThrows(
QuietRuntimeException.class,
() -> {
CompletableFuture<Void> cancelled = new CompletableFuture<>();
class ObjectThatThrowsFromKeyEquals {

Key key = new Key();

class Key {
@Override
public int hashCode() {
return 1;
}

@Override
public boolean equals(Object obj) {
throw new QuietRuntimeException("failed");
}
}
}
CompletionStage<List<ObjectThatThrowsFromKeyEquals>> result = Multi.createFrom()
.items(new ObjectThatThrowsFromKeyEquals(), new ObjectThatThrowsFromKeyEquals())
.onTermination()
.invoke(() -> cancelled.complete(null))
.select()
.distinct(o -> o.key)
.collect()
.asList()
.subscribeAsCompletionStage();
Await.await(cancelled);
Await.await(result);
});
}

@Test
Expand All @@ -99,16 +100,16 @@ public void distinctStageShouldPropagateCancel() {

@Override
public Flow.Publisher<KeyTester> createFlowPublisher(long elements) {
return upstream(elements)
.map(id -> new KeyTester(id, "text-" + id))
.select().distinct(kt -> kt.id);
return upstream(elements)
.map(id -> new KeyTester(id, "text-" + id))
.select().distinct(kt -> kt.id);
}

@Override
public Flow.Publisher<KeyTester> createFailedFlowPublisher() {
return failedUpstream()
.map(id -> new KeyTester(id, "text-" + id))
.select().distinct(kt -> kt.id);
.map(id -> new KeyTester(id, "text-" + id))
.select().distinct(kt -> kt.id);
}

public static final class KeyTester {
Expand Down

0 comments on commit 066db16

Please sign in to comment.