Skip to content

Commit

Permalink
Merge pull request #3 from clean-arch-enablers-project/refact/rename
Browse files Browse the repository at this point in the history
refact: rename
  • Loading branch information
zeluciojr authored Dec 16, 2024
2 parents 6a6f588 + 19b4583 commit cf79e64
Show file tree
Hide file tree
Showing 2 changed files with 159 additions and 51 deletions.
149 changes: 98 additions & 51 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
<description>CAE EnvVars library</description>
<url>https://github.com/clean-arch-enablers-project/cae-utils-env-vars/blob/main/README.md</url>
<groupId>com.clean-arch-enablers</groupId>
<artifactId>env-vars</artifactId>
<version>0.0.1</version>
<artifactId>cae-env-vars</artifactId>
<version>1.0.0</version>
<packaging>jar</packaging>
<licenses>
<license>
Expand Down Expand Up @@ -36,63 +36,110 @@
<dependencies>
<dependency>
<groupId>com.clean-arch-enablers</groupId>
<artifactId>trier</artifactId>
<version>0.0.1</version>
<artifactId>cae-trier</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.4.14</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.9.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>4.8.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<version>4.8.0</version>
<scope>test</scope>
</dependency>
</dependencies>


<profiles>
<profile>
<id>deployment</id>
<build>
<plugins>
<plugin>
<groupId>org.sonatype.central</groupId>
<artifactId>central-publishing-maven-plugin</artifactId>
<version>0.4.0</version>
<extensions>true</extensions>
<configuration>
<publishingServerId>central</publishingServerId>
<tokenAuth>true</tokenAuth>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.3.0</version>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.2.1</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>

<build>
<plugins>
<plugin>
<groupId>org.sonatype.central</groupId>
<artifactId>central-publishing-maven-plugin</artifactId>
<version>0.4.0</version>
<extensions>true</extensions>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
<configuration>
<publishingServerId>central</publishingServerId>
<tokenAuth>true</tokenAuth>
<environmentVariables>
<EnvVarOne>some-normal-value</EnvVarOne>
<EnvVarTwo>123</EnvVarTwo>
<EnvVarThree>true</EnvVarThree>
</environmentVariables>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.3.0</version>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.2.1</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>deploy</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

</project>
61 changes: 61 additions & 0 deletions src/test/java/com/cae/env_vars/EnvVarRetrieverTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package com.cae.env_vars;

import com.cae.env_vars.exceptions.MissingEnvVarException;
import com.cae.env_vars.exceptions.UnexpectedException;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.junit.jupiter.MockitoExtension;

@ExtendWith(MockitoExtension.class)
class EnvVarRetrieverTest {

@Test
void shouldThrowMissingEnvVarExceptionWhenNoEnvVarIsFound(){
Assertions.assertThrows(
MissingEnvVarException.class,
() -> EnvVarRetriever.getEnvVarByName("NON_EXISTENT_ENV_VAR_KEY", String.class)
);
}

@Test
void shouldReturnTheEnvVarValueWhenExistent(){
Assertions.assertDoesNotThrow(() -> {
var value = (EnvVarRetriever.getEnvVarByName("EnvVarOne", String.class));
Assertions.assertEquals("some-normal-value", value);
});
}

@Test
void shouldReturnTheEnvVarValueAsString(){
Assertions.assertDoesNotThrow(() -> {
var value = (EnvVarRetriever.getEnvVarByNameAsString("EnvVarOne"));
Assertions.assertEquals("some-normal-value", value);
});
}

@Test
void shouldReturnTheEnvVarValueAsInteger(){
Assertions.assertDoesNotThrow(() -> {
var value = (EnvVarRetriever.getEnvVarByNameAsInteger("EnvVarTwo"));
Assertions.assertEquals(123, value);
});
}

@Test
void shouldReturnTheEnvVarValueAsBoolean(){
Assertions.assertDoesNotThrow(() -> {
var value = (EnvVarRetriever.getEnvVarByNameAsBoolean("EnvVarThree"));
Assertions.assertEquals(true, value);
});
}

@Test
void shouldThrowUnexpectedExceptionWhenSomeProblemHappensOtherThanMissingEnvVar(){
Assertions.assertThrows(
UnexpectedException.class,
() -> EnvVarRetriever.getEnvVarByNameAsInteger("EnvVarThree")
);
}

}

0 comments on commit cf79e64

Please sign in to comment.