diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
new file mode 100644
index 0000000..929d31c
--- /dev/null
+++ b/.github/workflows/build.yml
@@ -0,0 +1,28 @@
+name: Build with Maven
+
+on:
+ push:
+ branches: [ "master" ]
+ pull_request:
+ branches: [ "master" ]
+
+jobs:
+ build:
+
+ runs-on: ubuntu-latest
+
+ steps:
+ - uses: actions/checkout@v3
+
+ - name: Set up JDK 11
+ uses: actions/setup-java@v3
+ with:
+ java-version: '11'
+ distribution: 'temurin'
+ cache: maven
+
+ - name: Build with Maven
+ run: mvn clean package dokka:javadocJar jacoco:report
+
+ - name: Report Coveralls
+ uses: coverallsapp/github-action@v2
diff --git a/.travis.yml b/.travis.yml
deleted file mode 100644
index e3df26c..0000000
--- a/.travis.yml
+++ /dev/null
@@ -1,9 +0,0 @@
-language: java
-jdk:
- - openjdk11
-
-script: mvn clean test
-
-sudo: false
-after_success:
- - mvn clean dokka:javadocJar test jacoco:report coveralls:report
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 4206f80..882cbff 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -45,7 +45,7 @@ Contributors are not responsible for pushing packages to mavencentral and jcente
mvn clean package dokka:javadocJar
```
-### Publish to Github Packages
+### Publish to GitHub Packages
Add `distributionManagement` to `pom.xml`
diff --git a/README.md b/README.md
index 744a77c..8327f18 100644
--- a/README.md
+++ b/README.md
@@ -66,7 +66,7 @@ With **Java**
import io.github.cdimascio.dotenv.Dotenv;
Dotenv dotenv = Dotenv.load();
-dotenv.get("MY_ENV_VAR1")
+dotenv.get("MY_ENV_VAR1");
```
or with **Kotlin**
@@ -217,7 +217,7 @@ for (e in dotenv.entries()) {
Dotenv
.configure()
.filename("myenv")
- .load()
+ .load();
```
**Kotlin Dsl example**
@@ -237,7 +237,7 @@ for (e in dotenv.entries()) {
Dotenv
.configure()
.ignoreIfMalformed()
- .load()
+ .load();
```
**Kotlin Dsl example**
@@ -257,7 +257,7 @@ for (e in dotenv.entries()) {
Dotenv
.configure()
.ignoreIfMissing()
- .load()
+ .load();
```
**Kotlin Dsl example**
@@ -277,7 +277,7 @@ for (e in dotenv.entries()) {
Dotenv
.configure()
.systemProperties()
- .load()
+ .load();
```
**Kotlin Dsl example**
diff --git a/pom.xml b/pom.xml
index 63a1995..7c767ff 100644
--- a/pom.xml
+++ b/pom.xml
@@ -48,36 +48,25 @@
-
- 2.3.2
- 1.8
- 1.8
- 1.8
- 1.6.0
+ 3.0.0
+ 11
+ 1.9.22
io.cdimascio.DotenvKt
- 4.13.1
+ 5.10.1
UTF-8
- 3.0.1
- 3.0.0
- 2.6
- 0.8.4
- 4.3.0
- 2.22.0
- 1.4.0
+ 3.12.1
+ 3.3.0
+ 3.6.3
+ 3.3.0
+ 0.8.11
+ 3.2.3
+ 1.9.10
cdimascio
maven
dotenv-kotlin
-
-
- jcenter
- JCenter
- https://jcenter.bintray.com/
-
-
-
org.jetbrains.kotlin
@@ -94,8 +83,8 @@
- junit
- junit
+ org.junit.jupiter
+ junit-jupiter
${junit.version}
test
@@ -111,6 +100,13 @@
${project.basedir}/src/main/kotlin
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ ${maven.compiler.plugin}
+
+
kotlin-maven-plugin
org.jetbrains.kotlin
@@ -119,6 +115,7 @@
compile
+ process-sources
compile
@@ -156,13 +153,6 @@
org.apache.maven.plugins
maven-surefire-plugin
${maven.surefire.plugin}
-
-
- org.apache.maven.surefire
- surefire-junit4
- 2.22.0
-
-
**/*.java
@@ -246,25 +236,10 @@
-
- org.eluder.coveralls
- coveralls-maven-plugin
- ${maven.coveralls.plugin}
-
- DTE7449Zg7tuwgrV6HeE0et1YB6JPPfeY
-
-
-
- javax.xml.bind
- jaxb-api
- 2.2.3
-
-
-
org.sonatype.plugins
nexus-staging-maven-plugin
- 1.6.7
+ 1.6.13
true
ossrh
@@ -305,7 +280,7 @@
org.apache.maven.plugins
maven-gpg-plugin
- 1.5
+ 3.1.0
sign-artifacts
diff --git a/src/test/java/tests/JavaTests.java b/src/test/java/tests/JavaTests.java
index 42f7e5c..093caec 100644
--- a/src/test/java/tests/JavaTests.java
+++ b/src/test/java/tests/JavaTests.java
@@ -3,39 +3,32 @@
import io.github.cdimascio.dotenv.Dotenv;
import io.github.cdimascio.dotenv.DotenvEntry;
import io.github.cdimascio.dotenv.DotenvException;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.*;
public class JavaTests {
- private Map envVars;
-
- @Before
- public void setUp() {
- envVars = new HashMap<>();
- envVars.put("MY_TEST_EV1", "my test ev 1");
- envVars.put("MY_TEST_EV2", "my test ev 2");
- envVars.put("WITHOUT_VALUE", "");
- }
+ private final Map envVars = Map.of(
+ "MY_TEST_EV1", "my test ev 1",
+ "MY_TEST_EV2", "my test ev 2",
+ "WITHOUT_VALUE", ""
+ );
- @Test(expected = DotenvException.class)
+ @Test
public void throwIfMalconfigured() {
- Dotenv.configure().load();
+ assertThrows(DotenvException.class, () -> Dotenv.configure().load());
}
- @Test(expected = DotenvException.class)
+ @Test
public void load() {
- Dotenv dotenv = Dotenv.load();
-
- for (String envName : envVars.keySet()) {
- assertEquals(envVars.get(envName), dotenv.get(envName));
- }
+ assertThrows(DotenvException.class, () -> {
+ Dotenv dotenv = Dotenv.load();
+ envVars.keySet().forEach(envName -> assertEquals(envVars.get(envName), dotenv.get(envName)));
+ });
}
@Test
@@ -44,13 +37,7 @@ public void iteratorOverDotenv() {
.ignoreIfMalformed()
.load();
- dotenv
- .entries()
- .forEach(e -> assertEquals(dotenv.get(e.getKey()), e.getValue()));
-
- for (DotenvEntry e : dotenv.entries()) {
- assertEquals(dotenv.get(e.getKey()), e.getValue());
- }
+ dotenv.entries().forEach(e -> assertEquals(dotenv.get(e.getKey()), e.getValue()));
}
@Test
@@ -63,32 +50,31 @@ public void iteratorOverDotenvWithFilter() {
Set entriesAll = dotenv.entries();
assertTrue(entriesInFile.size() < entriesAll.size());
- for (Map.Entry e: envVars.entrySet()) {
- assertEquals(dotenv.get(e.getKey()), e.getValue());
- }
+ envVars.forEach((key, value) -> assertEquals(dotenv.get(key), value));
}
- @Test(expected = UnsupportedOperationException.class)
+ @Test
public void failToRemoveFromDotenv() {
Dotenv dotenv = Dotenv.configure()
.ignoreIfMalformed()
.load();
- Iterator iter = dotenv.entries().iterator();
- while (iter.hasNext()) {
- iter.next();
- iter.remove();
- }
+ assertThrows(UnsupportedOperationException.class, () -> {
+ Iterator iter = dotenv.entries().iterator();
+ while (iter.hasNext()) {
+ iter.next();
+ iter.remove();
+ }
+ });
}
- @Test(expected = UnsupportedOperationException.class)
+ @Test
public void failToAddToDotenv() {
-
Dotenv dotenv = Dotenv.configure()
.ignoreIfMalformed()
.load();
- dotenv.entries().add(new DotenvEntry("new", "value"));
+ assertThrows(UnsupportedOperationException.class, () -> dotenv.entries().add(new DotenvEntry("new", "value")));
}
@Test
diff --git a/src/test/kotlin/tests/BasicTests.kt b/src/test/kotlin/tests/BasicTests.kt
index 88164d2..85a54ad 100644
--- a/src/test/kotlin/tests/BasicTests.kt
+++ b/src/test/kotlin/tests/BasicTests.kt
@@ -1,11 +1,12 @@
package tests
-import io.github.cdimascio.dotenv.DotenvException
import io.github.cdimascio.dotenv.Dotenv
+import io.github.cdimascio.dotenv.DotenvException
import kotlin.test.assertEquals
+import kotlin.test.assertFailsWith
import kotlin.test.assertNotNull
import kotlin.test.assertNull
-import org.junit.Test as test
+import org.junit.jupiter.api.Test as test
class DotEnvTest {
private val envVars = mapOf(
@@ -15,11 +16,13 @@ class DotEnvTest {
"MULTI_LINE" to "hello\\nworld"
)
- @test(expected = DotenvException::class)
+ @test
fun dotenvMalformed() {
- Dotenv.configure()
- .directory("./src/test/resources")
- .load()
+ assertFailsWith {
+ Dotenv.configure()
+ .directory("./src/test/resources")
+ .load()
+ }
}
@test
@@ -113,11 +116,13 @@ class DotEnvTest {
}
}
- @test(expected = DotenvException::class)
+ @test
fun dotenvMissing() {
- Dotenv.configure()
- .directory("/missing/.env")
- .load()
+ assertFailsWith {
+ Dotenv.configure()
+ .directory("/missing/.env")
+ .load()
+ }
}
@test
@@ -133,7 +138,7 @@ class DotEnvTest {
}
private fun assertHostEnvVar(env: Dotenv) {
- val isWindows = System.getProperty("os.name").toLowerCase().indexOf("win") >= 0
+ val isWindows = System.getProperty("os.name").lowercase().indexOf("win") >= 0
if (isWindows) {
val path = env["PATH"]
assertNotNull(path)
diff --git a/src/test/kotlin/tests/DslTests.kt b/src/test/kotlin/tests/DslTests.kt
index ddbc741..bc866da 100644
--- a/src/test/kotlin/tests/DslTests.kt
+++ b/src/test/kotlin/tests/DslTests.kt
@@ -1,15 +1,10 @@
package tests
-import io.github.cdimascio.dotenv.DotenvException
import io.github.cdimascio.dotenv.Dotenv
-import io.github.cdimascio.dotenv.DotenvEntry
+import io.github.cdimascio.dotenv.DotenvException
import io.github.cdimascio.dotenv.dotenv
-import kotlin.test.assertTrue
-import kotlin.test.assertEquals
-import kotlin.test.assertNotEquals
-import kotlin.test.assertNotNull
-import kotlin.test.assertNull
-import org.junit.Test as test
+import kotlin.test.*
+import org.junit.jupiter.api.Test as test
class DotEnvDslTest {
private val envVars = mapOf(
@@ -24,9 +19,11 @@ class DotEnvDslTest {
"HOME" to "dotenv_test_home"
)
- @test(expected = DotenvException::class)
+ @test
fun dotenvMalformed() {
- dotenv()
+ assertFailsWith {
+ dotenv()
+ }
}
@test
@@ -94,7 +91,7 @@ class DotEnvDslTest {
assertNotEquals(envVarsOverridenByHostEnv["HOME"], env["HOME"])
}
- @org.junit.Test
+ @test
fun iteratorOverDotenvWithFilter() {
val dotenv = Dotenv.configure()
.ignoreIfMalformed()
@@ -128,10 +125,12 @@ class DotEnvDslTest {
assertHostEnvVar(env)
}
- @test(expected = DotenvException::class)
+ @test
fun dotenvMissing() {
- dotenv {
- directory = "/missing/.env"
+ assertFailsWith {
+ dotenv {
+ directory = "/missing/.env"
+ }
}
}
@@ -146,8 +145,34 @@ class DotEnvDslTest {
assertNull(env["MY_TEST_EV1"])
}
+ @test
+ fun systemProperties() {
+ val env = dotenv {
+ ignoreIfMalformed = true
+ systemProperties = true
+ }
+
+ assertHostEnvVar(env)
+ assertEquals("my test ev 1", env["MY_TEST_EV1"])
+ assertEquals("my test ev 1", System.getProperty("MY_TEST_EV1"))
+ env.entries().forEach {
+ System.clearProperty(it.key)
+ }
+ }
+
+ @test
+ fun noSystemProperties() {
+ val env = dotenv {
+ ignoreIfMalformed = true
+ }
+
+ assertHostEnvVar(env)
+ assertEquals("my test ev 1", env["MY_TEST_EV1"])
+ assertNull(System.getProperty("MY_TEST_EV1"))
+ }
+
private fun assertHostEnvVar(env: Dotenv) {
- val isWindows = System.getProperty("os.name").toLowerCase().indexOf("win") >= 0
+ val isWindows = System.getProperty("os.name").lowercase().indexOf("win") >= 0
if (isWindows) {
val path = env["PATH"]
assertNotNull(path)