-
Notifications
You must be signed in to change notification settings - Fork 340
Add coverage for ForeignMemoryWriterFactory #11772
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| package datadog.trace.core.servicediscovery; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
| import static org.junit.jupiter.api.Assertions.assertNull; | ||
| import static org.junit.jupiter.api.Assertions.assertTrue; | ||
| import static org.mockito.Mockito.mockStatic; | ||
|
|
||
| import datadog.environment.JavaVirtualMachine; | ||
| import datadog.environment.OperatingSystem; | ||
| import org.junit.jupiter.api.Assumptions; | ||
| import org.mockito.MockedStatic; | ||
| import org.tabletest.junit.TableTest; | ||
|
|
||
| class ForeignMemoryWriterFactoryTest { | ||
|
|
||
| @TableTest({ | ||
| "scenario | osType | architecture | javaAtLeast22 | expectedClassFragment", | ||
| "macOS | MACOS | X64 | false | ", | ||
| "Windows | WINDOWS | X64 | false | ", | ||
| "Linux unknown arch | LINUX | UNKNOWN | false | ", | ||
| "Linux pre-Java22 | LINUX | X64 | false | JNA ", | ||
| "Linux Java22+ | LINUX | X64 | true | FFM " | ||
| }) | ||
| void get( | ||
| String scenario, | ||
| String osType, | ||
| String architecture, | ||
| boolean javaAtLeast22, | ||
| String expectedClassFragment) { | ||
| // MemFDUnixWriterFFM uses java.lang.foreign and will fail to load on pre-22 JVMs | ||
| boolean realJavaAtLeast22 = JavaVirtualMachine.isJavaVersionAtLeast(22); | ||
| Assumptions.assumeTrue(!javaAtLeast22 || realJavaAtLeast22, "FFM writer requires Java 22+"); | ||
| try (MockedStatic<OperatingSystem> osMock = mockStatic(OperatingSystem.class); | ||
| MockedStatic<JavaVirtualMachine> jvmMock = mockStatic(JavaVirtualMachine.class)) { | ||
| osMock.when(OperatingSystem::type).thenReturn(OperatingSystem.Type.valueOf(osType)); | ||
| osMock | ||
| .when(OperatingSystem::architecture) | ||
| .thenReturn(OperatingSystem.Architecture.valueOf(architecture)); | ||
| jvmMock.when(() -> JavaVirtualMachine.isJavaVersionAtLeast(22)).thenReturn(javaAtLeast22); | ||
|
|
||
| ForeignMemoryWriter writer = new ForeignMemoryWriterFactory().get(); | ||
|
|
||
| if (expectedClassFragment == null) { | ||
| assertNull(writer, scenario); | ||
| } else { | ||
| assertNotNull(writer, scenario); | ||
| assertTrue(writer.getClass().getName().contains(expectedClassFragment), scenario); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| mock-maker-inline | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❔ question: Will it impact other mocks from the module too?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes As an additional note this mockmaker is the default since mockito 5.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that for OperatingSystem/SystemProperties and CO, we should work for a better testability interop (or at least design the class that use it to receive a mock) if we want to avoid mocking statically |
||
Uh oh!
There was an error while loading. Please reload this page.