diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 1c65017..55c36a4 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -1,7 +1,7 @@ # This workflow will build a Java project with Maven # For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven -name: 'Java Build' +name: 'Maven Build' on: push: @@ -12,7 +12,7 @@ on: jobs: build: env: - MAVEN_ARGS: -B -ntp -Prelease -Pcoverage + MAVEN_ARGS: -B -ntp -Prelease -Pcoverage -Dmaven.javadoc.skip=true runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 @@ -23,7 +23,7 @@ jobs: with: java-version: 1.8 - name: Build Maven - run: mvn ${MAVEN_ARGS} compile + run: mvn ${MAVEN_ARGS} -Drevision=${{ steps.bump_version.outputs.new_tag }} compile - name: Maven Test run: mvn ${MAVEN_ARGS} test - name: Set up JDK 11 @@ -34,4 +34,4 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} - run: mvn ${MAVEN_ARGS} -Dsonar.branch.name=${CIRCLE_BRANCH} -Dsonar.java.binaries=target/classes -Dsonar.host.url=https://sonarcloud.io -Dsonar.organization=yyvess-github -Dmaven.javadoc.skip=true jacoco:report sonar:sonar + run: mvn ${MAVEN_ARGS} -Dsonar.java.binaries=target/classes -Dsonar.host.url=https://sonarcloud.io -Dsonar.organization=yyvess-github jacoco:report sonar:sonar diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 9569b88..3e021a9 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -3,13 +3,15 @@ name: Release on: workflow_run: - workflows: ["Java Build"] + workflows: ["Maven Build"] branches: ["master"] types: - completed + jobs: deploy: + if: ${{ github.event.workflow_run.conclusion == 'success' }} env: MAVEN_ARGS: -B -ntp -Prelease -Dmaven.test.skip=true runs-on: ubuntu-latest @@ -35,7 +37,6 @@ jobs: with: github_token: ${{ secrets.GITHUB_TOKEN }} dry_run: true - custom_release_rules: patch:patch,minor:minor,major:major release_branches: release.*,hotfix.*,master - name: Build the release env: @@ -47,7 +48,6 @@ jobs: uses: mathieudutour/github-tag-action@v5 with: github_token: ${{ secrets.GITHUB_TOKEN }} - custom_release_rules: patch:patch,minor:minor,major:major release_branches: release.*,hotfix.*,master - name: Deploy the release to maven central env: diff --git a/README.md b/README.md index 8567af7..b5cc008 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,9 @@ Spring configuration module provides JSON & HOCON support, build on the top of Typesafe config ![Maven Central](https://maven-badges.herokuapp.com/maven-central/net.jmob/jsconf/badge.svg) -[![Build Status](https://travis-ci.org/yyvess/jsconf.svg?branch=master)](https://travis-ci.org/yyvess/jsconf) +[![Sonar Status](https://sonarcloud.io/api/project_badges/measure?project=net.jmob%3Ajsconf&metric=alert_status)](https://sonarcloud.io/dashboard?id=net.jmob%3Ajsconf) [![Coverage](https://sonarcloud.io/api/project_badges/measure?project=net.jmob%3Ajsconf&metric=coverage)](https://sonarcloud.io/dashboard?id=net.jmob%3Ajsconf) + +[![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) JSConf ====== @@ -22,7 +24,7 @@ You can find published releases (compiled for Java 7 and above) on Maven Central net.jmob jsconf - 1.3.1 + 1.4.0 Spring context is required, it's not provided by this library diff --git a/pom.xml b/pom.xml index 523081d..cb9e487 100644 --- a/pom.xml +++ b/pom.xml @@ -6,6 +6,10 @@ ${revision}${changelist} jar + + 3.6.0 + + JSON Spring Configuration Spring configuration module provides JSON and HOCON support @@ -32,9 +36,9 @@ 0.0.0 -SNAPSHOT UTF-8 - 3.2.4.RELEASE - 4.11 - 1.2.1 + 5.3.1 + 5.7.0 + 1.4.1 1.1.2 1.4 @@ -74,8 +78,8 @@ test - junit - junit + org.junit.jupiter + junit-jupiter-api ${junit-version} test @@ -106,7 +110,7 @@ org.glassfish.web javax.el - 2.2.4 + 2.2.6 test @@ -168,7 +172,7 @@ org.codehaus.mojo flatten-maven-plugin - 1.1.0 + 1.2.5 true resolveCiFriendliesOnly @@ -199,16 +203,16 @@ org.apache.maven.plugins maven-compiler-plugin - 3.2 + 3.7.0 - 1.7 - 1.7 + 1.8 + 1.8 org.apache.maven.plugins maven-source-plugin - 2.4 + 3.0.1 attach-sources @@ -221,7 +225,7 @@ org.apache.maven.plugins maven-surefire-plugin - 2.10 + 3.0.0-M5 classes @@ -236,7 +240,7 @@ org.apache.maven.plugins maven-javadoc-plugin - 2.10.1 + 3.0.0-M1 true true diff --git a/src/main/java/net/jmob/jsconf/core/ConfigurationFactory.java b/src/main/java/net/jmob/jsconf/core/ConfigurationFactory.java index 4ae4765..caf618f 100644 --- a/src/main/java/net/jmob/jsconf/core/ConfigurationFactory.java +++ b/src/main/java/net/jmob/jsconf/core/ConfigurationFactory.java @@ -1,12 +1,12 @@ /** * Copyright 2013 Yves Galante - * + *

* Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + *

* http://www.apache.org/licenses/LICENSE-2.0 - * + *

* Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/src/main/java/net/jmob/jsconf/core/impl/BeanDefinition.java b/src/main/java/net/jmob/jsconf/core/impl/BeanDefinition.java index b756a80..90bed30 100644 --- a/src/main/java/net/jmob/jsconf/core/impl/BeanDefinition.java +++ b/src/main/java/net/jmob/jsconf/core/impl/BeanDefinition.java @@ -1,16 +1,16 @@ package net.jmob.jsconf.core.impl; -import static org.springframework.util.StringUtils.isEmpty; +import static org.springframework.util.StringUtils.hasText; /** * Copyright 2015 Yves Galante - * + *

* Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + *

* http://www.apache.org/licenses/LICENSE-2.0 - * + *

* Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -26,10 +26,10 @@ public class BeanDefinition { private boolean reloading; public String getId() { - if (isEmpty(id)) { - return this.key; + if (hasText(id)) { + return id; } - return id; + return this.key; } public BeanDefinition withId(String id) { diff --git a/src/main/java/net/jmob/jsconf/core/impl/BeanFactory.java b/src/main/java/net/jmob/jsconf/core/impl/BeanFactory.java index d40b0a3..c0751b4 100644 --- a/src/main/java/net/jmob/jsconf/core/impl/BeanFactory.java +++ b/src/main/java/net/jmob/jsconf/core/impl/BeanFactory.java @@ -1,12 +1,12 @@ /** * Copyright 2013 Yves Galante - * + *

* Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + *

* http://www.apache.org/licenses/LICENSE-2.0 - * + *

* Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -16,15 +16,9 @@ package net.jmob.jsconf.core.impl; -import static java.lang.String.format; -import static org.springframework.beans.factory.support.BeanDefinitionBuilder.genericBeanDefinition; - -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Set; - +import com.typesafe.config.Config; +import com.typesafe.config.ConfigException; +import com.typesafe.config.ConfigValue; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.BeanCreationException; @@ -33,10 +27,14 @@ import org.springframework.beans.factory.support.BeanDefinitionRegistry; import org.springframework.context.ApplicationContext; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; -import com.typesafe.config.Config; -import com.typesafe.config.ConfigException; -import com.typesafe.config.ConfigValue; +import static java.lang.String.format; +import static org.springframework.beans.factory.support.BeanDefinitionBuilder.genericBeanDefinition; public class BeanFactory { @@ -77,25 +75,25 @@ public boolean isReloading() { } public String registerBean() { - final BeanDefinitionBuilder beanDefinition; + final BeanDefinitionBuilder bd; final String beanId = this.beanDefinition.getId(); this.log.debug("Initialize bean id : {}", beanId); if (this.beanDefinition.isAInterface()) { - beanDefinition = buildBeanFromInterface(); + bd = buildBeanFromInterface(); } else { - beanDefinition = buildBeanFromClass(); + bd = buildBeanFromClass(); } this.log.debug("Register bean id : {}", beanId); AutowireCapableBeanFactory factory = context.getAutowireCapableBeanFactory(); BeanDefinitionRegistry registry = (BeanDefinitionRegistry) factory; - registry.registerBeanDefinition(beanId, beanDefinition.getBeanDefinition()); + registry.registerBeanDefinition(beanId, bd.getBeanDefinition()); return beanId; } private BeanDefinitionBuilder buildBeanFromClass() { try { - BeanDefinitionBuilder beanDefinition = genericBeanDefinition(Class.forName(this.beanDefinition.getClassName())); - return addPropertiesValue(beanDefinition, buildProperties(beanDefinition)); + BeanDefinitionBuilder bd = genericBeanDefinition(Class.forName(this.beanDefinition.getClassName())); + return addPropertiesValue(bd, buildProperties(bd)); } catch (ClassNotFoundException e) { throw new BeanCreationException(format("Class not found : %s", this.beanDefinition.getClassName()), e); } diff --git a/src/main/java/net/jmob/jsconf/core/impl/BeanValidator.java b/src/main/java/net/jmob/jsconf/core/impl/BeanValidator.java index 50ed576..6d74b0e 100644 --- a/src/main/java/net/jmob/jsconf/core/impl/BeanValidator.java +++ b/src/main/java/net/jmob/jsconf/core/impl/BeanValidator.java @@ -1,12 +1,12 @@ /** * Copyright 2015 Yves Galante - * + *

* Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + *

* http://www.apache.org/licenses/LICENSE-2.0 - * + *

* Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -33,6 +33,8 @@ class BeanValidator { private static final Logger log = LoggerFactory.getLogger(BeanValidator.class); private static final ValidatorFactory factory; + private BeanValidator() { + } static { ValidatorFactory f = null; diff --git a/src/main/java/net/jmob/jsconf/core/impl/ProxyPostProcessor.java b/src/main/java/net/jmob/jsconf/core/impl/ProxyPostProcessor.java index d8b5b56..a226dab 100644 --- a/src/main/java/net/jmob/jsconf/core/impl/ProxyPostProcessor.java +++ b/src/main/java/net/jmob/jsconf/core/impl/ProxyPostProcessor.java @@ -1,12 +1,12 @@ /** * Copyright 2013 Yves Galante - * + *

* Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + *

* http://www.apache.org/licenses/LICENSE-2.0 - * + *

* Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -23,11 +23,7 @@ import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; import java.lang.reflect.Proxy; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; import static java.lang.String.format; @@ -43,16 +39,13 @@ public ProxyPostProcessor(ApplicationContext context) { public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { if (bean.getClass().getInterfaces().length > 0) { - BeanProxy proxy = this.proxyRef.get(beanName); - if (proxy == null) { + BeanProxy proxy = this.proxyRef.computeIfAbsent(beanName, key -> { ClassLoader cl = Thread.currentThread().getContextClassLoader(); - List> asList = new ArrayList<>(); - asList.addAll(Arrays.asList(bean.getClass().getInterfaces())); + List> asList = new ArrayList<>(Arrays.asList(bean.getClass().getInterfaces())); asList.add(BeanProxy.class); Class[] interfaces = asList.toArray(new Class[asList.size()]); - proxy = (BeanProxy) Proxy.newProxyInstance(cl, interfaces, new ProxyHandler()); - this.proxyRef.put(beanName, proxy); - } + return (BeanProxy) Proxy.newProxyInstance(cl, interfaces, new ProxyHandler()); + }); proxy.setBean(bean); return proxy; } else { @@ -80,9 +73,6 @@ private static class ProxyHandler implements InvocationHandler { private Object bean; - public ProxyHandler() { - } - @Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { if (method.isAnnotationPresent(SetBeanMethod.class)) { diff --git a/src/main/java/net/jmob/jsconf/core/impl/VirtualBean.java b/src/main/java/net/jmob/jsconf/core/impl/VirtualBean.java index d8f521a..f2b8b87 100644 --- a/src/main/java/net/jmob/jsconf/core/impl/VirtualBean.java +++ b/src/main/java/net/jmob/jsconf/core/impl/VirtualBean.java @@ -1,12 +1,12 @@ /** * Copyright 2015 Yves Galante - * + *

* Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + *

* http://www.apache.org/licenses/LICENSE-2.0 - * + *

* Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -57,7 +57,7 @@ public static T factory(Class beanInterface, Map values) } @Override - public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { + public Object invoke(Object proxy, Method method, Object[] args) { String methodName = method.getName(); int nbArgs = nbArgs(args); if (methodName.startsWith(GET_PREFIX) && nbArgs == 0) { diff --git a/src/main/java/net/jmob/jsconf/core/service/WatchResource.java b/src/main/java/net/jmob/jsconf/core/service/WatchResource.java index 9d0a21c..f31a8c6 100644 --- a/src/main/java/net/jmob/jsconf/core/service/WatchResource.java +++ b/src/main/java/net/jmob/jsconf/core/service/WatchResource.java @@ -7,13 +7,8 @@ import java.io.IOException; import java.net.URISyntaxException; import java.net.URL; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.nio.file.StandardWatchEventKinds; -import java.nio.file.WatchEvent; +import java.nio.file.*; import java.nio.file.WatchEvent.Kind; -import java.nio.file.WatchKey; -import java.nio.file.WatchService; import static java.nio.file.StandardWatchEventKinds.*; @@ -77,7 +72,7 @@ private WatchTask(ConfigurationFactory configuration, Path path) { public void run() { try (WatchService watchService = this.path.getFileSystem().newWatchService()) { this.path.register(watchService, ENTRY_CREATE, ENTRY_MODIFY, ENTRY_DELETE); - this.log.debug("Watch configuration change on {}", this.path.toString()); + this.log.debug("Watch configuration change on {}", this.path); WatchKey watchKey; do { watchKey = watchService.take(); @@ -93,9 +88,11 @@ public void run() { } while (watchKey.reset()); this.log.info("Configuration watching service stopped"); watchKey.cancel(); - watchService.close(); - } catch (IOException | InterruptedException e) { + } catch (IOException e) { this.log.error("Configuration watching service stopped", e); + } catch (InterruptedException e) { + this.log.error("Configuration watching service stopped", e); + Thread.currentThread().interrupt(); } } } diff --git a/src/test/java/net/jmob/jsconf/core/sample/Sample01.java b/src/test/java/net/jmob/jsconf/core/sample/Sample01.java index b091e0d..079d657 100644 --- a/src/test/java/net/jmob/jsconf/core/sample/Sample01.java +++ b/src/test/java/net/jmob/jsconf/core/sample/Sample01.java @@ -1,12 +1,12 @@ /** * Copyright 2013 Yves Galante - * + *

* Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + *

* http://www.apache.org/licenses/LICENSE-2.0 - * + *

* Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -16,30 +16,31 @@ package net.jmob.jsconf.core.sample; -import org.apache.commons.dbcp.BasicDataSource; import net.jmob.jsconf.core.ConfigurationFactory; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.apache.commons.dbcp.BasicDataSource; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.test.context.support.AnnotationConfigContextLoader; import javax.sql.DataSource; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; + -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @ContextConfiguration(loader = AnnotationConfigContextLoader.class) -public class Sample01 { +class Sample01 { @Autowired private DataSource datasource; @Test - public void test() { + void test() { BasicDataSource basic = (BasicDataSource) this.datasource; assertEquals("jdbc:mysql://localhost:3306/test", basic.getUrl()); assertEquals("com.mysql.jdbc.Driver", basic.getDriverClassName()); @@ -48,7 +49,7 @@ public void test() { @Configuration static class ContextConfiguration { @Bean - public static ConfigurationFactory configurationFactory() { + static ConfigurationFactory configurationFactory() { return new ConfigurationFactory() .withResourceName("net/jmob/jsconf/core/sample/app_01.conf") // .withBean("datasource", BasicDataSource.class); diff --git a/src/test/java/net/jmob/jsconf/core/sample/Sample02.java b/src/test/java/net/jmob/jsconf/core/sample/Sample02.java index d030323..ab088ca 100644 --- a/src/test/java/net/jmob/jsconf/core/sample/Sample02.java +++ b/src/test/java/net/jmob/jsconf/core/sample/Sample02.java @@ -1,12 +1,12 @@ /** * Copyright 2013 Yves Galante - * + *

* Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + *

* http://www.apache.org/licenses/LICENSE-2.0 - * + *

* Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -18,28 +18,29 @@ import net.jmob.jsconf.core.ConfigurationFactory; import net.jmob.jsconf.core.sample.bean.ConfigBean; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.test.context.support.AnnotationConfigContextLoader; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; -@RunWith(SpringJUnit4ClassRunner.class) + +@ExtendWith(SpringExtension.class) @ContextConfiguration(loader = AnnotationConfigContextLoader.class) -public class Sample02 { +class Sample02 { @Autowired // This interface not required implementation private ConfigBean conf; @Test - public void test() { + void test() { assertNotNull(this.conf); assertEquals("Hello World", this.conf.getUrl()); assertEquals(12, this.conf.getPort()); @@ -53,7 +54,7 @@ public void test() { @Configuration static class ContextConfiguration { @Bean - public static ConfigurationFactory configurationFactory() { + static ConfigurationFactory configurationFactory() { return new ConfigurationFactory() .withResourceName("net/jmob/jsconf/core/sample/app_02") .withScanPackage(ConfigBean.class.getPackage().getName()); diff --git a/src/test/java/net/jmob/jsconf/core/sample/Sample03.java b/src/test/java/net/jmob/jsconf/core/sample/Sample03.java index c66bc86..c8e3916 100644 --- a/src/test/java/net/jmob/jsconf/core/sample/Sample03.java +++ b/src/test/java/net/jmob/jsconf/core/sample/Sample03.java @@ -1,12 +1,12 @@ /** * Copyright 2013 Yves Galante - * + *

* Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + *

* http://www.apache.org/licenses/LICENSE-2.0 - * + *

* Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -19,21 +19,22 @@ import net.jmob.jsconf.core.ConfigurationFactory; import net.jmob.jsconf.core.sample.bean.ConfigBean; import net.jmob.jsconf.core.sample.bean.SpringBean; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.test.context.support.AnnotationConfigContextLoader; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; -@RunWith(SpringJUnit4ClassRunner.class) + +@ExtendWith(SpringExtension.class) @ContextConfiguration(loader = AnnotationConfigContextLoader.class) -public class Sample03 { +class Sample03 { @Autowired @Qualifier("node") @@ -44,7 +45,7 @@ public class Sample03 { private SpringBean node2; @Test - public void test() { + void test() { assertNotNull(this.node1); assertNotNull(this.node2); assertNotSame(this.node1, this.node2); @@ -60,7 +61,7 @@ public void test() { @Configuration static class ContextConfiguration { @Bean - public static ConfigurationFactory configurationFactory() { + static ConfigurationFactory configurationFactory() { return new ConfigurationFactory() .withResourceName("net/jmob/jsconf/core/sample/app_03.conf") .withBean("node", SpringBean.class) diff --git a/src/test/java/net/jmob/jsconf/core/sample/Sample04.java b/src/test/java/net/jmob/jsconf/core/sample/Sample04.java index 8f3dec4..d2d7d78 100644 --- a/src/test/java/net/jmob/jsconf/core/sample/Sample04.java +++ b/src/test/java/net/jmob/jsconf/core/sample/Sample04.java @@ -1,12 +1,12 @@ /** * Copyright 2013 Yves Galante - * + *

* Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + *

* http://www.apache.org/licenses/LICENSE-2.0 - * + *

* Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -17,31 +17,32 @@ package net.jmob.jsconf.core.sample; import net.jmob.jsconf.core.ConfigFormat; -import org.apache.commons.dbcp.BasicDataSource; import net.jmob.jsconf.core.ConfigurationFactory; import net.jmob.jsconf.core.sample.bean.Sequence; -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.apache.commons.dbcp.BasicDataSource; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.test.context.support.AnnotationConfigContextLoader; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @ContextConfiguration(loader = AnnotationConfigContextLoader.class) -public class Sample04 { +class Sample04 { @Autowired private Sequence sequence; @Test - public void test() { - Assert.assertNotNull(this.sequence); + void test() { + assertNotNull(this.sequence); assertEquals("SEQ_NAME", this.sequence.getName()); assertEquals("org.apache.commons.dbcp.BasicDataSource", this.sequence.getDataSource() .getClass().getName()); @@ -50,7 +51,7 @@ public void test() { @Configuration static class ContextConfiguration { @Bean - public static ConfigurationFactory configurationFactory() { + static ConfigurationFactory configurationFactory() { return new ConfigurationFactory() .withResourceName("net/jmob/jsconf/core/sample/app_04.conf") .withFormat(ConfigFormat.CONF) diff --git a/src/test/java/net/jmob/jsconf/core/sample/Sample05.java b/src/test/java/net/jmob/jsconf/core/sample/Sample05.java index a874be9..d6090d0 100644 --- a/src/test/java/net/jmob/jsconf/core/sample/Sample05.java +++ b/src/test/java/net/jmob/jsconf/core/sample/Sample05.java @@ -1,12 +1,12 @@ /** * Copyright 2013 Yves Galante - * + *

* Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + *

* http://www.apache.org/licenses/LICENSE-2.0 - * + *

* Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -18,21 +18,22 @@ import net.jmob.jsconf.core.ConfigurationFactory; import net.jmob.jsconf.core.sample.bean.ConfigBean; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.test.annotation.Repeat; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.test.context.support.AnnotationConfigContextLoader; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; -@RunWith(SpringJUnit4ClassRunner.class) + +@ExtendWith(SpringExtension.class) @ContextConfiguration(loader = AnnotationConfigContextLoader.class) -public class Sample05 { +class Sample05 { @Autowired private ConfigBean conf; @@ -42,14 +43,14 @@ public class Sample05 { @Test @Repeat(value = 4) - public void test() { + void test() { final Object ref = this.conf; assertNotNull(this.conf); assertEquals("https://localhost/Tic", this.conf.getUrl()); // Simulates configuration file change this.factory.withResourceName("net/jmob/jsconf/core/sample/app_05_2").reload(); - assertTrue(ref == this.conf); + assertSame(ref, this.conf); assertEquals("https://localhost/Tac", this.conf.getUrl()); this.factory.withResourceName("net/jmob/jsconf/core/sample/app_05").reload(); } @@ -57,7 +58,7 @@ public void test() { @Configuration static class ContextConfiguration { @Bean - public static ConfigurationFactory configurationFactory() { + static ConfigurationFactory configurationFactory() { return new ConfigurationFactory() .withResourceName("net/jmob/jsconf/core/sample/app_05") .withBean("simpleConf", ConfigBean.class, true); diff --git a/src/test/java/net/jmob/jsconf/core/sample/Sample06.java b/src/test/java/net/jmob/jsconf/core/sample/Sample06.java index 82bff97..50b34b8 100644 --- a/src/test/java/net/jmob/jsconf/core/sample/Sample06.java +++ b/src/test/java/net/jmob/jsconf/core/sample/Sample06.java @@ -1,12 +1,12 @@ /** * Copyright 2013 Yves Galante - * + *

* Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + *

* http://www.apache.org/licenses/LICENSE-2.0 - * + *

* Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -18,21 +18,22 @@ import net.jmob.jsconf.core.ConfigurationFactory; import net.jmob.jsconf.core.sample.bean.ConfigBean; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.test.annotation.Repeat; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.test.context.support.AnnotationConfigContextLoader; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; -@RunWith(SpringJUnit4ClassRunner.class) + +@ExtendWith(SpringExtension.class) @ContextConfiguration(loader = AnnotationConfigContextLoader.class) -public class Sample06 { +class Sample06 { @Autowired private ConfigBean conf; @@ -42,7 +43,7 @@ public class Sample06 { @Test @Repeat(value = 4) - public void test() { + void test() { final Object ref = this.conf; assertNotNull(this.conf); assertEquals("https://localhost/Tic", this.conf.getUrl()); @@ -50,9 +51,9 @@ public void test() { // Simulates configuration file change this.factory.withResourceName("net/jmob/jsconf/core/sample/app_06_2").reload(); - assertTrue(ref == this.conf); + assertSame(ref, this.conf); assertEquals("https://localhost/Tac", this.conf.getUrl()); - assertEquals(null, this.conf.getAMap()); + assertNull(this.conf.getAMap()); this.factory.withResourceName("net/jmob/jsconf/core/sample/app_06").reload(); } @@ -60,7 +61,7 @@ public void test() { @Configuration static class ContextConfiguration { @Bean - public static ConfigurationFactory configurationFactory() { + static ConfigurationFactory configurationFactory() { return new ConfigurationFactory() .withResourceName("net/jmob/jsconf/core/sample/app_06.properties") .withBean("simpleConf", ConfigBean.class, true); diff --git a/src/test/java/net/jmob/jsconf/core/sample/Sample07.java b/src/test/java/net/jmob/jsconf/core/sample/Sample07.java index de73b19..39584d9 100644 --- a/src/test/java/net/jmob/jsconf/core/sample/Sample07.java +++ b/src/test/java/net/jmob/jsconf/core/sample/Sample07.java @@ -1,12 +1,12 @@ /** * Copyright 2013 Yves Galante - * + *

* Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + *

* http://www.apache.org/licenses/LICENSE-2.0 - * + *

* Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -18,21 +18,24 @@ import net.jmob.jsconf.core.ConfigurationFactory; import net.jmob.jsconf.core.sample.bean.ConfigBean; -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.test.context.support.AnnotationConfigContextLoader; +import static org.junit.jupiter.api.Assertions.assertEquals; + + @ActiveProfiles("PROD") -@RunWith(SpringJUnit4ClassRunner.class) + +@ExtendWith(SpringExtension.class) @ContextConfiguration(loader = AnnotationConfigContextLoader.class) -public class Sample07 { +class Sample07 { @Autowired private ConfigBean conf; @@ -41,15 +44,15 @@ public class Sample07 { private ConfigurationFactory factory; @Test - public void test() { - Assert.assertEquals("Tac", this.conf.getUrl()); + void test() { + assertEquals("Tac", this.conf.getUrl()); } @Configuration static class ContextConfiguration { @Bean - public static ConfigurationFactory configurationFactory() { + static ConfigurationFactory configurationFactory() { return new ConfigurationFactory() .withResourceName("net/jmob/jsconf/core/sample/app_07.conf") .withBean("simpleConf", ConfigBean.class, true) diff --git a/src/test/java/net/jmob/jsconf/core/sample/Sample08.java b/src/test/java/net/jmob/jsconf/core/sample/Sample08.java index 88e6466..1701d42 100644 --- a/src/test/java/net/jmob/jsconf/core/sample/Sample08.java +++ b/src/test/java/net/jmob/jsconf/core/sample/Sample08.java @@ -1,12 +1,12 @@ /** * Copyright 2013 Yves Galante - * + *

* Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + *

* http://www.apache.org/licenses/LICENSE-2.0 - * + *

* Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -19,20 +19,21 @@ import net.jmob.jsconf.core.ConfigurationFactory; import net.jmob.jsconf.core.sample.bean.ConfigBean; import net.jmob.jsconf.core.sample.bean.RootConfigBean; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.test.context.support.AnnotationConfigContextLoader; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; -@RunWith(SpringJUnit4ClassRunner.class) + +@ExtendWith(SpringExtension.class) @ContextConfiguration(loader = AnnotationConfigContextLoader.class) -public class Sample08 { +class Sample08 { @Autowired private RootConfigBean myConfig; @@ -41,7 +42,7 @@ public class Sample08 { private ConfigBean myConfigChild; @Test - public void testChild() { + void testChild() { assertEquals("Tic", this.myConfig.getValue()); assertNotNull(this.myConfig.getChild()); assertEquals("https://localhost/Tic", this.myConfig.getChild().getUrl()); @@ -51,7 +52,7 @@ public void testChild() { @Configuration static class ContextConfiguration01 { @Bean - public static ConfigurationFactory configurationFactory() { + static ConfigurationFactory configurationFactory() { return new ConfigurationFactory() .withResourceName("net/jmob/jsconf/core/sample/app_08") .withBean("myRoot", RootConfigBean.class) diff --git a/src/test/java/net/jmob/jsconf/core/sample/bean/ConfigBean.java b/src/test/java/net/jmob/jsconf/core/sample/bean/ConfigBean.java index 6fc8ab7..21b622f 100644 --- a/src/test/java/net/jmob/jsconf/core/sample/bean/ConfigBean.java +++ b/src/test/java/net/jmob/jsconf/core/sample/bean/ConfigBean.java @@ -1,12 +1,12 @@ /** * Copyright 2013 Yves Galante - * + *

* Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + *

* http://www.apache.org/licenses/LICENSE-2.0 - * + *

* Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/src/test/java/net/jmob/jsconf/core/sample/bean/RootConfigBean.java b/src/test/java/net/jmob/jsconf/core/sample/bean/RootConfigBean.java index 87e012f..e68cb8a 100644 --- a/src/test/java/net/jmob/jsconf/core/sample/bean/RootConfigBean.java +++ b/src/test/java/net/jmob/jsconf/core/sample/bean/RootConfigBean.java @@ -1,12 +1,12 @@ /** * Copyright 2013 Yves Galante - * + *

* Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + *

* http://www.apache.org/licenses/LICENSE-2.0 - * + *

* Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/src/test/java/net/jmob/jsconf/core/sample/bean/Sequence.java b/src/test/java/net/jmob/jsconf/core/sample/bean/Sequence.java index 6be8a82..9e5bca7 100644 --- a/src/test/java/net/jmob/jsconf/core/sample/bean/Sequence.java +++ b/src/test/java/net/jmob/jsconf/core/sample/bean/Sequence.java @@ -1,12 +1,12 @@ /** * Copyright 2013 Yves Galante - * + *

* Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + *

* http://www.apache.org/licenses/LICENSE-2.0 - * + *

* Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/src/test/java/net/jmob/jsconf/core/sample/bean/SpringBean.java b/src/test/java/net/jmob/jsconf/core/sample/bean/SpringBean.java index 6a3f9f3..a632aaa 100644 --- a/src/test/java/net/jmob/jsconf/core/sample/bean/SpringBean.java +++ b/src/test/java/net/jmob/jsconf/core/sample/bean/SpringBean.java @@ -1,12 +1,12 @@ /** * Copyright 2013 Yves Galante - * + *

* Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + *

* http://www.apache.org/licenses/LICENSE-2.0 - * + *

* Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/src/test/java/net/jmob/jsconf/core/test/AnnotationTest.java b/src/test/java/net/jmob/jsconf/core/test/AnnotationTest.java index e29331e..6f53ed4 100644 --- a/src/test/java/net/jmob/jsconf/core/test/AnnotationTest.java +++ b/src/test/java/net/jmob/jsconf/core/test/AnnotationTest.java @@ -1,12 +1,12 @@ /** * Copyright 2013 Yves Galante - * + *

* Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + *

* http://www.apache.org/licenses/LICENSE-2.0 - * + *

* Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -16,43 +16,47 @@ package net.jmob.jsconf.core.test; -import net.jmob.jsconf.core.test.bean.MyConfig; import net.jmob.jsconf.core.ConfigurationFactory; import net.jmob.jsconf.core.test.bean.ConfigAnnotated; -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; +import net.jmob.jsconf.core.test.bean.MyConfig; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.BeanInitializationException; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.test.context.support.AnnotationConfigContextLoader; -@RunWith(SpringJUnit4ClassRunner.class) +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; + + +@ExtendWith(SpringExtension.class) @ContextConfiguration(loader = AnnotationConfigContextLoader.class) -public class AnnotationTest { +class AnnotationTest { @Autowired private ConfigAnnotated conf; - @Test(expected = BeanInitializationException.class) - public void testMissingAnnotation() { - new ConfigurationFactory() - .withResourceName("net/jmob/jsconf/core/test/app_annotated") - .withBean(MyConfig.class); + @Test + void testMissingAnnotation() { + assertThrows(BeanInitializationException.class, () -> + new ConfigurationFactory() + .withResourceName("net/jmob/jsconf/core/test/app_annotated") + .withBean(MyConfig.class)); } @Test - public void testAnnotated() { - Assert.assertEquals("Test", this.conf.getValue()); + void testAnnotated() { + assertEquals("Test", this.conf.getValue()); } @Configuration - static class ContextConfiguration { + public static class ContextConfiguration { @Bean - public static ConfigurationFactory configurationFactory() { + static ConfigurationFactory configurationFactory() { return new ConfigurationFactory() .withResourceName("net/jmob/jsconf/core/test/app_annotated.conf") .withScanPackage(AnnotationTest.class.getPackage().getName()); diff --git a/src/test/java/net/jmob/jsconf/core/test/ChildTest.java b/src/test/java/net/jmob/jsconf/core/test/ChildTest.java index b160fd6..28cd2c5 100644 --- a/src/test/java/net/jmob/jsconf/core/test/ChildTest.java +++ b/src/test/java/net/jmob/jsconf/core/test/ChildTest.java @@ -1,12 +1,12 @@ /** * Copyright 2013 Yves Galante - * + *

* Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + *

* http://www.apache.org/licenses/LICENSE-2.0 - * + *

* Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -18,20 +18,21 @@ import net.jmob.jsconf.core.ConfigurationFactory; import net.jmob.jsconf.core.test.bean.MyConfig; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.test.context.support.AnnotationConfigContextLoader; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; -@RunWith(SpringJUnit4ClassRunner.class) + +@ExtendWith(SpringExtension.class) @ContextConfiguration(loader = AnnotationConfigContextLoader.class) -public class ChildTest { +class ChildTest { @Autowired private MyConfig myConfig; @@ -46,13 +47,13 @@ public class ChildTest { private MyConfig myConfigChild2; @Test - public void testChild() { + void testChild() { assertNotSame(this.myConfig, this.myConfig2); assertNotSame(this.myConfigChild, this.myConfigChild2); } @Test - public void testChild1() { + void testChild1() { assertEquals("Tic", this.myConfig.getValue()); assertNotSame(this.myConfig, this.myConfig.getChild()); assertNotNull(this.myConfig.getChild()); @@ -61,7 +62,7 @@ public void testChild1() { } @Test - public void testChild2() { + void testChild2() { assertEquals("Tic", this.myConfig2.getValue()); assertNotSame(this.myConfig2, this.myConfig2.getChild()); assertNotNull(this.myConfig2.getChild()); @@ -70,9 +71,9 @@ public void testChild2() { } @Configuration - static class ContextConfiguration01 { + public static class ContextConfiguration01 { @Bean(name = "context") - public static ConfigurationFactory configurationFactory() { + static ConfigurationFactory configurationFactory() { return new ConfigurationFactory().withResourceName("net/jmob/jsconf/core/test/app_child") .withBean("myConfig", MyConfig.class) .withBean("myConfig/child", MyConfig.class, "myConfigChild"); @@ -80,9 +81,9 @@ public static ConfigurationFactory configurationFactory() { } @Configuration - static class ContextConfiguration02 { + public static class ContextConfiguration02 { @Bean(name = "context2") - public static ConfigurationFactory configurationFactory() { + static ConfigurationFactory configurationFactory() { return new ConfigurationFactory().withResourceName("net/jmob/jsconf/core/test/app_child2") .withBean("myConfig", MyConfig.class, "myConfig2") .withBean("myConfig/child", MyConfig.class, "myConfigChild2"); diff --git a/src/test/java/net/jmob/jsconf/core/test/ConfigTest.java b/src/test/java/net/jmob/jsconf/core/test/ConfigTest.java index e1dd406..2d9114c 100644 --- a/src/test/java/net/jmob/jsconf/core/test/ConfigTest.java +++ b/src/test/java/net/jmob/jsconf/core/test/ConfigTest.java @@ -1,12 +1,12 @@ /** * Copyright 2013 Yves Galante - * + *

* Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + *

* http://www.apache.org/licenses/LICENSE-2.0 - * + *

* Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -20,22 +20,23 @@ import net.jmob.jsconf.core.test.bean.MyConfig; import net.jmob.jsconf.core.test.bean.ServiceSpringBean; import net.jmob.jsconf.core.test.bean.SimpleBeanSpring; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.test.context.support.AnnotationConfigContextLoader; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; -@RunWith(SpringJUnit4ClassRunner.class) + +@ExtendWith(SpringExtension.class) @ContextConfiguration(loader = AnnotationConfigContextLoader.class) -public class ConfigTest { +class ConfigTest { @Autowired() @Qualifier(value = "test_2") @@ -45,7 +46,7 @@ public class ConfigTest { private ServiceSpringBean service; @Test - public void testServiceSpringBean() { + void testServiceSpringBean() { MyConfig localConfig = this.service.getConfig(); assertNotNull(localConfig.getChild()); assertEquals("Hello World, I a spring bean!", this.service.getValue()); @@ -61,7 +62,7 @@ public void testServiceSpringBean() { } @Test - public void testSimpleBeanSpring() { + void testSimpleBeanSpring() { assertEquals("I am a child of springOnConf!", this.config.getValue()); assertEquals("Hello from child", this.config.getChildRef().getValue()); assertEquals(this.service.getConfig().getChild(), this.config.getChildRef()); @@ -69,7 +70,7 @@ public void testSimpleBeanSpring() { @Configuration @ComponentScan(basePackageClasses = {ServiceSpringBean.class}) - static class ContextConfiguration { + public static class ContextConfiguration { @Bean public static ConfigurationFactory configurationFactory() { return new ConfigurationFactory() diff --git a/src/test/java/net/jmob/jsconf/core/test/ProfileTest.java b/src/test/java/net/jmob/jsconf/core/test/ProfileTest.java index b68bde1..75fb6f4 100644 --- a/src/test/java/net/jmob/jsconf/core/test/ProfileTest.java +++ b/src/test/java/net/jmob/jsconf/core/test/ProfileTest.java @@ -1,12 +1,12 @@ /** * Copyright 2013 Yves Galante - * + *

* Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + *

* http://www.apache.org/licenses/LICENSE-2.0 - * + *

* Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -18,21 +18,22 @@ import net.jmob.jsconf.core.ConfigurationFactory; import net.jmob.jsconf.core.sample.bean.ConfigBean; -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.test.context.support.AnnotationConfigContextLoader; +import static org.junit.jupiter.api.Assertions.assertEquals; + @ActiveProfiles("PROD") -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @ContextConfiguration(loader = AnnotationConfigContextLoader.class) -public class ProfileTest { +class ProfileTest { @Autowired private ConfigBean simpleConf; @@ -47,19 +48,19 @@ public class ProfileTest { private ConfigurationFactory context02; @Test - public void testProfile() { - Assert.assertEquals("Tac", this.simpleConf.getUrl()); + void testProfile() { + assertEquals("Tac", this.simpleConf.getUrl()); } @Test - public void testProfileConf() { - Assert.assertEquals("Tac", this.simpleConf2.getUrl()); + void testProfileConf() { + assertEquals("Tac", this.simpleConf2.getUrl()); } @Configuration - static class ContextConfiguration01 { + public static class ContextConfiguration01 { @Bean(name = "context01") - public static ConfigurationFactory configurationFactory() { + static ConfigurationFactory configurationFactory() { return new ConfigurationFactory() .withResourceName("net/jmob/jsconf/core/test/app_profile") .withBean("simpleConf", ConfigBean.class) diff --git a/src/test/java/net/jmob/jsconf/core/test/RealReloadingTest.java b/src/test/java/net/jmob/jsconf/core/test/RealReloadingTest.java index 6363474..355fffb 100644 --- a/src/test/java/net/jmob/jsconf/core/test/RealReloadingTest.java +++ b/src/test/java/net/jmob/jsconf/core/test/RealReloadingTest.java @@ -2,15 +2,16 @@ import net.jmob.jsconf.core.ConfigurationFactory; import net.jmob.jsconf.core.sample.bean.ConfigBean; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.test.context.support.AnnotationConfigContextLoader; import java.io.File; @@ -21,12 +22,14 @@ import java.nio.file.Paths; import static java.lang.Thread.sleep; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; + // Test required to have put ${java.io.tmpdir} on ClassPath -@RunWith(SpringJUnit4ClassRunner.class) +@Disabled +@ExtendWith(SpringExtension.class) @ContextConfiguration(loader = AnnotationConfigContextLoader.class) -public class RealReloadingTest { +class RealReloadingTest { private static final String TIC = "Tic"; private static final String TAC = "Tac"; @@ -37,31 +40,31 @@ public class RealReloadingTest { @Autowired private ConfigBean conf; - @BeforeClass - public static void init() throws IOException { - tempDirectory = Files.createTempDirectory("jsconf-" .concat(Long.toString(System.nanoTime()))); + @BeforeAll + static void init() throws IOException { + tempDirectory = Files.createTempDirectory("jsconf-".concat(Long.toString(System.nanoTime()))); tempFile = Files.createFile(Paths.get(tempDirectory.toString(), "app.conf")); } - @AfterClass - public static void clean() throws IOException { + @AfterAll + static void clean() throws IOException { Files.deleteIfExists(tempFile); Files.deleteIfExists(tempDirectory); } @Test - // Test required to have put ${java.io.tmpdir} on ClassPath - public void testRealReloading() throws IOException, InterruptedException { + // Test required to have put ${java.io.tmpdir} on ClassPath + void testRealReloading() throws IOException, InterruptedException { final Object ref = this.conf; assertNotNull(this.conf); - assertEquals(null, this.conf.getUrl()); + assertNull(this.conf.getUrl()); write(TIC); assertEquals(TIC, this.conf.getUrl()); write(TAC); assertEquals(TAC, this.conf.getUrl()); - assertTrue(ref == this.conf); + assertSame(ref, this.conf); Files.deleteIfExists(tempFile); Files.createFile(Paths.get(tempDirectory.toString(), "app.conf")); @@ -75,13 +78,13 @@ private void write(String value) throws IOException, InterruptedException { fw.append("simpleConf : { url : \"").append(value).append("\" }"); fw.flush(); } - sleep(5000); + sleep(10000); } @Configuration - static class ContextConfiguration { + public static class ContextConfiguration { @Bean - public static ConfigurationFactory configurationFactory() { + static ConfigurationFactory configurationFactory() { return new ConfigurationFactory() .withResourceName(tempDirectory.getName(tempDirectory.getNameCount() - 1) + "/app.conf")// .withBean("simpleConf", ConfigBean.class, "myBeanId", true); diff --git a/src/test/java/net/jmob/jsconf/core/test/VirtualBeanTest.java b/src/test/java/net/jmob/jsconf/core/test/VirtualBeanTest.java index 809c5bc..e96a42b 100644 --- a/src/test/java/net/jmob/jsconf/core/test/VirtualBeanTest.java +++ b/src/test/java/net/jmob/jsconf/core/test/VirtualBeanTest.java @@ -1,12 +1,12 @@ /** * Copyright 2013 Yves Galante - * + *

* Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + *

* http://www.apache.org/licenses/LICENSE-2.0 - * + *

* Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -16,11 +16,11 @@ package net.jmob.jsconf.core.test; -import net.jmob.jsconf.core.test.bean.ConfigByInterface; import net.jmob.jsconf.core.ConfigurationFactory; import net.jmob.jsconf.core.impl.VirtualBean; -import org.junit.Test; -import org.junit.runner.RunWith; +import net.jmob.jsconf.core.test.bean.ConfigByInterface; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.BeanCreationException; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; @@ -29,16 +29,17 @@ import org.springframework.context.annotation.Configuration; import org.springframework.jmx.access.InvocationFailureException; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.test.context.support.AnnotationConfigContextLoader; import java.util.HashMap; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; + -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @ContextConfiguration(loader = AnnotationConfigContextLoader.class) -public class VirtualBeanTest { +class VirtualBeanTest { @Autowired @Qualifier("simpleConf") @@ -51,7 +52,7 @@ public class VirtualBeanTest { private ConfigByInterface conf3; @Test - public void testHashCode() { + void testHashCode() { assertEquals(-1831264279, this.conf.hashCode()); assertEquals(this.conf.hashCode(), this.conf2.hashCode()); assertEquals(-1828017501, this.conf3.hashCode()); @@ -59,12 +60,12 @@ public void testHashCode() { } @Test - public void testEquals() { - assertNotEquals(this.conf, ""); - assertNotEquals(this.conf, null); + void testEquals() { + assertNotEquals("", this.conf); + assertNotNull(this.conf); assertEquals(this.conf, this.conf); assertEquals(new VirtualBean(null), new VirtualBean(null)); - assertEquals(new VirtualBean(new HashMap()), new VirtualBean(new HashMap())); + assertEquals(new VirtualBean(new HashMap<>()), new VirtualBean(new HashMap<>())); assertNotEquals(this.conf, new VirtualBean(null)); assertNotEquals(new VirtualBean(null), this.conf); assertNotSame(this.conf, this.conf2); @@ -74,37 +75,38 @@ public void testEquals() { } @Test - public void testToString() { + void testToString() { assertEquals("{getUrl=https://localhost/Tic}", this.conf.toString()); } @Test - public void testGet() { + void testGet() { assertEquals("https://localhost/Tic", this.conf.getUrl()); assertEquals("xxx", this.conf3.getX()); } - @Test(expected = InvocationFailureException.class) - public void testSet() { - this.conf3.setX("yyy"); + @Test + void testSet() { + assertThrows(InvocationFailureException.class, () -> this.conf3.setX("yyy")); } @Test - public void validationSuccess() { + void validationSuccess() { new AnnotationConfigApplicationContext(ContextConfiguration.class) .getBean("simpleConf"); } - @Test(expected = BeanCreationException.class) - public void validationFailed() { - new AnnotationConfigApplicationContext(ContextConfigurationValidationFailed.class) - .getBean("simpleConf"); + @Test + void validationFailed() { + assertThrows(BeanCreationException.class, () -> + new AnnotationConfigApplicationContext(ContextConfigurationValidationFailed.class) + .getBean("simpleConf")); } @Configuration - static class ContextConfiguration { + public static class ContextConfiguration { @Bean - public static ConfigurationFactory configurationFactory() { + static ConfigurationFactory configurationFactory() { return new ConfigurationFactory() .withResourceName("net/jmob/jsconf/core/test/app_virtual") .withBean("simpleConf", ConfigByInterface.class) @@ -113,9 +115,9 @@ public static ConfigurationFactory configurationFactory() { } } - static class ContextConfigurationValidationFailed { + public static class ContextConfigurationValidationFailed { @Bean - public static ConfigurationFactory configurationFactory() { + static ConfigurationFactory configurationFactory() { return new ConfigurationFactory() .withResourceName("net/jmob/jsconf/core/test/app_virtual_failed") .withBean("simpleConf", ConfigByInterface.class); diff --git a/src/test/java/net/jmob/jsconf/core/test/bean/ConfigAnnotated.java b/src/test/java/net/jmob/jsconf/core/test/bean/ConfigAnnotated.java index 57e75f2..5b9136c 100644 --- a/src/test/java/net/jmob/jsconf/core/test/bean/ConfigAnnotated.java +++ b/src/test/java/net/jmob/jsconf/core/test/bean/ConfigAnnotated.java @@ -1,12 +1,12 @@ /** * Copyright 2013 Yves Galante - * + *

* Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + *

* http://www.apache.org/licenses/LICENSE-2.0 - * + *

* Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/src/test/java/net/jmob/jsconf/core/test/bean/ConfigByInterface.java b/src/test/java/net/jmob/jsconf/core/test/bean/ConfigByInterface.java index 9afba13..1e94ccd 100644 --- a/src/test/java/net/jmob/jsconf/core/test/bean/ConfigByInterface.java +++ b/src/test/java/net/jmob/jsconf/core/test/bean/ConfigByInterface.java @@ -1,12 +1,12 @@ /** * Copyright 2013 Yves Galante - * + *

* Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + *

* http://www.apache.org/licenses/LICENSE-2.0 - * + *

* Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/src/test/java/net/jmob/jsconf/core/test/bean/MyConfig.java b/src/test/java/net/jmob/jsconf/core/test/bean/MyConfig.java index 4929281..c27710b 100644 --- a/src/test/java/net/jmob/jsconf/core/test/bean/MyConfig.java +++ b/src/test/java/net/jmob/jsconf/core/test/bean/MyConfig.java @@ -1,12 +1,12 @@ /** * Copyright 2013 Yves Galante - * + *

* Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + *

* http://www.apache.org/licenses/LICENSE-2.0 - * + *

* Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/src/test/java/net/jmob/jsconf/core/test/bean/ServiceSpringBean.java b/src/test/java/net/jmob/jsconf/core/test/bean/ServiceSpringBean.java index 099d4c0..fb603d3 100644 --- a/src/test/java/net/jmob/jsconf/core/test/bean/ServiceSpringBean.java +++ b/src/test/java/net/jmob/jsconf/core/test/bean/ServiceSpringBean.java @@ -1,12 +1,12 @@ /** * Copyright 2013 Yves Galante - * + *

* Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + *

* http://www.apache.org/licenses/LICENSE-2.0 - * + *

* Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/src/test/java/net/jmob/jsconf/core/test/bean/SimpleBeanSpring.java b/src/test/java/net/jmob/jsconf/core/test/bean/SimpleBeanSpring.java index 82fa1e7..be13090 100644 --- a/src/test/java/net/jmob/jsconf/core/test/bean/SimpleBeanSpring.java +++ b/src/test/java/net/jmob/jsconf/core/test/bean/SimpleBeanSpring.java @@ -1,12 +1,12 @@ /** * Copyright 2013 Yves Galante - * + *

* Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + *

* http://www.apache.org/licenses/LICENSE-2.0 - * + *

* Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/src/test/resources/net/jmob/jsconf/core/sample/app_06.properties b/src/test/resources/net/jmob/jsconf/core/sample/app_06.properties index 3cff864..4cf17b5 100644 --- a/src/test/resources/net/jmob/jsconf/core/sample/app_06.properties +++ b/src/test/resources/net/jmob/jsconf/core/sample/app_06.properties @@ -1,3 +1,3 @@ -simpleConf.url = https://localhost/Tic -simpleConf.aMap.key1= test1 -simpleConf.aMap.key2= test2 \ No newline at end of file +simpleConf.url=https://localhost/Tic +simpleConf.aMap.key1=test1 +simpleConf.aMap.key2=test2 \ No newline at end of file diff --git a/src/test/resources/net/jmob/jsconf/core/sample/app_06_2.properties b/src/test/resources/net/jmob/jsconf/core/sample/app_06_2.properties index a172321..564007a 100644 --- a/src/test/resources/net/jmob/jsconf/core/sample/app_06_2.properties +++ b/src/test/resources/net/jmob/jsconf/core/sample/app_06_2.properties @@ -1 +1 @@ -simpleConf.url = https://localhost/Tac \ No newline at end of file +simpleConf.url=https://localhost/Tac \ No newline at end of file