hosuaby / inject-resources

Simple and convenient way to read content of resource in Java.
http://inject-resources.hosuaby.io
Apache License 2.0
53 stars 5 forks source link

Library is compiled for preview JUnit 5.11.0-M2 #24

Closed michaldo closed 1 month ago

michaldo commented 1 month ago

Current JUnit version is 5.10.3 and code should be compiled to this version

inject-resources fails with

java.lang.NoSuchMethodError: 'java.lang.reflect.Field org.junit.platform.commons.util.ReflectionUtils.makeAccessible(java.lang.reflect.Field)'

hosuaby commented 1 month ago

Library is compiled to work with multiple versions of JUnit, and 5.10.3 is one of them. This exception with reflexion may be due to version of Java. Which version are you using?

michaldo commented 1 month ago

Library is compiled to work with multiple versions of JUnit, and 5.10.3 is one of them.

I would rather say "The library is compiled in hope to work with multiple versions of JUnit..."

It works with 5.11 with methods:

https://github.com/junit-team/junit5/blob/r5.11.0-M2/junit-platform-commons/src/main/java/org/junit/platform/commons/util/ReflectionUtils.java#L1905

It does not work with 5.10 with methods:

https://github.com/junit-team/junit5/blob/r5.10.3/junit-platform-commons/src/main/java/org/junit/platform/commons/util/ReflectionUtils.java#L1769

BTW, in order to work with multiple versions of JUnit, code like "makeAccessible" should be self-implemented

michaldo commented 1 month ago

The following code does not work for 5.10.3 and 0.3.4

@TestWithResources
class MyTest {

    @GivenTextResource("/file.txt")
    String file;

    @Test
    void test() {
        System.out.println(file);
    }

But the following, surprisingly works:

@Test
void test(@GivenTextResource("/file.txt") String file) {
    System.out.println(file); 

Java 21

hosuaby commented 1 month ago

I confirm this bug. looking for right solution.

hosuaby commented 1 month ago

Fixed in 0.3.5