Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public Stream<TestTemplateInvocationContext> provideTestTemplateInvocationContex
// Get parameter values
final Object parameterValues;
try {
parameterProvider.setAccessible(true);
parameterValues = parameterProvider.invoke(null);
context.getStore(NAMESPACE).put(PARAMETERS_STORE_KEY, parameterValues);
} catch (Exception e) {
Expand Down Expand Up @@ -155,6 +156,7 @@ public FieldInjectingHook(Object[] parameterValues) {
@Override
public void beforeEach(ExtensionContext context) throws Exception {
for (int i = 0; i < parameterValues.length; i++) {
getParameterField(i, context).setAccessible(true);
getParameterField(i, context)
.set(context.getRequiredTestInstance(), parameterValues[i]);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.paimon.testutils.junit.parameterized;

import org.junit.jupiter.api.TestTemplate;
import org.junit.jupiter.api.extension.ExtendWith;

import java.util.Arrays;
import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;

/**
* Tests that {@link ParameterizedTestExtension} can reach the {@link Parameters} provider and the
* {@link Parameter} fields even when Java access control denies the extension access to them.
*
* <p>Both nested classes below are picked up by surefire on their own, because the unit test
* pattern {@code **}{@code /*Test.*} also matches nested class files.
*/
class ParameterizedTestExtensionTest {

private static final List<String> VALUES = Arrays.asList("a", "b");

/** The {@code @Parameters} provider is not accessible to the extension. */
@ExtendWith(ParameterizedTestExtension.class)
static class InaccessibleParameterProviderTest {

@Parameter public String value;

@Parameters(name = "value = {0}")
private static List<String> parameters() {
return VALUES;
}

@TestTemplate
void injectsValueFromInaccessibleProvider() {
assertThat(VALUES).contains(value);
}
}

/** The {@code @Parameter} field is not accessible to the extension. */
@ExtendWith(ParameterizedTestExtension.class)
static class InaccessibleParameterFieldTest {

@Parameter private String value;

@Parameters(name = "value = {0}")
public static List<String> parameters() {
return VALUES;
}

@TestTemplate
void injectsValueIntoInaccessibleField() {
assertThat(VALUES).contains(value);
}
}
}
Loading