-
Notifications
You must be signed in to change notification settings - Fork 324
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
system lambda jdk 16 compatibility issue #1942
Comments
We could use the static mocking feature of Mockito 3.4.0+ to work around that: https://javadoc.io/doc/org.mockito/mockito-core/latest/org/mockito/Mockito.html#48 This requires the Example: try (MockedStatic mocked = mockStatic(System.class)) {
Map<String, String> mockedEnv = new HashMap(System.getenv());
mockedEnv.put("foo", "bar");
mocked.when(System::getenv).thenReturn(mockedEnv);
assertEquals("bar", System.getenv().get("foo"));
} |
|
Hmm.. Then two more ideas.
|
Alternatively, we could also create a very small abstraction over the calls to |
Yes, that's probably the simplest and cleanest approach 🙂 |
I actually took my chances with the instrumentation approach, mainly because it is much more fun, but also I think it is actually cleaner than changing production code for testing purposes. |
Closed by #2195 |
We use system-lambda for testing custom environment variables.
There is a known compatibility issue with JDK16 that makes some of our tests to fail.
There is no reliable work-around for now, the only option would be to modify our test implementation (and possibly use another way to mock dependencies on
System
class, at least to set environment variables.Known affected test(s)
co.elastic.apm.agent.impl.payload.ContainerInfoTest.testKubernetesDownwardApi
How to reproduce:
Work-around (not usable outside of testing)
--add-opens=java.base/java.util=ALL-UNNAMED
into JVM argumentsStack trace:
The text was updated successfully, but these errors were encountered: