Skip to content

Commit

Permalink
feat(dep): Upgrate Guice version to 5.0.1
Browse files Browse the repository at this point in the history
- Migrate to Junit 5
  • Loading branch information
yyvess committed Oct 2, 2021
1 parent 309c60f commit 22c477a
Show file tree
Hide file tree
Showing 16 changed files with 199 additions and 176 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
Guice configuration module, JSON, HOCON & Properties formats supported, build on the top of Typesafe config

[![Maven Central](https://maven-badges.herokuapp.com/maven-central/net.jmob/guice.conf/badge.svg)](https://maven-badges.herokuapp.com/maven-central/net.jmob/guice.conf)
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/net.jmob/guice.conf/badge.svg)](https://maven-badges.herokuapp.com/maven-central/net.jmob/guice.conf) [![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)

[![Sonar Status](https://sonarcloud.io/api/project_badges/measure?project=net.jmob%3Aguice.conf&metric=alert_status)](https://sonarcloud.io/dashboard?id=net.jmob%3Aguice.conf) [![Coverage](https://sonarcloud.io/api/project_badges/measure?project=net.jmob%3Aguice.conf&metric=coverage)](https://sonarcloud.io/dashboard?id=net.jmob%3Aguice.conf)


Guice configuration
======

Expand All @@ -21,15 +22,15 @@ You can find published releases on Maven Central.
<dependency>
<groupId>net.jmob</groupId>
<artifactId>guice.conf</artifactId>
<version>1.4.3</version>
<version>1.5.0</version>
</dependency>
Optionally, to active validation, you must import a validator like Hibernate validator

<dependency>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator-cdi</artifactId>
<version>6.0.15.Final</version>
<version>6.2.0.Final</version>
</dependency>
<dependency>
<groupId>org.glassfish</groupId>
Expand Down
63 changes: 43 additions & 20 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>
<groupId>net.jmob</groupId>
Expand Down Expand Up @@ -36,14 +37,17 @@
<revision>0.0.0</revision>
<changelist>-SNAPSHOT</changelist>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<guice.version>4.2.3</guice.version>
<junit.version>4.13.1</junit.version>
<guice.version>5.0.1</guice.version>
<junit.version>5.8.1</junit.version>
<typesafe.version>1.4.1</typesafe.version>
<logback.version>1.2.3</logback.version>
<logback.version>1.2.6</logback.version>
<validation-api.versoin>2.0.1.Final</validation-api.versoin>
<mockito.version>3.6.28</mockito.version>
<mockito.version>3.12.4</mockito.version>
<project.scm.id>github</project.scm.id>
<gpg.keyname>Yves Galante</gpg.keyname>
<hamcrest.version>2.2</hamcrest.version>
<hibernate-validator.version>6.2.0.Final</hibernate-validator.version>
<javax.el.version>3.0.0</javax.el.version>
</properties>

<dependencies>
Expand Down Expand Up @@ -74,27 +78,39 @@
</dependency>
<!-- test dependency -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-library</artifactId>
<version>${hamcrest.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>${mockito.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<version>${mockito.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator-cdi</artifactId>
<version>6.1.6.Final</version>
<version>${hibernate-validator.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.el</artifactId>
<version>3.0.0</version>
<version>${javax.el.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand All @@ -117,19 +133,26 @@
<id>coverage</id>
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.6</version>
<executions>
<execution>
<id>prepare-agent</id>
<execution>
<id>jacoco-initialize</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>jacoco-site</id>
<phase>package</phase>
<goals>
<goal>prepare-agent</goal>
</goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugin>
</plugins>
</build>
</profile>
Expand Down Expand Up @@ -185,7 +208,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
Expand All @@ -207,7 +230,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20</version>
<version>2.22.2</version>
<configuration>
<includes>
<include>**/*Test.java</include>
Expand All @@ -227,7 +250,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.1.1</version>
<version>3.3.1</version>
<configuration>
<quiet>true</quiet>
<nonavbar>true</nonavbar>
Expand All @@ -247,7 +270,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>3.0.0-M3</version>
<version>3.0.0</version>
<executions>
<execution>
<id>enforce-maven</id>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/jmob/guice/conf/core/internal/Typed.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@
@Target({ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
public @interface Typed {
Class value();
Class<?> value();
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public InjectorBuilder(ConfigFactory configFactory, VirtualBeanFactory virtualBe
this.virtualBeanFactory = virtualBeanFactory;
}

public Stream<Injector> build(Class beanClass) {
public Stream<Injector> build(Class<?> beanClass) {
final Config config = getConfig(configFactory, getOptions(beanClass), getAnnotationConfiguration(beanClass));
return stream(beanClass.getDeclaredFields())
.filter(f -> f.isAnnotationPresent(InjectConfig.class))
Expand Down Expand Up @@ -74,11 +74,11 @@ private String getAnnotationPath(Field f) {
return isNullOrEmpty(annotationValue) ? f.getName() : annotationValue;
}

private ConfigParseOptions getOptions(Class beanClass) {
private ConfigParseOptions getOptions(Class<?> beanClass) {
return defaults().setSyntax(ConfigSyntax.valueOf(getAnnotationConfiguration(beanClass).syntax().name()));
}

private BindConfig getAnnotationConfiguration(Class beanClass) {
return (BindConfig) beanClass.getAnnotationsByType(BindConfig.class)[0];
private BindConfig getAnnotationConfiguration(Class<?> beanClass) {
return beanClass.getAnnotationsByType(BindConfig.class)[0];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ private Entry<String, Object> buildChildEntry(String key, Method m, Map<String,
.collect(toMap(Entry::getKey, Entry::getValue)));
}

private Entry<String, Map> buildChildEntry(Method m, String key, Map<String, Object> values) {
private Entry<String, Map<?,?>> buildChildEntry(Method m, String key, Map<String, Object> values) {
return new SimpleImmutableEntry(key, newProxyInstance(getType(m), values));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,18 @@
import net.jmob.guice.conf.core.internal.injector.InjectorBuilder;
import net.jmob.guice.conf.core.internal.virtual.BeanValidator;
import net.jmob.guice.conf.core.internal.virtual.VirtualBeanFactory;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;
import org.mockito.junit.jupiter.MockitoExtension;

import java.util.Optional;

import static org.mockito.Mockito.*;

public class ConfigurationListenerTest {

@Rule
public MockitoRule mockito = MockitoJUnit.rule();
@ExtendWith(MockitoExtension.class)
class ConfigurationListenerTest {

@Mock
private TypeLiteral typeLiteral;
Expand All @@ -57,20 +54,18 @@ public class ConfigurationListenerTest {
@Mock
private BeanValidator beanValidator;

private VirtualBeanFactory virtualBeanFactory;

private InjectorBuilder injectorBuilder;

@Before
public void initializeMock() {
virtualBeanFactory = new VirtualBeanFactory(beanValidator);
@BeforeEach
void initializeMock() {
VirtualBeanFactory virtualBeanFactory = new VirtualBeanFactory(beanValidator);
injectorBuilder = new InjectorBuilder(configFactory, virtualBeanFactory);
when(configFactory.parseResources(anyString(), any(ConfigParseOptions.class)))
lenient().when(configFactory.parseResources(anyString(), any(ConfigParseOptions.class)))
.thenReturn(config);
}

@Test
public void no_class_match() {
void no_class_match() {
when(typeLiteral.getRawType())
.thenReturn(String.class);
new ConfigurationListener(injectorBuilder)
Expand All @@ -79,7 +74,7 @@ public void no_class_match() {
}

@Test
public void one_class_match() {
void one_class_match() {
when(typeLiteral.getRawType())
.thenReturn(ConfiguredClass.class);
new ConfigurationListener(injectorBuilder)
Expand All @@ -88,7 +83,7 @@ public void one_class_match() {
}

@Test
public void super_class_match() {
void super_class_match() {
when(typeLiteral.getRawType())
.thenReturn(Extends.class);
new ConfigurationListener(injectorBuilder)
Expand All @@ -97,7 +92,7 @@ public void super_class_match() {
}

@BindConfig(value = "rootPath")
public static class ConfiguredClass {
static class ConfiguredClass {
@InjectConfig
private Optional<String> p1;
}
Expand Down
Loading

0 comments on commit 22c477a

Please sign in to comment.