Skip to content

Commit

Permalink
Merge pull request #1280 from holunda-io/bug/1278__fix_zeebe_test_ext…
Browse files Browse the repository at this point in the history
…ension

Don't use JUnit internal API
  • Loading branch information
megglos authored Jan 6, 2025
2 parents d1b258a + 6d9b92a commit 9344359
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 14 deletions.
5 changes: 0 additions & 5 deletions extension-testcontainer/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,6 @@
<artifactId>zeebe-process-test-filters</artifactId>
</dependency>

<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-commons</artifactId>
</dependency>

<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import org.junit.jupiter.api.extension.BeforeEachCallback;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.jupiter.api.extension.TestWatcher;
import org.junit.platform.commons.util.ReflectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -148,7 +147,7 @@ private Optional<Field> getField(final Class<?> requiredTestClass, final Class<?
+ "found %s. Please make sure at most one field of type %s has been declared in the"
+ " test class.",
clazz.getSimpleName(), fields.size(), clazz.getSimpleName()));
} else if (fields.size() == 0) {
} else if (fields.isEmpty()) {
final Class<?> superclass = requiredTestClass.getSuperclass();
return superclass == null ? Optional.empty() : getField(superclass, clazz);
} else {
Expand All @@ -159,7 +158,7 @@ private Optional<Field> getField(final Class<?> requiredTestClass, final Class<?
private void injectField(
final ExtensionContext extensionContext, final Field field, final Object object) {
try {
ReflectionUtils.makeAccessible(field);
field.setAccessible(true);
field.set(extensionContext.getRequiredTestInstance(), object);
} catch (final IllegalAccessException e) {
throw new RuntimeException(e);
Expand Down Expand Up @@ -190,7 +189,7 @@ private ObjectMapper getObjectMapper(final ExtensionContext context) {
}

final Field customMapper = customMapperOpt.get();
ReflectionUtils.makeAccessible(customMapper);
customMapper.setAccessible(true);
try {
return (ObjectMapper) customMapper.get(context.getRequiredTestInstance());
} catch (final IllegalAccessException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import org.junit.jupiter.api.extension.BeforeEachCallback;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.jupiter.api.extension.TestWatcher;
import org.junit.platform.commons.util.ReflectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -123,18 +122,18 @@ private Optional<Field> getField(final Class<?> requiredTestClass, final Class<?
+ "found %s. Please make sure at most one field of type %s has been declared in the"
+ " test class.",
clazz.getSimpleName(), fields.size(), clazz.getSimpleName()));
} else if (fields.size() == 0) {
} else if (fields.isEmpty()) {
final Class<?> superclass = requiredTestClass.getSuperclass();
return superclass == null ? Optional.empty() : getField(superclass, clazz);
} else {
return Optional.of(fields.get(0));
return Optional.of(fields.getFirst());
}
}

private void injectField(
final ExtensionContext extensionContext, final Field field, final Object object) {
try {
ReflectionUtils.makeAccessible(field);
field.setAccessible(true);
field.set(extensionContext.getRequiredTestInstance(), object);
} catch (final IllegalAccessException e) {
throw new RuntimeException(e);
Expand All @@ -159,7 +158,7 @@ private ObjectMapper getObjectMapper(final ExtensionContext context) {
}

final var customMapper = customMapperOpt.get();
ReflectionUtils.makeAccessible(customMapper);
customMapper.setAccessible(true);
try {
return (ObjectMapper) customMapper.get(context.getRequiredTestInstance());
} catch (final IllegalAccessException e) {
Expand Down

0 comments on commit 9344359

Please sign in to comment.