import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.mockStatic;
import java.util.UUID;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.junit.jupiter.MockitoExtension;
@ExtendWith(MockitoExtension.class)
class DummyTest {
static final UUID dummyUUID = new UUID(1, 1);
@Test
void testUUIDMock() {
System.out.println("Before mocking: " + dummyUUID);
try (final var mockUUID = mockStatic(UUID.class)) {
System.out.println("After mocking: " + dummyUUID);
assertEquals("00000000-0000-0001-0000-000000000001", dummyUUID.toString());
}
}
}
fails and prints:
Before mocking: 00000000-0000-0001-0000-000000000001
After mocking: ��������-����-����-����-������������
org.opentest4j.AssertionFailedError:
Expected :00000000-0000-0001-0000-000000000001
Actual :��������-����-����-����-������������
Interestingly, editing the sample to
@Test
void testUUIDMock() {
System.out.println("Before mocking: " + dummyUUID);
try (final var mockUUID = mockStatic(UUID.class)) {
System.out.println("After mocking: " + dummyUUID);
}
System.out.println("After try: " + dummyUUID);
}
leads to
Before mocking: 00000000-0000-0001-0000-000000000001
After mocking: ��������-����-����-����-������������
After try: 00000000-0000-0001-0000-000000000001
BTW, the � seem to be null chars.
openJDK 25.0.1+8-LTS
mockito-core:5.21.0
byte-buddy:1.18.3
With jdk21 this test is green.
fails and prints:
Interestingly, editing the sample to
leads to
BTW, the
�seem to benullchars.openJDK 25.0.1+8-LTS
mockito-core:5.21.0
byte-buddy:1.18.3
With jdk21 this test is green.