Skip to content

Commit

Permalink
#1117 Document test customizers, add deprecation markers
Browse files Browse the repository at this point in the history
  • Loading branch information
GuusLieben committed Nov 1, 2024
1 parent 517f9f5 commit 4f8cec7
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package test.org.dockbox.hartshorn.inject.conditions;

import java.util.List;
import java.util.stream.Stream;

import org.dockbox.hartshorn.launchpad.ApplicationContext;
Expand All @@ -32,12 +31,9 @@
import org.dockbox.hartshorn.inject.condition.support.RequiresClass;
import org.dockbox.hartshorn.inject.condition.RequiresCondition;
import org.dockbox.hartshorn.inject.binding.BindingHierarchy;
import org.dockbox.hartshorn.test.TestCustomizer;
import org.dockbox.hartshorn.test.annotations.CustomizeTests;
import org.dockbox.hartshorn.test.annotations.TestComponents;
import org.dockbox.hartshorn.test.annotations.TestProperties;
import org.dockbox.hartshorn.test.junit.HartshornIntegrationTest;
import org.dockbox.hartshorn.util.TypeUtils;
import org.dockbox.hartshorn.util.introspect.view.MethodView;
import org.dockbox.hartshorn.util.introspect.view.TypeView;
import org.junit.jupiter.api.Assertions;
Expand All @@ -56,27 +52,12 @@
"--property.d=d",
"--property.e=otherValue"
})
@DemoActivator
public class ConditionTests {

@Inject
private ApplicationContext applicationContext;

@CustomizeTests
public static void factory() {
TestCustomizer.BUILDER.compose(builder -> {
builder.arguments(List.of(
"--property.c=o",
"--property.d=d",
"--property.e=otherValue"
));
});
TestCustomizer.CONSTRUCTOR.compose(constructor -> {
constructor.activators(activators -> {
activators.add(TypeUtils.annotation(DemoActivator.class));
});
});
}

public static Stream<Arguments> properties() {
return Stream.of(
Arguments.of("a", true),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@

package test.org.dockbox.hartshorn.inject.conditions;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import org.dockbox.hartshorn.launchpad.activation.ServiceActivator;

@Retention(RetentionPolicy.RUNTIME)
@ServiceActivator
public @interface DemoActivator {
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,12 @@
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

@HartshornIntegrationTest(includeBasePackages = false)
@HartshornIntegrationTest(
includeBasePackages = false,
processors = SimpleContextConfiguringComponentProcessor.class
)
public class ContextConfiguringComponentProcessorTests {

@CustomizeTests
public static void customize() {
TestCustomizer.CONSTRUCTOR.compose(constructor -> {
constructor.componentPostProcessors(processors -> {
processors.add(new SimpleContextConfiguringComponentProcessor());
});
});
}

@Test
@TestComponents(components = EmptyComponent.class)
void testNonContextComponentIsProcessed(@Inject EmptyComponent emptyComponent, @Inject ProxyOrchestrator proxyOrchestrator) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,25 @@
import org.dockbox.hartshorn.launchpad.environment.ContextualApplicationEnvironment;
import org.dockbox.hartshorn.util.Customizer;

/**
* A utility class to provide customizers for the various components of the test suite. These customizers are consumed
* by the {@link IntegrationTestApplicationFactoryCustomizer} to apply customizations to the application factory.
*
* @param <T> the type of the customizer
*
* @since 0.7.0
*
* @author Guus Lieben
*/
public final class TestCustomizer<T> {

@Deprecated(forRemoval = true, since = "0.7.0")
public static final TestCustomizer<StandardApplicationBuilder.Configurer> BUILDER = new TestCustomizer<>();

public static final TestCustomizer<ContextualApplicationEnvironment.Configurer> ENVIRONMENT = new TestCustomizer<>();
@Deprecated(forRemoval = true, since = "0.7.0")
public static final TestCustomizer<StandardApplicationContextFactory.Configurer> CONSTRUCTOR = new TestCustomizer<>();
@Deprecated(forRemoval = true, since = "0.7.0")
public static final TestCustomizer<SimpleApplicationContext.Configurer> APPLICATION_CONTEXT = new TestCustomizer<>();

private Customizer<T> customizer = Customizer.useDefaults();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,15 @@
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.dockbox.hartshorn.test.TestCustomizer;

/**
* Marks a method within a test class as capable of customizing the test environment, typically through
* the {@link TestCustomizer} utility class.
*
* <p>For example, a test class may have a method annotated with {@code @CustomizeTests} that sets up a
*
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(java.lang.annotation.ElementType.METHOD)
public @interface CustomizeTests {
Expand Down

0 comments on commit 4f8cec7

Please sign in to comment.