Skip to content
Merged
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 @@ -23,6 +23,7 @@
import org.apache.commons.vfs2.provider.VfsComponentContext;
import org.apache.hop.vfs.azure.config.AzureConfig;
import org.apache.hop.vfs.azure.config.AzureConfigSingleton;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
Expand All @@ -34,18 +35,27 @@

class AzureFileNameParserTest {

private static MockedStatic<AzureConfigSingleton> azureConfigSingleton;

private AzureFileNameParser parser;

@BeforeAll
static void init() {
AzureConfig azureConfig = new AzureConfig();
azureConfig.setAccount("hopsa");
azureConfig.setKey("aGVsbG93b3JsZA==");
MockedStatic<AzureConfigSingleton> azureConfigSingleton =
Mockito.mockStatic(AzureConfigSingleton.class);
azureConfigSingleton = Mockito.mockStatic(AzureConfigSingleton.class);
azureConfigSingleton.when(AzureConfigSingleton::getConfig).thenReturn(azureConfig);
}

@AfterAll
static void tearDown() {
if (azureConfigSingleton != null) {
azureConfigSingleton.close();
azureConfigSingleton = null;
}
}

@BeforeEach
void setup() {
parser = new AzureFileNameParser();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.apache.commons.vfs2.provider.VfsComponentContext;
import org.apache.hop.vfs.azure.config.AzureConfig;
import org.apache.hop.vfs.azure.config.AzureConfigSingleton;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.mockito.MockedStatic;
Expand All @@ -43,19 +44,23 @@
*/
class AzureFileObjectSdkPathTest {

private static MockedStatic<AzureConfigSingleton> mocked;

@BeforeAll
static void init() {
AzureConfig azureConfig = new AzureConfig();
// Obvious dummy values: account is a placeholder, key is base64 of "dummy-key".
azureConfig.setAccount("dummy-account");
azureConfig.setKey("ZHVtbXkta2V5");
try {
// Intentionally not closed - mirrors AzureFileNameParserTest, which leaks the same static
// mock for the JVM lifetime. We just need a config available when the parser asks.
MockedStatic<AzureConfigSingleton> mocked = Mockito.mockStatic(AzureConfigSingleton.class);
mocked.when(AzureConfigSingleton::getConfig).thenReturn(azureConfig);
} catch (org.mockito.exceptions.base.MockitoException alreadyRegistered) {
// Another test in this JVM already mocked it; reuse that registration.
mocked = Mockito.mockStatic(AzureConfigSingleton.class);
mocked.when(AzureConfigSingleton::getConfig).thenReturn(azureConfig);
}

@AfterAll
static void tearDown() {
if (mocked != null) {
mocked.close();
mocked = null;
}
}

Expand Down
Loading