Skip to content

Commit

Permalink
Update env checker
Browse files Browse the repository at this point in the history
  • Loading branch information
MathieuSoysal authored Apr 24, 2023
1 parent 0b39811 commit 37d8d2b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
29 changes: 22 additions & 7 deletions src/main/java/io/github/mathieusoysal/App.java
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
package io.github.mathieusoysal;

import java.util.ArrayList;

import com.github.forax.beautifullogger.Logger;

import io.github.mathieusoysal.exceptions.EnvironementVariableNotFoundException;
import io.github.mathieusoysal.exceptions.RobotoException;

public class App {

private static final String ENV_NAME_PASSWORD = "TEST_PASSWORD";
private static final String ENV_NAME_MAIL = "TEST_EMAIL";
private static final Logger LOGGER = Logger.getLogger();

public static void main(String[] args) {
try {
checkEnvVariable("TEST_EMAIL");
checkEnvVariable("TEST_PASSWORD");
} catch (EnvironementVariableNotFoundException e) {
LOGGER.error(e.getMessage(), e);
}
checkAllEnvVariables(ENV_NAME_MAIL, ENV_NAME_PASSWORD);
try (Roboto roboto = new Roboto()) {
roboto.connect(System.getenv("TEST_EMAIL"), System.getenv("TEST_PASSWORD"));
roboto.connect(System.getenv(ENV_NAME_MAIL), System.getenv(ENV_NAME_PASSWORD));
while (!roboto.checkinButtonIsPresent())
roboto.refreshPage();
roboto.clickOnSubscription();
Expand All @@ -26,6 +25,22 @@ public static void main(String[] args) {
}
}

static void checkAllEnvVariables(String... envNames) {
var notFound = new ArrayList<String>();
for (String name : envNames) {
try {
checkEnvVariable(name);
} catch (EnvironementVariableNotFoundException e) {
LOGGER.error(e.getMessage(), e);
notFound.add(name);
}
}
if (notFound.size() > 0) {
throw new RuntimeException(
"Please set the following environment variables: " + String.join(", ", notFound));
}
}

static void checkEnvVariable(String name) throws EnvironementVariableNotFoundException {
if (System.getenv(name) == null) {
throw new EnvironementVariableNotFoundException(name);
Expand Down
7 changes: 7 additions & 0 deletions src/test/java/io/github/mathieusoysal/AppTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,11 @@ void testCheckEnvVariable2() {
});
}

@Test
void testCheckAllEnvVariables() {
assertDoesNotThrow(() -> {
App.checkAllEnvVariables();
});
}

}

0 comments on commit 37d8d2b

Please sign in to comment.