Verified Commit 9e0fc9e7 authored by roebert's avatar roebert 👻
Browse files

.

parent c0e8986a
Pipeline #56059 passed with stages
in 6 minutes and 55 seconds
/*
* Copyright (c) 2020-2021.
*
* This file is part of drasyl.
*
* drasyl is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* drasyl is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with drasyl. If not, see <http://www.gnu.org/licenses/>.
*/
package org.drasyl.util;
import io.reactivex.rxjava3.observers.BaseTestConsumer;
import org.drasyl.annotation.NonNull;
import java.util.Arrays;
import java.util.List;
public final class RxJavaTestUtil {
private RxJavaTestUtil() {
// util class
}
/**
* Assert that the {@code TestObserver}/{@code TestSubscriber} received only the specified
* values in any order.
*
* @param values the values expected
* @return {@code baseTestConsumer}
*/
@SafeVarargs
@NonNull
public static <T, U extends BaseTestConsumer<T, U>> U assertValues(@NonNull final U baseTestConsumer,
@NonNull final T... values) {
final List<T> actualValues = baseTestConsumer.values();
final int s = actualValues.size();
if (s != values.length) {
throw new AssertionError("Value count differs; expected: " + values.length
+ " " + Arrays.toString(values) + " but was: " + s + " " + actualValues);
}
for (final T value : values) {
if (!actualValues.contains(value)) {
throw new AssertionError("expected: " + U.valueAndClass(value)
+ " but was not included");
}
}
return baseTestConsumer;
}
}
......@@ -45,7 +45,6 @@ import org.drasyl.plugin.groups.manager.data.Membership;
import org.drasyl.plugin.groups.manager.database.DatabaseAdapter;
import org.drasyl.plugin.groups.manager.database.DatabaseException;
import org.drasyl.serialization.JacksonJsonSerializer;
import org.drasyl.util.RxJavaTestUtil;
import org.drasyl.util.scheduler.DrasylScheduler;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Nested;
......@@ -54,6 +53,7 @@ import org.junit.jupiter.api.Timeout;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import test.util.RxJavaTestUtil;
import java.time.Duration;
import java.util.Set;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment