diff --git a/core-java/README.md b/core-java/README.md index 1d1e63f36a..1de57c9311 100644 --- a/core-java/README.md +++ b/core-java/README.md @@ -104,3 +104,11 @@ - [Guide to DelayQueue](http://www.baeldung.com/java-delay-queue) - [Comparing getPath(), getAbsolutePath(), and getCanonicalPath() in Java](http://www.baeldung.com/java-path) - [How to Add a Single Element to a Stream](http://www.baeldung.com/java-stream-append-prepend) +- [A Guide to Java SynchronousQueue](http://www.baeldung.com/java-synchronous-queue) +- [Guide to the Java TransferQueue](http://www.baeldung.com/java-transfer-queue) +- [Kotlin Java Interoperability](http://www.baeldung.com/kotlin-java-interoperability) +- [Guide to the ConcurrentSkipListMap](http://www.baeldung.com/java-concurrent-skip-list-map) +- [Difference Between Wait and Sleep in Java](http://www.baeldung.com/java-wait-and-sleep) +- [LongAdder and LongAccumulator in Java](http://www.baeldung.com/java-longadder-and-longaccumulator) +- [Using Java MappedByteBuffer](http://www.baeldung.com/java-mapped-byte-buffer) + diff --git a/guava21/README.md b/guava21/README.md index 8725352d69..2a54416e41 100644 --- a/guava21/README.md +++ b/guava21/README.md @@ -1,2 +1,3 @@ ### Relevant articles: - [New Stream, Comparator and Collector Functionality in Guava 21](http://www.baeldung.com/guava-21-new) +- [New in Guava 21 common.util.concurrent](http://www.baeldung.com/guava-21-util-concurrent) diff --git a/jee7/README.md b/jee7/README.md index fdd260468c..71163d6640 100644 --- a/jee7/README.md +++ b/jee7/README.md @@ -3,3 +3,4 @@ - [JSON Processing in Java EE 7](http://www.baeldung.com/jee7-json) - [Converters, Listeners and Validators in Java EE 7](http://www.baeldung.com/java-ee7-converter-listener-validator) - [Introduction to JAX-WS](http://www.baeldung.com/jax-ws) +- [A Guide to Java EE Web-Related Annotations](http://www.baeldung.com/javaee-web-annotations) diff --git a/jee7/pom.xml b/jee7/pom.xml index fe7c5e4c11..e633d2df3d 100644 --- a/jee7/pom.xml +++ b/jee7/pom.xml @@ -1,381 +1,381 @@ - 4.0.0 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + 4.0.0 - com.baeldung - jee7 - 1.0-SNAPSHOT - JavaEE 7 Arquillian Archetype Sample + com.baeldung + jee7 + 1.0-SNAPSHOT + JavaEE 7 Arquillian Archetype Sample - - com.baeldung - parent-modules - 1.0.0-SNAPSHOT - + + com.baeldung + parent-modules + 1.0.0-SNAPSHOT + - - 1.8 - 3.0.0 + + 1.8 + 3.0.0 - 7.0 - 1.1.11.Final - 8.2.1.Final - 1.7.0 - 1.4.6.Final - 3.0.19.Final - 4.1.1 - 1.0.4 - 1.13 - 2.25 - 1.0.0.Final + 7.0 + 1.1.11.Final + 8.2.1.Final + 1.7.0 + 1.4.6.Final + 3.0.19.Final + 4.1.1 + 1.0.4 + 1.13 + 2.25 + 1.0.0.Final - 2.6 - + 2.6 + - - ${maven.min.version} - + + ${maven.min.version} + - - - - org.jboss.arquillian - arquillian-bom - ${arquillian_core.version} - import - pom - - - org.jboss.arquillian.extension - arquillian-drone-bom - 2.0.1.Final - pom - import - - - + + + + org.jboss.arquillian + arquillian-bom + ${arquillian_core.version} + import + pom + + + org.jboss.arquillian.extension + arquillian-drone-bom + 2.0.1.Final + pom + import + + + - - - javax - javaee-api - ${javaee_api.version} - provided - - - - org.jboss.arquillian.junit - arquillian-junit-container - test - + - org.jboss.arquillian.graphene - graphene-webdriver - 2.1.0.Final - pom - test - - - com.jayway.awaitility - awaitility - ${awaitility.version} - test - + javax + javaee-api + ${javaee_api.version} + provided + - - org.jboss.shrinkwrap.resolver - shrinkwrap-resolver-impl-maven - test - jar - - - - org.jboss.shrinkwrap.resolver - shrinkwrap-resolver-impl-maven-archive - test - - - org.apache.httpcomponents - httpclient - 4.5 - - - commons-io - commons-io - 2.4 - - - com.sun.faces - jsf-api - 2.2.14 - - - com.sun.faces - jsf-impl - 2.2.14 - - - javax.servlet - jstl - 1.2 - - - javax.servlet - javax.servlet-api - 3.1.0 - - javax.servlet.jsp - jsp-api - 2.2 - provided + org.jboss.arquillian.junit + arquillian-junit-container + test - taglibs - standard - 1.1.2 - - + org.jboss.arquillian.graphene + graphene-webdriver + 2.1.0.Final + pom + test + + + com.jayway.awaitility + awaitility + ${awaitility.version} + test + - - - - org.apache.maven.plugins - maven-war-plugin - ${maven-war-plugin.version} - - false - - - - + + org.jboss.shrinkwrap.resolver + shrinkwrap-resolver-impl-maven + test + jar + - + + org.jboss.shrinkwrap.resolver + shrinkwrap-resolver-impl-maven-archive + test + + + org.apache.httpcomponents + httpclient + 4.5 + + + commons-io + commons-io + 2.4 + + + com.sun.faces + jsf-api + 2.2.14 + + + com.sun.faces + jsf-impl + 2.2.14 + + + javax.servlet + jstl + 1.2 + + + javax.servlet + javax.servlet-api + 3.1.0 + + + javax.servlet.jsp + jsp-api + 2.2 + provided + + + taglibs + standard + 1.1.2 + + - - wildfly-managed-arquillian - - true - - - standalone-full.xml - ${project.build.directory}/wildfly-${version.wildfly} - - - - io.undertow - undertow-websockets-jsr - ${undertow-websockets-jsr.version} - test - - - org.jboss.resteasy - resteasy-client - ${resteasy.version} - test - - - org.jboss.resteasy - resteasy-jaxb-provider - ${resteasy.version} - test - - - org.jboss.resteasy - resteasy-json-p-provider - ${resteasy.version} - test - - - org.wildfly - wildfly-arquillian-container-managed - ${wildfly.version} - test - - - - - - - maven-dependency-plugin - 2.8 - - ${maven.test.skip} - - - - unpack - process-test-classes - - unpack - - - - - org.wildfly - wildfly-dist - ${wildfly.version} - zip - false - ${project.build.directory} - - - - - - - - maven-surefire-plugin - 2.17 - - - ${project.build.directory}/wildfly-${wildfly.version} - - - - - - - - - wildfly-remote-arquillian - - - io.undertow - undertow-websockets-jsr - ${undertow-websockets-jsr.version} - test - - - org.jboss.resteasy - resteasy-client - ${resteasy.version} - test - - - org.jboss.resteasy - resteasy-jaxb-provider - ${resteasy.version} - test - - - org.jboss.resteasy - resteasy-json-p-provider - ${resteasy.version} - test - - - org.wildfly - wildfly-arquillian-container-remote - ${wildfly.version} - test - - - - - glassfish-embedded-arquillian - - - org.glassfish.main.extras - glassfish-embedded-all - ${glassfish-embedded-all.version} - test - - - org.glassfish - javax.json - ${javax.json.version} - test - - - org.glassfish.tyrus - tyrus-client - ${tyrus.version} - test - - - org.glassfish.tyrus - tyrus-container-grizzly-client - ${tyrus.version} - test - - - org.glassfish.jersey.core - jersey-client - ${jersey.version} - test - - - org.jboss.arquillian.container - arquillian-glassfish-embedded-3.1 - ${arquillian-glassfish.version} - test - - - - - glassfish-remote-arquillian - - - org.glassfish - javax.json - ${javax.json.version} - test - - - org.glassfish.tyrus - tyrus-client - ${tyrus.version} - test - - - org.glassfish.tyrus - tyrus-container-grizzly-client - ${tyrus.version} - test - - - org.glassfish.jersey.core - jersey-client - ${jersey.version} - test - - - org.glassfish.jersey.media - jersey-media-json-jackson - ${jersey.version} - test - - - org.glassfish.jersey.media - jersey-media-json-processing - ${jersey.version} - test - - - org.jboss.arquillian.container - arquillian-glassfish-remote-3.1 - ${arquillian-glassfish.version} - test - - - - - webdriver-chrome - - true - - - chrome - - + + + + org.apache.maven.plugins + maven-war-plugin + ${maven-war-plugin.version} + + false + + + + - - webdriver-firefox - - firefox - + + + + wildfly-managed-arquillian + + true + + + standalone-full.xml + ${project.build.directory}/wildfly-${version.wildfly} + + + + io.undertow + undertow-websockets-jsr + ${undertow-websockets-jsr.version} + test + + + org.jboss.resteasy + resteasy-client + ${resteasy.version} + test + + + org.jboss.resteasy + resteasy-jaxb-provider + ${resteasy.version} + test + + + org.jboss.resteasy + resteasy-json-p-provider + ${resteasy.version} + test + + + org.wildfly + wildfly-arquillian-container-managed + ${wildfly.version} + test + + + + + + + maven-dependency-plugin + 2.8 + + ${maven.test.skip} + + + + unpack + process-test-classes + + unpack + + + + + org.wildfly + wildfly-dist + ${wildfly.version} + zip + false + ${project.build.directory} + + + + + + + + maven-surefire-plugin + 2.17 + + + ${project.build.directory}/wildfly-${wildfly.version} + + + + + + - + + wildfly-remote-arquillian + + + io.undertow + undertow-websockets-jsr + ${undertow-websockets-jsr.version} + test + + + org.jboss.resteasy + resteasy-client + ${resteasy.version} + test + + + org.jboss.resteasy + resteasy-jaxb-provider + ${resteasy.version} + test + + + org.jboss.resteasy + resteasy-json-p-provider + ${resteasy.version} + test + + + org.wildfly + wildfly-arquillian-container-remote + ${wildfly.version} + test + + + + + glassfish-embedded-arquillian + + + org.glassfish.main.extras + glassfish-embedded-all + ${glassfish-embedded-all.version} + test + + + org.glassfish + javax.json + ${javax.json.version} + test + + + org.glassfish.tyrus + tyrus-client + ${tyrus.version} + test + + + org.glassfish.tyrus + tyrus-container-grizzly-client + ${tyrus.version} + test + + + org.glassfish.jersey.core + jersey-client + ${jersey.version} + test + + + org.jboss.arquillian.container + arquillian-glassfish-embedded-3.1 + ${arquillian-glassfish.version} + test + + + + + glassfish-remote-arquillian + + + org.glassfish + javax.json + ${javax.json.version} + test + + + org.glassfish.tyrus + tyrus-client + ${tyrus.version} + test + + + org.glassfish.tyrus + tyrus-container-grizzly-client + ${tyrus.version} + test + + + org.glassfish.jersey.core + jersey-client + ${jersey.version} + test + + + org.glassfish.jersey.media + jersey-media-json-jackson + ${jersey.version} + test + + + org.glassfish.jersey.media + jersey-media-json-processing + ${jersey.version} + test + + + org.jboss.arquillian.container + arquillian-glassfish-remote-3.1 + ${arquillian-glassfish.version} + test + + + + + webdriver-chrome + + true + + + chrome + + + + + webdriver-firefox + + firefox + + + diff --git a/junit5/src/test/java/com/baeldung/DynamicTestsExample.java b/junit5/src/test/java/com/baeldung/DynamicTestsExample.java index ce1f8b16a7..6a97f2347b 100644 --- a/junit5/src/test/java/com/baeldung/DynamicTestsExample.java +++ b/junit5/src/test/java/com/baeldung/DynamicTestsExample.java @@ -18,6 +18,9 @@ import org.junit.jupiter.api.DynamicTest; import org.junit.jupiter.api.TestFactory; import org.junit.jupiter.api.function.ThrowingConsumer; +import com.baeldung.helpers.Employee; +import com.baeldung.helpers.EmployeeDao; + public class DynamicTestsExample { @TestFactory @@ -111,6 +114,29 @@ public class DynamicTestsExample { } + @TestFactory + Stream dynamicTestsForEmployeeWorkflows() { + List inputList = + Arrays.asList(new Employee(1, "Fred"), new Employee(2), new Employee(3, "John")); + + EmployeeDao dao = new EmployeeDao(); + Stream saveEmployeeStream = inputList.stream().map(emp -> + DynamicTest.dynamicTest("saveEmployee: " + emp.toString(), () -> { + Employee returned = dao.save(emp.getId()); + assertEquals(returned.getId(), emp.getId()); + })); + + Stream saveEmployeeWithFirstNameStream + = inputList.stream().filter(emp -> !emp.getFirstName().isEmpty()) + .map(emp -> DynamicTest.dynamicTest("saveEmployeeWithName" + emp.toString(), () -> { + Employee returned = dao.save(emp.getId(), emp.getFirstName()); + assertEquals(returned.getId(), emp.getId()); + assertEquals(returned.getFirstName(), emp.getFirstName()); + })); + + return Stream.concat(saveEmployeeStream, saveEmployeeWithFirstNameStream); + } + class DomainNameResolver { private Map ipByDomainName = new HashMap<>(); diff --git a/junit5/src/test/java/com/baeldung/helpers/Employee.java b/junit5/src/test/java/com/baeldung/helpers/Employee.java new file mode 100644 index 0000000000..7fa724e4a8 --- /dev/null +++ b/junit5/src/test/java/com/baeldung/helpers/Employee.java @@ -0,0 +1,38 @@ +package com.baeldung.helpers; + +public class Employee { + + private long id; + private String firstName; + + public Employee(long id) { + this.id = id; + this.firstName = ""; + } + + public Employee(long id, String firstName) { + this.id = id; + this.firstName = firstName; + } + + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + @Override + public String toString() { + return "Employee [id=" + id + ", firstName=" + firstName + "]"; + } +} diff --git a/junit5/src/test/java/com/baeldung/helpers/EmployeeDao.java b/junit5/src/test/java/com/baeldung/helpers/EmployeeDao.java new file mode 100644 index 0000000000..b23e5bf5e3 --- /dev/null +++ b/junit5/src/test/java/com/baeldung/helpers/EmployeeDao.java @@ -0,0 +1,16 @@ +package com.baeldung.helpers; + +public class EmployeeDao { + + public Employee save(long id) { + return new Employee(id); + } + + public Employee save(long id, String firstName) { + return new Employee(id, firstName); + } + + public Employee update(Employee employee) { + return employee; + } +} diff --git a/kotlin/README.md b/kotlin/README.md index 950f6460d5..57d16e0415 100644 --- a/kotlin/README.md +++ b/kotlin/README.md @@ -5,3 +5,4 @@ - [Comprehensive Guide to Null Safety in Kotlin](http://www.baeldung.com/kotlin-null-safety) - [Kotlin Java Interoperability](http://www.baeldung.com/kotlin-java-interoperability) - [Difference Between “==” and “===” in Kotlin]() +- [Generics in Kotlin](http://www.baeldung.com/kotlin-generics) diff --git a/libraries/README.md b/libraries/README.md index 1cfa7be86c..c405cc90d8 100644 --- a/libraries/README.md +++ b/libraries/README.md @@ -9,7 +9,8 @@ - [Introduction to Apache Flink with Java](http://www.baeldung.com/apache-flink) - [Introduction to JSONassert](http://www.baeldung.com/jsonassert) - [Intro to JaVer](http://www.baeldung.com/javers) - +- [Introduction to Apache Commons Math](http://www.baeldung.com/apache-commons-math) +- [Intro to JaVer](http://www.baeldung.com/serenity-bdd) The libraries module contains examples related to small libraries that are relatively easy to use and does not require any separate module of its own. diff --git a/libraries/pom.xml b/libraries/pom.xml index 6d41902db7..a4b554365d 100644 --- a/libraries/pom.xml +++ b/libraries/pom.xml @@ -225,12 +225,7 @@ org.datanucleus datanucleus-maven-plugin 5.0.2 - - - com.h2database - h2 - 1.4.194 - + org.datanucleus datanucleus-xml @@ -269,6 +264,18 @@ h2 1.4.195 + + pl.pragmatists + JUnitParams + ${jUnitParams.version} + test + + + org.quartz-scheduler + quartz + 2.3.0 + + 0.7.0 @@ -292,6 +299,7 @@ 1.24.0 1.1.3-rc.5 1.4.0 + 1.1.0 diff --git a/libraries/src/main/java/com/baeldung/junitparams/SafeAdditionUtil.java b/libraries/src/main/java/com/baeldung/junitparams/SafeAdditionUtil.java new file mode 100644 index 0000000000..a2c1573dca --- /dev/null +++ b/libraries/src/main/java/com/baeldung/junitparams/SafeAdditionUtil.java @@ -0,0 +1,15 @@ +package com.baeldung.junitparams; + +public class SafeAdditionUtil { + + public int safeAdd(int a, int b) { + long result = ((long) a) + b; + if (result > Integer.MAX_VALUE) { + return Integer.MAX_VALUE; + } else if (result < Integer.MIN_VALUE) { + return Integer.MIN_VALUE; + } + return (int) result; + } + +} diff --git a/libraries/src/main/java/com/baeldung/quartz/QuartzExample.java b/libraries/src/main/java/com/baeldung/quartz/QuartzExample.java new file mode 100644 index 0000000000..1e37fc028b --- /dev/null +++ b/libraries/src/main/java/com/baeldung/quartz/QuartzExample.java @@ -0,0 +1,42 @@ +package com.baeldung.quartz; + +import org.quartz.JobBuilder; +import org.quartz.JobDetail; +import org.quartz.Scheduler; +import org.quartz.SchedulerException; +import org.quartz.SchedulerFactory; +import org.quartz.SimpleScheduleBuilder; +import org.quartz.Trigger; +import org.quartz.TriggerBuilder; +import org.quartz.impl.StdSchedulerFactory; + +public class QuartzExample { + + public static void main(String args[]) { + + SchedulerFactory schedFact = new StdSchedulerFactory(); + try { + + Scheduler sched = schedFact.getScheduler(); + + JobDetail job = JobBuilder.newJob(SimpleJob.class) + .withIdentity("myJob", "group1") + .build(); + + Trigger trigger = TriggerBuilder.newTrigger() + .withIdentity("myTrigger", "group1") + .startNow() + .withSchedule(SimpleScheduleBuilder.simpleSchedule() + .withIntervalInSeconds(40) + .repeatForever()) + .build(); + + sched.scheduleJob(job, trigger); + sched.start(); + + } catch (SchedulerException e) { + e.printStackTrace(); + } + } + +} \ No newline at end of file diff --git a/libraries/src/main/java/com/baeldung/quartz/SimpleJob.java b/libraries/src/main/java/com/baeldung/quartz/SimpleJob.java new file mode 100644 index 0000000000..370d698d13 --- /dev/null +++ b/libraries/src/main/java/com/baeldung/quartz/SimpleJob.java @@ -0,0 +1,13 @@ +package com.baeldung.quartz; + +import org.quartz.Job; +import org.quartz.JobExecutionContext; +import org.quartz.JobExecutionException; + +public class SimpleJob implements Job { + + public void execute(JobExecutionContext arg0) throws JobExecutionException { + System.out.println("This is a quartz job!"); + } + +} \ No newline at end of file diff --git a/libraries/src/test/java/com/baeldung/junitparams/SafeAdditionUtilTest.java b/libraries/src/test/java/com/baeldung/junitparams/SafeAdditionUtilTest.java new file mode 100644 index 0000000000..c9141a6e57 --- /dev/null +++ b/libraries/src/test/java/com/baeldung/junitparams/SafeAdditionUtilTest.java @@ -0,0 +1,55 @@ +package com.baeldung.junitparams; + +import static org.junit.Assert.*; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import junitparams.FileParameters; +import junitparams.JUnitParamsRunner; +import junitparams.Parameters; + +@RunWith(JUnitParamsRunner.class) +public class SafeAdditionUtilTest { + + private SafeAdditionUtil serviceUnderTest = new SafeAdditionUtil(); + + @Test + @Parameters({ "1, 2, 3", "-10, 30, 20", "15, -5, 10", "-5, -10, -15" }) + public void whenCalledWithAnnotationProvidedParams_thenSafeAddAndReturn(int a, int b, int expectedValue) { + assertEquals(expectedValue, serviceUnderTest.safeAdd(a, b)); + } + + @Test + @Parameters(method = "parametersToTestAdd") + public void whenCalledWithNamedMethod_thendSafeAddAndReturn(int a, int b, int expectedValue) { + assertEquals(expectedValue, serviceUnderTest.safeAdd(a, b)); + } + + private Object[] parametersToTestAdd() { + return new Object[] { new Object[] { 1, 2, 3 }, new Object[] { -10, 30, 20 }, new Object[] { Integer.MAX_VALUE, 2, Integer.MAX_VALUE }, new Object[] { Integer.MIN_VALUE, -8, Integer.MIN_VALUE } }; + } + + @Test + @Parameters + public void whenCalledWithnoParam_thenLoadByNameSafeAddAndReturn(int a, int b, int expectedValue) { + assertEquals(expectedValue, serviceUnderTest.safeAdd(a, b)); + } + + private Object[] parametersForWhenCalledWithnoParam_thenLoadByNameSafeAddAndReturn() { + return new Object[] { new Object[] { 1, 2, 3 }, new Object[] { -10, 30, 20 }, new Object[] { Integer.MAX_VALUE, 2, Integer.MAX_VALUE }, new Object[] { Integer.MIN_VALUE, -8, Integer.MIN_VALUE } }; + } + + @Test + @Parameters(source = TestDataProvider.class) + public void whenCalledWithNamedClass_thenSafeAddAndReturn(int a, int b, int expectedValue) { + assertEquals(expectedValue, serviceUnderTest.safeAdd(a, b)); + } + + @Test + @FileParameters("src/test/resources/JunitParamsTestParameters.csv") + public void whenCalledWithCsvFile_thenSafeAddAndReturn(int a, int b, int expectedValue) { + assertEquals(expectedValue, serviceUnderTest.safeAdd(a, b)); + } + +} diff --git a/libraries/src/test/java/com/baeldung/junitparams/TestDataProvider.java b/libraries/src/test/java/com/baeldung/junitparams/TestDataProvider.java new file mode 100644 index 0000000000..d318345a56 --- /dev/null +++ b/libraries/src/test/java/com/baeldung/junitparams/TestDataProvider.java @@ -0,0 +1,13 @@ +package com.baeldung.junitparams; + +public class TestDataProvider { + + public static Object[] provideBasicData() { + return new Object[] { new Object[] { 1, 2, 3 }, new Object[] { -10, 30, 20 }, new Object[] { 15, -5, 10 }, new Object[] { -5, -10, -15 } }; + } + + public static Object[] provideEdgeCaseData() { + return new Object[] { new Object[] { Integer.MAX_VALUE, 2, Integer.MAX_VALUE }, new Object[] { Integer.MIN_VALUE, -2, Integer.MIN_VALUE }, }; + } + +} diff --git a/libraries/src/test/resources/JunitParamsTestParameters.csv b/libraries/src/test/resources/JunitParamsTestParameters.csv new file mode 100644 index 0000000000..84eb5a0b23 --- /dev/null +++ b/libraries/src/test/resources/JunitParamsTestParameters.csv @@ -0,0 +1,4 @@ +1,2,3 +-10, 30, 20 +15, -5, 10 +-5, -10, -15 \ No newline at end of file diff --git a/mybatis/README.md b/mybatis/README.md new file mode 100644 index 0000000000..7c366aeab6 --- /dev/null +++ b/mybatis/README.md @@ -0,0 +1,2 @@ +### Relevant Articles: +- [Quick Guide to MyBatis](http://www.baeldung.com/mybatis) diff --git a/pom.xml b/pom.xml index d54ac5a2b8..d1b27bc9c9 100644 --- a/pom.xml +++ b/pom.xml @@ -121,7 +121,7 @@ selenium-junit-testng solr spark-java - spring-5 + spring-5 spring-akka spring-amqp spring-all diff --git a/spring-5/pom.xml b/spring-5/pom.xml index 63014d6e51..605dbe39e1 100644 --- a/spring-5/pom.xml +++ b/spring-5/pom.xml @@ -14,7 +14,7 @@ org.springframework.boot spring-boot-starter-parent - 2.0.0.BUILD-SNAPSHOT + 2.0.0.M1 diff --git a/spring-amqp-simple/README.md b/spring-amqp-simple/README.md new file mode 100644 index 0000000000..a176247d4c --- /dev/null +++ b/spring-amqp-simple/README.md @@ -0,0 +1,2 @@ +### Relevant Articles: +- [RabbitMQ Message Dispatching with Spring AMQP](http://www.baeldung.com/rabbitmq-spring-amqp) diff --git a/spring-boot-custom-starter/README.md b/spring-boot-custom-starter/README.md new file mode 100644 index 0000000000..5b05394d6e --- /dev/null +++ b/spring-boot-custom-starter/README.md @@ -0,0 +1,2 @@ +### Relevant Articles: +- [Creating a Custom Starter with Spring Boot](http://www.baeldung.com/spring-boot-custom-starter) diff --git a/spring-boot/README.MD b/spring-boot/README.MD index a1168106cb..4199b43e9a 100644 --- a/spring-boot/README.MD +++ b/spring-boot/README.MD @@ -21,3 +21,5 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring - [Custom Information in Spring Boot Info Endpoint](http://www.baeldung.com/spring-boot-info-actuator-custom) - [Using @JsonComponent in Spring Boot](http://www.baeldung.com/spring-boot-jsoncomponent) - [Create a Custom Auto-Configuration with Spring Boot](http://www.baeldung.com/spring-boot-custom-auto-configuration) +- [Testing in Spring Boot](http://www.baeldung.com/spring-boot-testing) +- [Guide to @ConfigurationProperties in Spring Boot](http://www.baeldung.com/configuration-properties-in-spring-boot) diff --git a/spring-cloud/README.md b/spring-cloud/README.md index 2ffb3a86d0..1b793144b1 100644 --- a/spring-cloud/README.md +++ b/spring-cloud/README.md @@ -18,3 +18,4 @@ ### Relevant Articles: - [Introduction to Spring Cloud Rest Client with Netflix Ribbon](http://www.baeldung.com/spring-cloud-rest-client-with-netflix-ribbon) + [An Introduction to Spring Cloud Zookeeper](http://www.baeldung.com/spring-cloud-zookeeper) diff --git a/spring-security-mvc-boot/README.MD b/spring-security-mvc-boot/README.MD index 70b0f23cbb..feda6efcd7 100644 --- a/spring-security-mvc-boot/README.MD +++ b/spring-security-mvc-boot/README.MD @@ -7,3 +7,4 @@ The "REST With Spring" Classes: http://github.learnspringsecurity.com - [Spring Security: Authentication with a Database-backed UserDetailsService](http://www.baeldung.com/spring-security-authentication-with-a-database) - [Two Login Pages with Spring Security](http://www.baeldung.com/spring-security-two-login-pages) - [Multiple Entry Points in Spring Security](http://www.baeldung.com/spring-security-multiple-entry-points) +- [Multiple Authentication Providers in Spring Security](http://www.baeldung.com/spring-security-multiple-auth-providers) diff --git a/testing/pom.xml b/testing/pom.xml index a0bc5b99cf..8c6898ac67 100644 --- a/testing/pom.xml +++ b/testing/pom.xml @@ -64,6 +64,12 @@ ${truth.version} test + + pl.pragmatists + JUnitParams + ${jUnitParams.version} + test + @@ -130,5 +136,6 @@ 3.1.0 3.6.1 0.32 + 1.1.0 diff --git a/testing/src/main/java/com/baeldung/junitparams/SafeAdditionUtil.java b/testing/src/main/java/com/baeldung/junitparams/SafeAdditionUtil.java new file mode 100644 index 0000000000..a2c1573dca --- /dev/null +++ b/testing/src/main/java/com/baeldung/junitparams/SafeAdditionUtil.java @@ -0,0 +1,15 @@ +package com.baeldung.junitparams; + +public class SafeAdditionUtil { + + public int safeAdd(int a, int b) { + long result = ((long) a) + b; + if (result > Integer.MAX_VALUE) { + return Integer.MAX_VALUE; + } else if (result < Integer.MIN_VALUE) { + return Integer.MIN_VALUE; + } + return (int) result; + } + +} diff --git a/testing/src/test/java/com/baeldung/junitparams/SafeAdditionUtilTest.java b/testing/src/test/java/com/baeldung/junitparams/SafeAdditionUtilTest.java new file mode 100644 index 0000000000..8ab49309cd --- /dev/null +++ b/testing/src/test/java/com/baeldung/junitparams/SafeAdditionUtilTest.java @@ -0,0 +1,54 @@ +package com.baeldung.junitparams; + +import static org.junit.Assert.assertEquals; + +import junitparams.FileParameters; +import junitparams.JUnitParamsRunner; +import junitparams.Parameters; +import org.junit.Test; +import org.junit.runner.RunWith; + +@RunWith(JUnitParamsRunner.class) +public class SafeAdditionUtilTest { + + private SafeAdditionUtil serviceUnderTest = new SafeAdditionUtil(); + + @Test + @Parameters({ "1, 2, 3", "-10, 30, 20", "15, -5, 10", "-5, -10, -15" }) + public void whenWithAnnotationProvidedParams_thenSafeAdd(int a, int b, int expectedValue) { + assertEquals(expectedValue, serviceUnderTest.safeAdd(a, b)); + } + + @Test + @Parameters(method = "parametersToTestAdd") + public void whenWithNamedMethod_thendSafeAdd(int a, int b, int expectedValue) { + assertEquals(expectedValue, serviceUnderTest.safeAdd(a, b)); + } + + private Object[] parametersToTestAdd() { + return new Object[] { new Object[] { 1, 2, 3 }, new Object[] { -10, 30, 20 }, new Object[] { Integer.MAX_VALUE, 2, Integer.MAX_VALUE }, new Object[] { Integer.MIN_VALUE, -8, Integer.MIN_VALUE } }; + } + + @Test + @Parameters + public void whenWithnoParam_thenLoadByNameSafeAdd(int a, int b, int expectedValue) { + assertEquals(expectedValue, serviceUnderTest.safeAdd(a, b)); + } + + private Object[] parametersForWhenWithnoParam_thenLoadByNameSafeAdd() { + return new Object[] { new Object[] { 1, 2, 3 }, new Object[] { -10, 30, 20 }, new Object[] { Integer.MAX_VALUE, 2, Integer.MAX_VALUE }, new Object[] { Integer.MIN_VALUE, -8, Integer.MIN_VALUE } }; + } + + @Test + @Parameters(source = TestDataProvider.class) + public void whenWithNamedClass_thenSafeAdd(int a, int b, int expectedValue) { + assertEquals(expectedValue, serviceUnderTest.safeAdd(a, b)); + } + + @Test + @FileParameters("src/test/resources/JunitParamsTestParameters.csv") + public void whenWithCsvFile_thenSafeAdd(int a, int b, int expectedValue) { + assertEquals(expectedValue, serviceUnderTest.safeAdd(a, b)); + } + +} diff --git a/testing/src/test/java/com/baeldung/junitparams/TestDataProvider.java b/testing/src/test/java/com/baeldung/junitparams/TestDataProvider.java new file mode 100644 index 0000000000..d318345a56 --- /dev/null +++ b/testing/src/test/java/com/baeldung/junitparams/TestDataProvider.java @@ -0,0 +1,13 @@ +package com.baeldung.junitparams; + +public class TestDataProvider { + + public static Object[] provideBasicData() { + return new Object[] { new Object[] { 1, 2, 3 }, new Object[] { -10, 30, 20 }, new Object[] { 15, -5, 10 }, new Object[] { -5, -10, -15 } }; + } + + public static Object[] provideEdgeCaseData() { + return new Object[] { new Object[] { Integer.MAX_VALUE, 2, Integer.MAX_VALUE }, new Object[] { Integer.MIN_VALUE, -2, Integer.MIN_VALUE }, }; + } + +} diff --git a/testing/src/test/resources/JunitParamsTestParameters.csv b/testing/src/test/resources/JunitParamsTestParameters.csv new file mode 100644 index 0000000000..84eb5a0b23 --- /dev/null +++ b/testing/src/test/resources/JunitParamsTestParameters.csv @@ -0,0 +1,4 @@ +1,2,3 +-10, 30, 20 +15, -5, 10 +-5, -10, -15 \ No newline at end of file