Skip to content

Commit

Permalink
Add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
arniu committed Feb 23, 2019
1 parent 4ba7182 commit 2bda8c2
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 17 deletions.
44 changes: 34 additions & 10 deletions src/test/java/tests/JavaTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,25 @@

import io.github.cdimascio.dotenv.DotEnvException;
import io.github.cdimascio.dotenv.Dotenv;
import org.junit.Before;
import org.junit.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import java.util.HashMap;
import java.util.Map;

import static org.junit.Assert.*;

public class JavaTests {
private Map<String, String> envVars;

@Before
public void setUp() {
envVars = new HashMap<String, String>();
envVars.put("MY_TEST_EV1", "my test ev 1");
envVars.put("MY_TEST_EV2", "my test ev 2");
envVars.put("WITHOUT_VALUE", "");
}

@Test(expected = DotEnvException.class)
public void throwIfMalconfigured() {
Dotenv.configure().load();
Expand All @@ -16,24 +29,35 @@ public void throwIfMalconfigured() {
@Test(expected = DotEnvException.class)
public void load() {
Dotenv dotenv = Dotenv.load();
assertEquals("my test ev 1", dotenv.get("MY_TEST_EV1"));

for (String envName : envVars.keySet()) {
assertEquals(envVars.get(envName), dotenv.get(envName));
}

String envName = "ABSENT_ENV_VARIABLE";
String defValue = "This is the default value";
assertEquals(defValue, dotenv.get(envName, defValue));
assertNull(dotenv.get(envName, defValue));
}

@Test
public void configurWithIgnoreMalformed() {
Dotenv dotenv = Dotenv.configure()
.ignoreIfMalformed()
.load();
assertEquals("my test ev 1", dotenv.get("MY_TEST_EV1"));
.ignoreIfMalformed()
.load();

for (String envName : envVars.keySet()) {
assertEquals(envVars.get(envName), dotenv.get(envName));
}
}

@Test
public void configurWithIgnoreMissingAndMalformed() {
Dotenv dotenv = Dotenv.configure()
.directory("/missing/dir")
.ignoreIfMalformed()
.ignoreIfMissing()
.load();
.directory("/missing/dir")
.ignoreIfMalformed()
.ignoreIfMissing()
.load();
assertNotNull(dotenv.get("PATH"));
}
}
3 changes: 2 additions & 1 deletion src/test/kotlin/tests/BasicTests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import org.junit.Test as test
class DotEnvTest {
private val envVars = mapOf(
"MY_TEST_EV1" to "my test ev 1",
"MY_TEST_EV2" to "my test ev 2"
"MY_TEST_EV2" to "my test ev 2",
"WITHOUT_VALUE" to ""
)

@test(expected = DotEnvException::class)
Expand Down
5 changes: 3 additions & 2 deletions src/test/kotlin/tests/DslTests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ import org.junit.Test as test

class DotEnvDslTest {
private val envVars = mapOf(
"MY_TEST_EV1" to "my test ev 1",
"MY_TEST_EV2" to "my test ev 2"
"MY_TEST_EV1" to "my test ev 1",
"MY_TEST_EV2" to "my test ev 2",
"WITHOUT_VALUE" to ""
)

@test(expected = DotEnvException::class)
Expand Down
4 changes: 2 additions & 2 deletions src/test/resources/.env
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
## Good test EVs
MY_TEST_EV1=my test ev 1
MY_TEST_EV2=my test ev 2

WITHOUT_VALUE=

## Malformed EV!
MY_TEST_EV3
MY_TEST_EV3
4 changes: 2 additions & 2 deletions src/test/resources/env
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
## Good test EVs
MY_TEST_EV1=my test ev 1
MY_TEST_EV2=my test ev 2

WITHOUT_VALUE=

## Malformed EV!
MY_TEST_EV3
MY_TEST_EV3

0 comments on commit 2bda8c2

Please sign in to comment.