From 887ec588b61c5ab90eacfaad1865ad9182f80e2c Mon Sep 17 00:00:00 2001 From: Michael Hoennig Date: Fri, 18 Oct 2024 10:48:33 +0200 Subject: [PATCH] encapsulate aliases+properties --- .../hsadminng/hs/office/usecases/UseCase.java | 20 ++++++------------- .../hs/office/usecases/UseCaseTest.java | 20 +++++++++++++++++-- 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/usecases/UseCase.java b/src/test/java/net/hostsharing/hsadminng/hs/office/usecases/UseCase.java index da1b03b0..3adf416a 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/usecases/UseCase.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/usecases/UseCase.java @@ -1,17 +1,13 @@ package net.hostsharing.hsadminng.hs.office.usecases; -import com.tngtech.archunit.thirdparty.com.google.common.collect.Streams; import io.restassured.RestAssured; import io.restassured.http.ContentType; import io.restassured.response.Response; import io.restassured.response.ValidatableResponse; -import lombok.SneakyThrows; import org.apache.commons.collections4.map.LinkedMap; import org.springframework.http.HttpMethod; import org.springframework.http.HttpStatus; -import java.nio.file.Files; -import java.nio.file.Paths; import java.util.ArrayList; import java.util.Map; import java.util.UUID; @@ -20,11 +16,7 @@ import java.util.function.Function; import java.util.function.Supplier; import java.util.regex.Pattern; import java.util.stream.Collectors; -import java.util.stream.Stream; -import static java.nio.file.StandardOpenOption.APPEND; -import static java.nio.file.StandardOpenOption.CREATE; -import static java.nio.file.StandardOpenOption.TRUNCATE_EXISTING; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assumptions.assumeThat; import static org.hamcrest.Matchers.startsWith; @@ -50,16 +42,16 @@ public abstract class UseCase> { } public final void requires(final String alias, final Function> useCaseFactory) { - if ( !UseCaseTest.aliases.containsKey(alias) ) { + if ( !UseCaseTest.containsAlias(alias) ) { requirements.put(alias, useCaseFactory); } } public void requires(final String alias) { - assumeThat(UseCaseTest.aliases.containsKey(alias)) + assumeThat(UseCaseTest.containsAlias(alias)) .as("skipping because alias '" + alias + "' not found, maybe the other test failed?") .isTrue(); - log("depends on ["+alias+"]("+UseCaseTest.aliases.get(alias).useCase().getSimpleName()+".md)"); + log("depends on ["+alias+"]("+UseCaseTest.getAlias(alias).useCase().getSimpleName()+".md)"); } public final HttpResponse doRun() { @@ -70,7 +62,7 @@ public abstract class UseCase> { protected abstract HttpResponse run(); public final UseCase given(final String propName, final Object propValue) { - UseCaseTest.properties.put(propName, propValue); + UseCaseTest.putProperty(propName, propValue); return this; } @@ -105,7 +97,7 @@ public abstract class UseCase> { } public final UUID uuid(final String alias) { - return UseCaseTest.aliases.get(alias).uuid(); + return UseCaseTest.getAlias(alias).uuid(); } static class JsonTemplate { @@ -196,7 +188,7 @@ public abstract class UseCase> { } public void keep() { - UseCaseTest.aliases.put( + UseCaseTest.putAlias( nextTitle != null ? nextTitle : resultAlias, new UseCaseTest.Alias<>(UseCase.this.getClass(), locationUuid)); } diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/usecases/UseCaseTest.java b/src/test/java/net/hostsharing/hsadminng/hs/office/usecases/UseCaseTest.java index d8819db0..17c393fc 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/usecases/UseCaseTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/usecases/UseCaseTest.java @@ -34,8 +34,8 @@ public abstract class UseCaseTest extends ContextBasedTest { record Alias>(Class useCase, UUID uuid) {} - final static Map> aliases = new HashMap<>(); - final static Map properties = new HashMap<>(); + private final static Map> aliases = new HashMap<>(); + private final static Map properties = new HashMap<>(); @LocalServerPort Integer port; @@ -81,6 +81,22 @@ public abstract class UseCaseTest extends ContextBasedTest { markdownFile.println(output); } + static boolean containsAlias(final String alias) { + return aliases.containsKey(alias); + } + + static Alias getAlias(final String alias) { + return aliases.get(alias); + } + + static void putAlias(final String name, final Alias value) { + aliases.put(name, value); + } + + static void putProperty(final String name, final Object value) { + properties.put(name, value); + } + static Stream> knowVariables() { return Streams.concat( UseCaseTest.aliases.entrySet().stream().map(e -> Map.entry(e.getKey(), e.getValue().uuid())),