Skip to content

Commit

Permalink
refactoring of DotEnv
Browse files Browse the repository at this point in the history
  • Loading branch information
jorg3lopez committed Oct 25, 2023
1 parent a105b36 commit 4696577
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@ public class ApplicationContext {
protected static final Map<Class<?>, Object> OBJECT_MAP = new ConcurrentHashMap<>();
protected static final Set<Object> IMPLEMENTATIONS = new HashSet<>();

static {
DotEnv.load();
}

protected ApplicationContext() {}

public static void register(Class<?> clazz, Object implementation) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
class DotEnv {
private static Dotenv DOTENV;

static {
DOTENV = Dotenv.configure().ignoreIfMissing().load();
}

private DotEnv() {}

public static String get(String key) {
Expand All @@ -15,11 +19,7 @@ public static String get(String key, String defaultValue) {
return DOTENV.get(key, defaultValue);
}

public static void load() {
DOTENV = Dotenv.configure().ignoreIfMissing().load();
}

public static void load(Dotenv dotenv) {
static void load(Dotenv dotenv) {
DOTENV = dotenv;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,12 @@ class DotEnvTest extends Specification {
def "get method should return value for existing key"() {
given:
def mockDotenv = Mock(Dotenv)
mockDotenv.get(_ as String) >> "test_value"
mockDotenv.get("test_id") >> "test_value"

DotEnv.load(mockDotenv)

// dotenv.get("test_key") >> "test_value"
// final var dotenv = Dotenv.configure().directory("app/src/main/resources").ignoreIfMissing().load();
// DotEnv.mixin()

// Dotenv dotenv = GroovyMock(global: true) as Dotenv
// dotenv.get("test_key" as String) >> "test_value"


// Field field = DotEnv.class.getDeclaredField("DOTENV")
// field.setAccessible(true)
// field.set(null, dotenv)

// DotEnv.mixin(new Expando() {
// def get(key) {
// return dotenv.get(key)
// }
// } as Class)

when:
String value = DotEnv.get("test_key")
String value = DotEnv.get("test_id")

then:
1==1
Expand Down

0 comments on commit 4696577

Please sign in to comment.