From 543c87fa7002f4bb4ebb953da5707884674cb680 Mon Sep 17 00:00:00 2001 From: Chris Oberle Date: Tue, 29 May 2018 09:35:09 -0400 Subject: [PATCH 01/15] initial import of source for BAEL-1786 --- core-java-8/pom.xml | 10 +++++ .../java/com/baeldung/reflect/Person.java | 42 +++++++++++++++++++ .../baeldung/reflect/MethodParamNameTest.java | 33 +++++++++++++++ 3 files changed, 85 insertions(+) create mode 100644 core-java-8/src/main/java/com/baeldung/reflect/Person.java create mode 100644 core-java-8/src/test/java/com/baeldung/reflect/MethodParamNameTest.java diff --git a/core-java-8/pom.xml b/core-java-8/pom.xml index aab349781a..20db1e1146 100644 --- a/core-java-8/pom.xml +++ b/core-java-8/pom.xml @@ -195,6 +195,16 @@ + + org.apache.maven.plugins + maven-compiler-plugin + 3.1 + + 1.8 + 1.8 + -parameters + + org.springframework.boot spring-boot-maven-plugin diff --git a/core-java-8/src/main/java/com/baeldung/reflect/Person.java b/core-java-8/src/main/java/com/baeldung/reflect/Person.java new file mode 100644 index 0000000000..b78536dc2c --- /dev/null +++ b/core-java-8/src/main/java/com/baeldung/reflect/Person.java @@ -0,0 +1,42 @@ +package com.baeldung.reflect; + +public class Person { + + private String firstName; + private String lastName; + private Integer age; + + public Person(String firstName, String lastName, Integer age) { + this.firstName = firstName; + this.lastName = lastName; + this.age = age; + } + + public Person() {} + + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + + public Integer getAge() { + return age; + } + + public void setAge(Integer age) { + this.age = age; + } + + +} diff --git a/core-java-8/src/test/java/com/baeldung/reflect/MethodParamNameTest.java b/core-java-8/src/test/java/com/baeldung/reflect/MethodParamNameTest.java new file mode 100644 index 0000000000..be72762c1d --- /dev/null +++ b/core-java-8/src/test/java/com/baeldung/reflect/MethodParamNameTest.java @@ -0,0 +1,33 @@ +package com.baeldung.reflect; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.lang.reflect.Parameter; +import java.util.Arrays; +import java.util.List; + +import static java.util.stream.Collectors.toList; +import org.junit.Test; + +public class MethodParamNameTest { + + @Test + public void whenGetConstructorParams_thenOk() throws NoSuchMethodException, SecurityException { + List parameters + = Arrays.asList( + Person.class.getConstructor(String.class, String.class, Integer.class) + .getParameters()); + List parameterNames + = parameters.stream().map(Parameter::getName).collect(toList()); + assertThat(parameterNames) + .containsExactlyInAnyOrder("lastName", "firstName", "age"); + } + + @Test + public void whenGetMethodParams_thenOk() throws NoSuchMethodException, SecurityException { + List parameters + = Arrays.asList( + Person.class.getMethod("setLastName", String.class).getParameters()); + assertThat(parameters.get(0).getName()).isEqualTo("lastName"); + } +} From d683b370f6e579b7873589093299e1769a21164d Mon Sep 17 00:00:00 2001 From: Chris Oberle Date: Wed, 30 May 2018 07:40:26 -0400 Subject: [PATCH 02/15] refactor example --- .../java/com/baeldung/reflect/Person.java | 38 ++++--------------- .../baeldung/reflect/MethodParamNameTest.java | 25 ++++++------ 2 files changed, 20 insertions(+), 43 deletions(-) diff --git a/core-java-8/src/main/java/com/baeldung/reflect/Person.java b/core-java-8/src/main/java/com/baeldung/reflect/Person.java index b78536dc2c..fba25aca8b 100644 --- a/core-java-8/src/main/java/com/baeldung/reflect/Person.java +++ b/core-java-8/src/main/java/com/baeldung/reflect/Person.java @@ -2,41 +2,17 @@ package com.baeldung.reflect; public class Person { - private String firstName; - private String lastName; - private Integer age; + private String fullName; - public Person(String firstName, String lastName, Integer age) { - this.firstName = firstName; - this.lastName = lastName; - this.age = age; + public Person(String fullName) { + this.fullName = fullName; } - public Person() {} - - public String getFirstName() { - return firstName; + public void setFullName(String fullName) { + this.fullName = fullName; } - public void setFirstName(String firstName) { - this.firstName = firstName; + public String getFullName() { + return fullName; } - - public String getLastName() { - return lastName; - } - - public void setLastName(String lastName) { - this.lastName = lastName; - } - - public Integer getAge() { - return age; - } - - public void setAge(Integer age) { - this.age = age; - } - - } diff --git a/core-java-8/src/test/java/com/baeldung/reflect/MethodParamNameTest.java b/core-java-8/src/test/java/com/baeldung/reflect/MethodParamNameTest.java index be72762c1d..46c833cfb1 100644 --- a/core-java-8/src/test/java/com/baeldung/reflect/MethodParamNameTest.java +++ b/core-java-8/src/test/java/com/baeldung/reflect/MethodParamNameTest.java @@ -5,29 +5,30 @@ import static org.assertj.core.api.Assertions.assertThat; import java.lang.reflect.Parameter; import java.util.Arrays; import java.util.List; +import java.util.Optional; -import static java.util.stream.Collectors.toList; import org.junit.Test; public class MethodParamNameTest { @Test - public void whenGetConstructorParams_thenOk() throws NoSuchMethodException, SecurityException { + public void whenGetConstructorParams_thenOk() + throws NoSuchMethodException, SecurityException { List parameters - = Arrays.asList( - Person.class.getConstructor(String.class, String.class, Integer.class) - .getParameters()); - List parameterNames - = parameters.stream().map(Parameter::getName).collect(toList()); - assertThat(parameterNames) - .containsExactlyInAnyOrder("lastName", "firstName", "age"); + = Arrays.asList(Person.class.getConstructor(String.class).getParameters()); + Optional parameter + = parameters.stream().filter(Parameter::isNamePresent).findFirst(); + assertThat(parameter.get().getName()).isEqualTo("fullName"); } @Test - public void whenGetMethodParams_thenOk() throws NoSuchMethodException, SecurityException { + public void whenGetMethodParams_thenOk() + throws NoSuchMethodException, SecurityException { List parameters = Arrays.asList( - Person.class.getMethod("setLastName", String.class).getParameters()); - assertThat(parameters.get(0).getName()).isEqualTo("lastName"); + Person.class.getMethod("setFullName", String.class).getParameters()); + Optional parameter + = parameters.stream().filter(Parameter::isNamePresent).findFirst(); + assertThat(parameter.get().getName()).isEqualTo("fullName"); } } From 722dec76cbfd2277e79043f8ca7b662bc43b8b57 Mon Sep 17 00:00:00 2001 From: araknoid Date: Wed, 30 May 2018 13:50:41 +0200 Subject: [PATCH 03/15] Add java.lang.Module API code --- .../java9/modules/ModuleAPIUnitTest.java | 199 ++++++++++++++++++ 1 file changed, 199 insertions(+) create mode 100644 core-java-9/src/test/java/com/baeldung/java9/modules/ModuleAPIUnitTest.java diff --git a/core-java-9/src/test/java/com/baeldung/java9/modules/ModuleAPIUnitTest.java b/core-java-9/src/test/java/com/baeldung/java9/modules/ModuleAPIUnitTest.java new file mode 100644 index 0000000000..aa2fb34753 --- /dev/null +++ b/core-java-9/src/test/java/com/baeldung/java9/modules/ModuleAPIUnitTest.java @@ -0,0 +1,199 @@ +package com.baeldung.java9.modules; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.nullValue; +import static org.hamcrest.Matchers.contains; +import static org.hamcrest.Matchers.containsInAnyOrder; +import static org.hamcrest.collection.IsEmptyCollection.empty; +import static org.junit.Assert.*; + +import java.lang.module.ModuleDescriptor; +import java.lang.module.ModuleDescriptor.*; +import java.sql.Date; +import java.sql.Driver; +import java.util.HashMap; +import java.util.Set; +import java.util.stream.Collectors; + +import org.junit.Before; +import org.junit.Test; + +public class ModuleAPIUnitTest { + + public static final String JAVA_BASE_MODULE_NAME = "java.base"; + + private Module javaBaseModule; + private Module javaSqlModule; + private Module module; + + @Before + public void setUp() { + Class hashMapClass = HashMap.class; + javaBaseModule = hashMapClass.getModule(); + + Class dateClass = Date.class; + javaSqlModule = dateClass.getModule(); + + Class personClass = Person.class; + module = personClass.getModule(); + } + + @Test + public void whenCheckingIfNamed_thenModuleIsNamed() { + assertThat(javaBaseModule.isNamed(), is(true)); + assertThat(javaBaseModule.getName(), is(JAVA_BASE_MODULE_NAME)); + } + + @Test + public void whenCheckingIfNamed_thenModuleIsUnnamed() { + assertThat(module.isNamed(), is(false)); + assertThat(module.getName(), is(nullValue())); + } + + @Test + public void whenExtractingPackagesContainedInAModule_thenModuleContainsOnlyFewOfThem() { + assertTrue(javaBaseModule.getPackages().contains("java.lang.annotation")); + assertFalse(javaBaseModule.getPackages().contains("java.sql")); + } + + @Test + public void whenRetrievingClassLoader_thenClassLoaderIsReturned() { + assertThat( + module.getClassLoader().getClass().getName(), + is("jdk.internal.loader.ClassLoaders$AppClassLoader") + ); + } + + @Test + public void whenGettingAnnotationsPresentOnAModule_thenNoAnnotationsArePresent() { + assertThat(javaBaseModule.getAnnotations().length, is(0)); + } + + @Test + public void whenGettingLayerOfAModule_thenModuleLayerInformationAreAvailable() { + ModuleLayer javaBaseModuleLayer = javaBaseModule.getLayer(); + + assertTrue(javaBaseModuleLayer.configuration().findModule(JAVA_BASE_MODULE_NAME).isPresent()); + assertThat(javaBaseModuleLayer.configuration().modules().size(), is(78)); + assertTrue(javaBaseModuleLayer.parents().get(0).configuration().parents().isEmpty()); + } + + @Test + public void whenRetrievingModuleDescriptor_thenTypeOfModuleIsInferred() { + ModuleDescriptor javaBaseModuleDescriptor = javaBaseModule.getDescriptor(); + ModuleDescriptor javaSqlModuleDescriptor = javaSqlModule.getDescriptor(); + + assertFalse(javaBaseModuleDescriptor.isAutomatic()); + assertFalse(javaBaseModuleDescriptor.isOpen()); + assertFalse(javaSqlModuleDescriptor.isAutomatic()); + assertFalse(javaSqlModuleDescriptor.isOpen()); + } + + @Test + public void givenModuleName_whenBuildingModuleDescriptor_thenBuilt() { + Builder moduleBuilder = ModuleDescriptor.newModule("baeldung.base"); + + ModuleDescriptor moduleDescriptor = moduleBuilder.build(); + + assertThat(moduleDescriptor.name(), is("baeldung.base")); + } + + @Test + public void givenModules_whenAccessingModuleDescriptorRequires_thenRequiresAreReturned() { + Set javaBaseRequires = javaBaseModule.getDescriptor().requires(); + Set javaSqlRequires = javaSqlModule.getDescriptor().requires(); + + Set javaSqlRequiresNames = javaSqlRequires.stream() + .map(Requires::name) + .collect(Collectors.toSet()); + + assertThat(javaBaseRequires, empty()); + assertThat(javaSqlRequires.size(), is(3)); + assertThat(javaSqlRequiresNames, containsInAnyOrder("java.base", "java.xml", "java.logging")); + } + + @Test + public void givenModules_whenAccessingModuleDescriptorProvides_thenProvidesAreReturned() { + Set javaBaseProvides = javaBaseModule.getDescriptor().provides(); + Set javaSqlProvides = javaSqlModule.getDescriptor().provides(); + + Set javaBaseProvidesService = javaBaseProvides.stream() + .map(Provides::service) + .collect(Collectors.toSet()); + + assertThat(javaBaseProvidesService, contains("java.nio.file.spi.FileSystemProvider")); + assertThat(javaSqlProvides, empty()); + } + + @Test + public void givenModules_whenAccessingModuleDescriptorExports_thenExportsAreReturned() { + Set javaBaseExports = javaBaseModule.getDescriptor().exports(); + Set javaSqlExports = javaSqlModule.getDescriptor().exports(); + + Set javaSqlExportsSource = javaSqlExports.stream() + .map(Exports::source) + .collect(Collectors.toSet()); + + assertThat(javaBaseExports.size(), is(108)); + assertThat(javaSqlExports.size(), is(3)); + assertThat(javaSqlExportsSource, containsInAnyOrder("java.sql", "javax.transaction.xa", "javax.sql")); + } + + @Test + public void givenModules_whenAccessingModuleDescriptorUses_thenUsesAreReturned() { + Set javaBaseUses = javaBaseModule.getDescriptor().uses(); + Set javaSqlUses = javaSqlModule.getDescriptor().uses(); + + assertThat(javaBaseUses.size(), is(34)); + assertThat(javaSqlUses, contains("java.sql.Driver")); + } + + @Test + public void givenModules_whenAccessingModuleDescriptorOpen_thenOpenAreReturned() { + Set javaBaseUses = javaBaseModule.getDescriptor().opens(); + Set javaSqlUses = javaSqlModule.getDescriptor().opens(); + + assertThat(javaBaseUses, empty()); + assertThat(javaSqlUses, empty()); + } + + @Test + public void whenAddingReadsToAModule_thenModuleCanReadNewModule() { + Module updatedModule = module.addReads(javaSqlModule); + + assertTrue(updatedModule.canRead(javaSqlModule)); + } + + @Test + public void whenExportingPackage_thenPackageIsExported() { + Module updatedModule = module.addExports("com.baeldung.java9.modules", javaSqlModule); + + assertTrue(updatedModule.isExported("com.baeldung.java9.modules")); + } + + @Test + public void whenOpeningAModulePackage_thenPackagedIsOpened() { + Module updatedModule = module.addOpens("com.baeldung.java9.modules", javaSqlModule); + + assertTrue(updatedModule.isOpen("com.baeldung.java9.modules", javaSqlModule)); + } + + @Test + public void whenAddingUsesToModule_thenUsesIsAdded() { + Module updatedModule = module.addUses(Driver.class); + + assertTrue(updatedModule.canUse(Driver.class)); + } + + private class Person { + private String name; + + public Person(String name) { + this.name = name; + } + + public String getName() { + return name; + } + } +} From a673f2d809b25faa4797b9856b1912c00b1b261e Mon Sep 17 00:00:00 2001 From: Loredana Crusoveanu Date: Sat, 2 Jun 2018 23:14:27 +0300 Subject: [PATCH 04/15] fix package name --- .../baeldung/annotation/CascadeSave.java | 2 +- .../{org => com}/baeldung/config/MongoConfig.java | 12 ++++++------ .../baeldung/config/SimpleMongoConfig.java | 4 ++-- .../baeldung/converter/UserWriterConverter.java | 4 ++-- .../{org => com}/baeldung/event/CascadeCallback.java | 4 ++-- .../event/CascadeSaveMongoEventListener.java | 2 +- .../{org => com}/baeldung/event/FieldCallback.java | 2 +- .../event/UserCascadeSaveMongoEventListener.java | 4 ++-- .../{org => com}/baeldung/model/EmailAddress.java | 2 +- .../main/java/{org => com}/baeldung/model/User.java | 4 ++-- .../baeldung/repository/UserRepository.java | 4 ++-- .../aggregation/ZipsAggregationLiveTest.java | 6 +++--- .../baeldung/aggregation/model/StatePopulation.java | 2 +- .../{org => com}/baeldung/gridfs/GridFSLiveTest.java | 2 +- .../mongotemplate/DocumentQueryLiveTest.java | 8 ++++---- .../MongoTemplateProjectionLiveTest.java | 6 +++--- .../mongotemplate/MongoTemplateQueryLiveTest.java | 8 ++++---- .../baeldung/repository/BaseQueryLiveTest.java | 6 +++--- .../baeldung/repository/DSLQueryLiveTest.java | 8 ++++---- .../baeldung/repository/JSONQueryLiveTest.java | 6 +++--- .../baeldung/repository/QueryMethodsLiveTest.java | 6 +++--- .../baeldung/repository/UserRepositoryLiveTest.java | 6 +++--- .../repository/UserRepositoryProjectionLiveTest.java | 6 +++--- 23 files changed, 57 insertions(+), 57 deletions(-) rename spring-data-mongodb/src/main/java/{org => com}/baeldung/annotation/CascadeSave.java (88%) rename spring-data-mongodb/src/main/java/{org => com}/baeldung/config/MongoConfig.java (84%) rename spring-data-mongodb/src/main/java/{org => com}/baeldung/config/SimpleMongoConfig.java (86%) rename spring-data-mongodb/src/main/java/{org => com}/baeldung/converter/UserWriterConverter.java (92%) rename spring-data-mongodb/src/main/java/{org => com}/baeldung/event/CascadeCallback.java (95%) rename spring-data-mongodb/src/main/java/{org => com}/baeldung/event/CascadeSaveMongoEventListener.java (96%) rename spring-data-mongodb/src/main/java/{org => com}/baeldung/event/FieldCallback.java (95%) rename spring-data-mongodb/src/main/java/{org => com}/baeldung/event/UserCascadeSaveMongoEventListener.java (92%) rename spring-data-mongodb/src/main/java/{org => com}/baeldung/model/EmailAddress.java (94%) rename spring-data-mongodb/src/main/java/{org => com}/baeldung/model/User.java (96%) rename spring-data-mongodb/src/main/java/{org => com}/baeldung/repository/UserRepository.java (94%) rename spring-data-mongodb/src/test/java/{org => com}/baeldung/aggregation/ZipsAggregationLiveTest.java (97%) rename spring-data-mongodb/src/test/java/{org => com}/baeldung/aggregation/model/StatePopulation.java (95%) rename spring-data-mongodb/src/test/java/{org => com}/baeldung/gridfs/GridFSLiveTest.java (99%) rename spring-data-mongodb/src/test/java/{org => com}/baeldung/mongotemplate/DocumentQueryLiveTest.java (97%) rename spring-data-mongodb/src/test/java/{org => com}/baeldung/mongotemplate/MongoTemplateProjectionLiveTest.java (94%) rename spring-data-mongodb/src/test/java/{org => com}/baeldung/mongotemplate/MongoTemplateQueryLiveTest.java (97%) rename spring-data-mongodb/src/test/java/{org => com}/baeldung/repository/BaseQueryLiveTest.java (83%) rename spring-data-mongodb/src/test/java/{org => com}/baeldung/repository/DSLQueryLiveTest.java (95%) rename spring-data-mongodb/src/test/java/{org => com}/baeldung/repository/JSONQueryLiveTest.java (96%) rename spring-data-mongodb/src/test/java/{org => com}/baeldung/repository/QueryMethodsLiveTest.java (96%) rename spring-data-mongodb/src/test/java/{org => com}/baeldung/repository/UserRepositoryLiveTest.java (97%) rename spring-data-mongodb/src/test/java/{org => com}/baeldung/repository/UserRepositoryProjectionLiveTest.java (93%) diff --git a/spring-data-mongodb/src/main/java/org/baeldung/annotation/CascadeSave.java b/spring-data-mongodb/src/main/java/com/baeldung/annotation/CascadeSave.java similarity index 88% rename from spring-data-mongodb/src/main/java/org/baeldung/annotation/CascadeSave.java rename to spring-data-mongodb/src/main/java/com/baeldung/annotation/CascadeSave.java index aae0214d09..3e43221aff 100644 --- a/spring-data-mongodb/src/main/java/org/baeldung/annotation/CascadeSave.java +++ b/spring-data-mongodb/src/main/java/com/baeldung/annotation/CascadeSave.java @@ -1,4 +1,4 @@ -package org.baeldung.annotation; +package com.baeldung.annotation; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; diff --git a/spring-data-mongodb/src/main/java/org/baeldung/config/MongoConfig.java b/spring-data-mongodb/src/main/java/com/baeldung/config/MongoConfig.java similarity index 84% rename from spring-data-mongodb/src/main/java/org/baeldung/config/MongoConfig.java rename to spring-data-mongodb/src/main/java/com/baeldung/config/MongoConfig.java index 80b177f4c9..551a9142a6 100644 --- a/spring-data-mongodb/src/main/java/org/baeldung/config/MongoConfig.java +++ b/spring-data-mongodb/src/main/java/com/baeldung/config/MongoConfig.java @@ -1,10 +1,10 @@ -package org.baeldung.config; +package com.baeldung.config; import com.mongodb.Mongo; import com.mongodb.MongoClient; -import org.baeldung.converter.UserWriterConverter; -import org.baeldung.event.CascadeSaveMongoEventListener; -import org.baeldung.event.UserCascadeSaveMongoEventListener; +import com.baeldung.converter.UserWriterConverter; +import com.baeldung.event.CascadeSaveMongoEventListener; +import com.baeldung.event.UserCascadeSaveMongoEventListener; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.convert.converter.Converter; @@ -17,7 +17,7 @@ import java.util.ArrayList; import java.util.List; @Configuration -@EnableMongoRepositories(basePackages = "org.baeldung.repository") +@EnableMongoRepositories(basePackages = "com.baeldung.repository") public class MongoConfig extends AbstractMongoConfiguration { private final List> converters = new ArrayList>(); @@ -34,7 +34,7 @@ public class MongoConfig extends AbstractMongoConfiguration { @Override public String getMappingBasePackage() { - return "org.baeldung"; + return "com.baeldung"; } @Bean diff --git a/spring-data-mongodb/src/main/java/org/baeldung/config/SimpleMongoConfig.java b/spring-data-mongodb/src/main/java/com/baeldung/config/SimpleMongoConfig.java similarity index 86% rename from spring-data-mongodb/src/main/java/org/baeldung/config/SimpleMongoConfig.java rename to spring-data-mongodb/src/main/java/com/baeldung/config/SimpleMongoConfig.java index 9653796d8d..95f192811f 100644 --- a/spring-data-mongodb/src/main/java/org/baeldung/config/SimpleMongoConfig.java +++ b/spring-data-mongodb/src/main/java/com/baeldung/config/SimpleMongoConfig.java @@ -1,4 +1,4 @@ -package org.baeldung.config; +package com.baeldung.config; import com.mongodb.Mongo; import com.mongodb.MongoClient; @@ -8,7 +8,7 @@ import org.springframework.data.mongodb.core.MongoTemplate; import org.springframework.data.mongodb.repository.config.EnableMongoRepositories; @Configuration -@EnableMongoRepositories(basePackages = "org.baeldung.repository") +@EnableMongoRepositories(basePackages = "com.baeldung.repository") public class SimpleMongoConfig { @Bean diff --git a/spring-data-mongodb/src/main/java/org/baeldung/converter/UserWriterConverter.java b/spring-data-mongodb/src/main/java/com/baeldung/converter/UserWriterConverter.java similarity index 92% rename from spring-data-mongodb/src/main/java/org/baeldung/converter/UserWriterConverter.java rename to spring-data-mongodb/src/main/java/com/baeldung/converter/UserWriterConverter.java index 4a6970489e..542ebb2c85 100644 --- a/spring-data-mongodb/src/main/java/org/baeldung/converter/UserWriterConverter.java +++ b/spring-data-mongodb/src/main/java/com/baeldung/converter/UserWriterConverter.java @@ -1,8 +1,8 @@ -package org.baeldung.converter; +package com.baeldung.converter; import com.mongodb.BasicDBObject; import com.mongodb.DBObject; -import org.baeldung.model.User; +import com.baeldung.model.User; import org.springframework.core.convert.converter.Converter; import org.springframework.stereotype.Component; diff --git a/spring-data-mongodb/src/main/java/org/baeldung/event/CascadeCallback.java b/spring-data-mongodb/src/main/java/com/baeldung/event/CascadeCallback.java similarity index 95% rename from spring-data-mongodb/src/main/java/org/baeldung/event/CascadeCallback.java rename to spring-data-mongodb/src/main/java/com/baeldung/event/CascadeCallback.java index 94cad4566a..6ce5747793 100644 --- a/spring-data-mongodb/src/main/java/org/baeldung/event/CascadeCallback.java +++ b/spring-data-mongodb/src/main/java/com/baeldung/event/CascadeCallback.java @@ -1,8 +1,8 @@ -package org.baeldung.event; +package com.baeldung.event; import java.lang.reflect.Field; -import org.baeldung.annotation.CascadeSave; +import com.baeldung.annotation.CascadeSave; import org.springframework.data.mongodb.core.MongoOperations; import org.springframework.data.mongodb.core.mapping.DBRef; import org.springframework.util.ReflectionUtils; diff --git a/spring-data-mongodb/src/main/java/org/baeldung/event/CascadeSaveMongoEventListener.java b/spring-data-mongodb/src/main/java/com/baeldung/event/CascadeSaveMongoEventListener.java similarity index 96% rename from spring-data-mongodb/src/main/java/org/baeldung/event/CascadeSaveMongoEventListener.java rename to spring-data-mongodb/src/main/java/com/baeldung/event/CascadeSaveMongoEventListener.java index acc377011d..499e727a90 100644 --- a/spring-data-mongodb/src/main/java/org/baeldung/event/CascadeSaveMongoEventListener.java +++ b/spring-data-mongodb/src/main/java/com/baeldung/event/CascadeSaveMongoEventListener.java @@ -1,4 +1,4 @@ -package org.baeldung.event; +package com.baeldung.event; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.mongodb.core.MongoOperations; diff --git a/spring-data-mongodb/src/main/java/org/baeldung/event/FieldCallback.java b/spring-data-mongodb/src/main/java/com/baeldung/event/FieldCallback.java similarity index 95% rename from spring-data-mongodb/src/main/java/org/baeldung/event/FieldCallback.java rename to spring-data-mongodb/src/main/java/com/baeldung/event/FieldCallback.java index c6bd90d4f3..5e478270c1 100644 --- a/spring-data-mongodb/src/main/java/org/baeldung/event/FieldCallback.java +++ b/spring-data-mongodb/src/main/java/com/baeldung/event/FieldCallback.java @@ -1,4 +1,4 @@ -package org.baeldung.event; +package com.baeldung.event; import java.lang.reflect.Field; diff --git a/spring-data-mongodb/src/main/java/org/baeldung/event/UserCascadeSaveMongoEventListener.java b/spring-data-mongodb/src/main/java/com/baeldung/event/UserCascadeSaveMongoEventListener.java similarity index 92% rename from spring-data-mongodb/src/main/java/org/baeldung/event/UserCascadeSaveMongoEventListener.java rename to spring-data-mongodb/src/main/java/com/baeldung/event/UserCascadeSaveMongoEventListener.java index ade20bcc1d..832e3563f9 100644 --- a/spring-data-mongodb/src/main/java/org/baeldung/event/UserCascadeSaveMongoEventListener.java +++ b/spring-data-mongodb/src/main/java/com/baeldung/event/UserCascadeSaveMongoEventListener.java @@ -1,6 +1,6 @@ -package org.baeldung.event; +package com.baeldung.event; -import org.baeldung.model.User; +import com.baeldung.model.User; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.mongodb.core.MongoOperations; import org.springframework.data.mongodb.core.mapping.event.AbstractMongoEventListener; diff --git a/spring-data-mongodb/src/main/java/org/baeldung/model/EmailAddress.java b/spring-data-mongodb/src/main/java/com/baeldung/model/EmailAddress.java similarity index 94% rename from spring-data-mongodb/src/main/java/org/baeldung/model/EmailAddress.java rename to spring-data-mongodb/src/main/java/com/baeldung/model/EmailAddress.java index 6db7d160d7..13fe340f69 100644 --- a/spring-data-mongodb/src/main/java/org/baeldung/model/EmailAddress.java +++ b/spring-data-mongodb/src/main/java/com/baeldung/model/EmailAddress.java @@ -1,4 +1,4 @@ -package org.baeldung.model; +package com.baeldung.model; import org.springframework.data.annotation.Id; import org.springframework.data.mongodb.core.mapping.Document; diff --git a/spring-data-mongodb/src/main/java/org/baeldung/model/User.java b/spring-data-mongodb/src/main/java/com/baeldung/model/User.java similarity index 96% rename from spring-data-mongodb/src/main/java/org/baeldung/model/User.java rename to spring-data-mongodb/src/main/java/com/baeldung/model/User.java index 9b8c47a58f..1bbe49ee1d 100644 --- a/spring-data-mongodb/src/main/java/org/baeldung/model/User.java +++ b/spring-data-mongodb/src/main/java/com/baeldung/model/User.java @@ -1,6 +1,6 @@ -package org.baeldung.model; +package com.baeldung.model; -import org.baeldung.annotation.CascadeSave; +import com.baeldung.annotation.CascadeSave; import org.springframework.beans.factory.annotation.Value; import org.springframework.data.annotation.Id; import org.springframework.data.annotation.PersistenceConstructor; diff --git a/spring-data-mongodb/src/main/java/org/baeldung/repository/UserRepository.java b/spring-data-mongodb/src/main/java/com/baeldung/repository/UserRepository.java similarity index 94% rename from spring-data-mongodb/src/main/java/org/baeldung/repository/UserRepository.java rename to spring-data-mongodb/src/main/java/com/baeldung/repository/UserRepository.java index 8e442e8b7f..e9dc0f5c95 100644 --- a/spring-data-mongodb/src/main/java/org/baeldung/repository/UserRepository.java +++ b/spring-data-mongodb/src/main/java/com/baeldung/repository/UserRepository.java @@ -1,6 +1,6 @@ -package org.baeldung.repository; +package com.baeldung.repository; -import org.baeldung.model.User; +import com.baeldung.model.User; import org.springframework.data.mongodb.repository.MongoRepository; import org.springframework.data.mongodb.repository.Query; import org.springframework.data.querydsl.QueryDslPredicateExecutor; diff --git a/spring-data-mongodb/src/test/java/org/baeldung/aggregation/ZipsAggregationLiveTest.java b/spring-data-mongodb/src/test/java/com/baeldung/aggregation/ZipsAggregationLiveTest.java similarity index 97% rename from spring-data-mongodb/src/test/java/org/baeldung/aggregation/ZipsAggregationLiveTest.java rename to spring-data-mongodb/src/test/java/com/baeldung/aggregation/ZipsAggregationLiveTest.java index 5686465c19..a4bea45fcf 100644 --- a/spring-data-mongodb/src/test/java/org/baeldung/aggregation/ZipsAggregationLiveTest.java +++ b/spring-data-mongodb/src/test/java/com/baeldung/aggregation/ZipsAggregationLiveTest.java @@ -1,12 +1,12 @@ -package org.baeldung.aggregation; +package com.baeldung.aggregation; import com.mongodb.DB; import com.mongodb.DBCollection; import com.mongodb.DBObject; import com.mongodb.MongoClient; import com.mongodb.util.JSON; -import org.baeldung.aggregation.model.StatePopulation; -import org.baeldung.config.MongoConfig; +import com.baeldung.aggregation.model.StatePopulation; +import com.baeldung.config.MongoConfig; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; diff --git a/spring-data-mongodb/src/test/java/org/baeldung/aggregation/model/StatePopulation.java b/spring-data-mongodb/src/test/java/com/baeldung/aggregation/model/StatePopulation.java similarity index 95% rename from spring-data-mongodb/src/test/java/org/baeldung/aggregation/model/StatePopulation.java rename to spring-data-mongodb/src/test/java/com/baeldung/aggregation/model/StatePopulation.java index 6a3cd0d426..be77783439 100644 --- a/spring-data-mongodb/src/test/java/org/baeldung/aggregation/model/StatePopulation.java +++ b/spring-data-mongodb/src/test/java/com/baeldung/aggregation/model/StatePopulation.java @@ -1,4 +1,4 @@ -package org.baeldung.aggregation.model; +package com.baeldung.aggregation.model; import org.springframework.data.annotation.Id; diff --git a/spring-data-mongodb/src/test/java/org/baeldung/gridfs/GridFSLiveTest.java b/spring-data-mongodb/src/test/java/com/baeldung/gridfs/GridFSLiveTest.java similarity index 99% rename from spring-data-mongodb/src/test/java/org/baeldung/gridfs/GridFSLiveTest.java rename to spring-data-mongodb/src/test/java/com/baeldung/gridfs/GridFSLiveTest.java index 88205ba7fd..02485e8517 100644 --- a/spring-data-mongodb/src/test/java/org/baeldung/gridfs/GridFSLiveTest.java +++ b/spring-data-mongodb/src/test/java/com/baeldung/gridfs/GridFSLiveTest.java @@ -1,4 +1,4 @@ -package org.baeldung.gridfs; +package com.baeldung.gridfs; import com.mongodb.BasicDBObject; import com.mongodb.DBObject; diff --git a/spring-data-mongodb/src/test/java/org/baeldung/mongotemplate/DocumentQueryLiveTest.java b/spring-data-mongodb/src/test/java/com/baeldung/mongotemplate/DocumentQueryLiveTest.java similarity index 97% rename from spring-data-mongodb/src/test/java/org/baeldung/mongotemplate/DocumentQueryLiveTest.java rename to spring-data-mongodb/src/test/java/com/baeldung/mongotemplate/DocumentQueryLiveTest.java index 729b0f6dfa..7a61f9f98a 100644 --- a/spring-data-mongodb/src/test/java/org/baeldung/mongotemplate/DocumentQueryLiveTest.java +++ b/spring-data-mongodb/src/test/java/com/baeldung/mongotemplate/DocumentQueryLiveTest.java @@ -1,8 +1,8 @@ -package org.baeldung.mongotemplate; +package com.baeldung.mongotemplate; -import org.baeldung.config.MongoConfig; -import org.baeldung.model.EmailAddress; -import org.baeldung.model.User; +import com.baeldung.config.MongoConfig; +import com.baeldung.model.EmailAddress; +import com.baeldung.model.User; import org.junit.After; import org.junit.Before; import org.junit.Test; diff --git a/spring-data-mongodb/src/test/java/org/baeldung/mongotemplate/MongoTemplateProjectionLiveTest.java b/spring-data-mongodb/src/test/java/com/baeldung/mongotemplate/MongoTemplateProjectionLiveTest.java similarity index 94% rename from spring-data-mongodb/src/test/java/org/baeldung/mongotemplate/MongoTemplateProjectionLiveTest.java rename to spring-data-mongodb/src/test/java/com/baeldung/mongotemplate/MongoTemplateProjectionLiveTest.java index 2d2117afbb..309f14e995 100644 --- a/spring-data-mongodb/src/test/java/org/baeldung/mongotemplate/MongoTemplateProjectionLiveTest.java +++ b/spring-data-mongodb/src/test/java/com/baeldung/mongotemplate/MongoTemplateProjectionLiveTest.java @@ -1,7 +1,7 @@ -package org.baeldung.mongotemplate; +package com.baeldung.mongotemplate; -import org.baeldung.config.SimpleMongoConfig; -import org.baeldung.model.User; +import com.baeldung.config.SimpleMongoConfig; +import com.baeldung.model.User; import org.junit.After; import org.junit.Before; import org.junit.Test; diff --git a/spring-data-mongodb/src/test/java/org/baeldung/mongotemplate/MongoTemplateQueryLiveTest.java b/spring-data-mongodb/src/test/java/com/baeldung/mongotemplate/MongoTemplateQueryLiveTest.java similarity index 97% rename from spring-data-mongodb/src/test/java/org/baeldung/mongotemplate/MongoTemplateQueryLiveTest.java rename to spring-data-mongodb/src/test/java/com/baeldung/mongotemplate/MongoTemplateQueryLiveTest.java index b7ce0cafae..ee1d4f4760 100644 --- a/spring-data-mongodb/src/test/java/org/baeldung/mongotemplate/MongoTemplateQueryLiveTest.java +++ b/spring-data-mongodb/src/test/java/com/baeldung/mongotemplate/MongoTemplateQueryLiveTest.java @@ -1,8 +1,8 @@ -package org.baeldung.mongotemplate; +package com.baeldung.mongotemplate; -import org.baeldung.config.MongoConfig; -import org.baeldung.model.EmailAddress; -import org.baeldung.model.User; +import com.baeldung.config.MongoConfig; +import com.baeldung.model.EmailAddress; +import com.baeldung.model.User; import org.junit.After; import org.junit.Before; import org.junit.Test; diff --git a/spring-data-mongodb/src/test/java/org/baeldung/repository/BaseQueryLiveTest.java b/spring-data-mongodb/src/test/java/com/baeldung/repository/BaseQueryLiveTest.java similarity index 83% rename from spring-data-mongodb/src/test/java/org/baeldung/repository/BaseQueryLiveTest.java rename to spring-data-mongodb/src/test/java/com/baeldung/repository/BaseQueryLiveTest.java index afd7259c6c..e4849181e5 100644 --- a/spring-data-mongodb/src/test/java/org/baeldung/repository/BaseQueryLiveTest.java +++ b/spring-data-mongodb/src/test/java/com/baeldung/repository/BaseQueryLiveTest.java @@ -1,7 +1,7 @@ -package org.baeldung.repository; +package com.baeldung.repository; -import org.baeldung.model.User; -import org.baeldung.repository.UserRepository; +import com.baeldung.model.User; +import com.baeldung.repository.UserRepository; import org.junit.After; import org.junit.Before; import org.springframework.beans.factory.annotation.Autowired; diff --git a/spring-data-mongodb/src/test/java/org/baeldung/repository/DSLQueryLiveTest.java b/spring-data-mongodb/src/test/java/com/baeldung/repository/DSLQueryLiveTest.java similarity index 95% rename from spring-data-mongodb/src/test/java/org/baeldung/repository/DSLQueryLiveTest.java rename to spring-data-mongodb/src/test/java/com/baeldung/repository/DSLQueryLiveTest.java index 5924dea9fe..f87ca5cbb5 100644 --- a/spring-data-mongodb/src/test/java/org/baeldung/repository/DSLQueryLiveTest.java +++ b/spring-data-mongodb/src/test/java/com/baeldung/repository/DSLQueryLiveTest.java @@ -1,13 +1,13 @@ -package org.baeldung.repository; +package com.baeldung.repository; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertThat; import java.util.List; -import org.baeldung.config.MongoConfig; -import org.baeldung.model.QUser; -import org.baeldung.model.User; +import com.baeldung.config.MongoConfig; +import com.baeldung.model.QUser; +import com.baeldung.model.User; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.test.context.ContextConfiguration; diff --git a/spring-data-mongodb/src/test/java/org/baeldung/repository/JSONQueryLiveTest.java b/spring-data-mongodb/src/test/java/com/baeldung/repository/JSONQueryLiveTest.java similarity index 96% rename from spring-data-mongodb/src/test/java/org/baeldung/repository/JSONQueryLiveTest.java rename to spring-data-mongodb/src/test/java/com/baeldung/repository/JSONQueryLiveTest.java index 9464a4eb52..4e99c0b140 100644 --- a/spring-data-mongodb/src/test/java/org/baeldung/repository/JSONQueryLiveTest.java +++ b/spring-data-mongodb/src/test/java/com/baeldung/repository/JSONQueryLiveTest.java @@ -1,12 +1,12 @@ -package org.baeldung.repository; +package com.baeldung.repository; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertThat; import java.util.List; -import org.baeldung.config.MongoConfig; -import org.baeldung.model.User; +import com.baeldung.config.MongoConfig; +import com.baeldung.model.User; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.test.context.ContextConfiguration; diff --git a/spring-data-mongodb/src/test/java/org/baeldung/repository/QueryMethodsLiveTest.java b/spring-data-mongodb/src/test/java/com/baeldung/repository/QueryMethodsLiveTest.java similarity index 96% rename from spring-data-mongodb/src/test/java/org/baeldung/repository/QueryMethodsLiveTest.java rename to spring-data-mongodb/src/test/java/com/baeldung/repository/QueryMethodsLiveTest.java index 5705c119b8..47e67a6b4c 100644 --- a/spring-data-mongodb/src/test/java/org/baeldung/repository/QueryMethodsLiveTest.java +++ b/spring-data-mongodb/src/test/java/com/baeldung/repository/QueryMethodsLiveTest.java @@ -1,12 +1,12 @@ -package org.baeldung.repository; +package com.baeldung.repository; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertThat; import java.util.List; -import org.baeldung.config.MongoConfig; -import org.baeldung.model.User; +import com.baeldung.config.MongoConfig; +import com.baeldung.model.User; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.test.context.ContextConfiguration; diff --git a/spring-data-mongodb/src/test/java/org/baeldung/repository/UserRepositoryLiveTest.java b/spring-data-mongodb/src/test/java/com/baeldung/repository/UserRepositoryLiveTest.java similarity index 97% rename from spring-data-mongodb/src/test/java/org/baeldung/repository/UserRepositoryLiveTest.java rename to spring-data-mongodb/src/test/java/com/baeldung/repository/UserRepositoryLiveTest.java index 1543b847ba..da4e91baec 100644 --- a/spring-data-mongodb/src/test/java/org/baeldung/repository/UserRepositoryLiveTest.java +++ b/spring-data-mongodb/src/test/java/com/baeldung/repository/UserRepositoryLiveTest.java @@ -1,12 +1,12 @@ -package org.baeldung.repository; +package com.baeldung.repository; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertThat; import java.util.List; -import org.baeldung.config.MongoConfig; -import org.baeldung.model.User; +import com.baeldung.config.MongoConfig; +import com.baeldung.model.User; import org.junit.After; import org.junit.Before; import org.junit.Test; diff --git a/spring-data-mongodb/src/test/java/org/baeldung/repository/UserRepositoryProjectionLiveTest.java b/spring-data-mongodb/src/test/java/com/baeldung/repository/UserRepositoryProjectionLiveTest.java similarity index 93% rename from spring-data-mongodb/src/test/java/org/baeldung/repository/UserRepositoryProjectionLiveTest.java rename to spring-data-mongodb/src/test/java/com/baeldung/repository/UserRepositoryProjectionLiveTest.java index 5436896f08..80f4275794 100644 --- a/spring-data-mongodb/src/test/java/org/baeldung/repository/UserRepositoryProjectionLiveTest.java +++ b/spring-data-mongodb/src/test/java/com/baeldung/repository/UserRepositoryProjectionLiveTest.java @@ -1,9 +1,9 @@ -package org.baeldung.repository; +package com.baeldung.repository; import static org.junit.Assert.*; -import org.baeldung.config.MongoConfig; -import org.baeldung.model.User; +import com.baeldung.config.MongoConfig; +import com.baeldung.model.User; import org.junit.After; import org.junit.Before; import org.junit.Test; From 3f9cf77272e56b784f9adc71b2a6bf86fa2d6aab Mon Sep 17 00:00:00 2001 From: Seun Matt Date: Sun, 3 Jun 2018 06:13:07 +0100 Subject: [PATCH 05/15] Example Code for BAEL-1425 (#4394) * added example code for Java mail * added examp code for BAEL-1425 * updated example code for BAEL-1425 --- core-java/pom.xml | 5 ++ libraries/pom.xml | 13 +++ .../com/baeldung/commons/math3/Histogram.java | 90 +++++++++++++++++++ 3 files changed, 108 insertions(+) create mode 100644 libraries/src/main/java/com/baeldung/commons/math3/Histogram.java diff --git a/core-java/pom.xml b/core-java/pom.xml index 88fae5edea..f7a2139d99 100644 --- a/core-java/pom.xml +++ b/core-java/pom.xml @@ -198,6 +198,11 @@ mail ${javax.mail.version} + + javax.mail + mail + 1.5.0-b01 + diff --git a/libraries/pom.xml b/libraries/pom.xml index 678ba3279c..4f90d63d93 100644 --- a/libraries/pom.xml +++ b/libraries/pom.xml @@ -698,6 +698,17 @@ jctools-core ${jctools.version} + + + org.apache.commons + commons-math3 + ${common-math3-version} + + + org.knowm.xchart + xchart + ${xchart-version} + @@ -910,6 +921,8 @@ 0.9.4.0006L 2.1.2 2.5.11 + 3.6.1 + 3.5.2 \ No newline at end of file diff --git a/libraries/src/main/java/com/baeldung/commons/math3/Histogram.java b/libraries/src/main/java/com/baeldung/commons/math3/Histogram.java new file mode 100644 index 0000000000..63cc4514c0 --- /dev/null +++ b/libraries/src/main/java/com/baeldung/commons/math3/Histogram.java @@ -0,0 +1,90 @@ +package com.baeldung.commons.math3; + +import org.apache.commons.math3.stat.Frequency; +import org.knowm.xchart.CategoryChart; +import org.knowm.xchart.CategoryChartBuilder; +import org.knowm.xchart.SwingWrapper; +import org.knowm.xchart.style.Styler; + +import java.util.*; + +public class Histogram { + + public Histogram() { + + Map distributionMap = processRawData(); + List yData = new ArrayList(); + yData.addAll(distributionMap.values()); + List xData = Arrays.asList(distributionMap.keySet().toArray()); + + CategoryChart chart = buildChart(xData, yData); + new SwingWrapper<>(chart).displayChart(); + + } + + private CategoryChart buildChart(List xData, List yData) { + + // Create Chart + CategoryChart chart = new CategoryChartBuilder().width(800).height(600) + .title("Age Distribution") + .xAxisTitle("Age Group") + .yAxisTitle("Frequency") + .build(); + + chart.getStyler().setLegendPosition(Styler.LegendPosition.InsideNW); + chart.getStyler().setAvailableSpaceFill(0.99); + chart.getStyler().setOverlapped(true); + + chart.addSeries("age group", xData, yData); + + return chart; + } + + private Map processRawData() { + + List datasetList = Arrays.asList(36, 25, 38, 46, 55, 68, 72, 55, 36, 38, 67, 45, 22, 48, 91, 46, 52, 61, 58, 55); + Frequency frequency = new Frequency(); + datasetList.forEach(d -> frequency.addValue(Double.parseDouble(d.toString()))); + + int classWidth = 10; + + Map distributionMap = new TreeMap(); + List processed = new ArrayList(); + datasetList.forEach(d -> { + + double observation = Double.parseDouble(d.toString()); + + if(processed.contains(observation)) + return; + + long observationFrequency = frequency.getCount(observation); + int upperBoundary = (observation > classWidth) ? Math.multiplyExact( (int) Math.ceil(observation / classWidth), classWidth) : classWidth; + int lowerBoundary = (upperBoundary > classWidth) ? Math.subtractExact(upperBoundary, classWidth) : 0; + String bin = lowerBoundary + "-" + upperBoundary; + + int prevUpperBoundary = lowerBoundary; + int prevLowerBoundary = (lowerBoundary > classWidth) ? lowerBoundary - classWidth : 0; + String prevBin = prevLowerBoundary + "-" + prevUpperBoundary; + if(!distributionMap.containsKey(prevBin)) + distributionMap.put(prevBin, 0); + + if(!distributionMap.containsKey(bin)) { + distributionMap.put(bin, observationFrequency); + } + else { + long oldFrequency = Long.parseLong(distributionMap.get(bin).toString()); + distributionMap.replace(bin, oldFrequency + observationFrequency); + } + + processed.add(observation); + + }); + + return distributionMap; + } + + public static void main(String[] args) { + new Histogram(); + } + +} From c7b2aded99c6e212c2b9b2b624873ba4fd4e4a46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bruno=20Mattos=20Torr=C3=A3o?= Date: Sun, 3 Jun 2018 03:47:42 -0300 Subject: [PATCH 06/15] BAEL-1325 - Spring Data Reactive Repositories with MongoDB (#4373) * refactor: use StepVerifier * refactor: use test observer --- spring-5-reactive/pom.xml | 7 ++++ .../AccountCrudRepositoryIntegrationTest.java | 37 ++++++++++++++----- ...AccountMongoRepositoryIntegrationTest.java | 35 ++++++++++++------ ...ccountRxJavaRepositoryIntegrationTest.java | 35 +++++++++++++----- 4 files changed, 84 insertions(+), 30 deletions(-) diff --git a/spring-5-reactive/pom.xml b/spring-5-reactive/pom.xml index 9c317e9966..8b40ccee00 100644 --- a/spring-5-reactive/pom.xml +++ b/spring-5-reactive/pom.xml @@ -141,6 +141,12 @@ rxjava ${rxjava-version} + + io.projectreactor + reactor-test + ${project-reactor-test} + test + @@ -185,6 +191,7 @@ 1.0 1.0 4.1 + 3.1.6.RELEASE diff --git a/spring-5-reactive/src/test/java/com/baeldung/reactive/repository/AccountCrudRepositoryIntegrationTest.java b/spring-5-reactive/src/test/java/com/baeldung/reactive/repository/AccountCrudRepositoryIntegrationTest.java index 86f995ed79..f425826dce 100644 --- a/spring-5-reactive/src/test/java/com/baeldung/reactive/repository/AccountCrudRepositoryIntegrationTest.java +++ b/spring-5-reactive/src/test/java/com/baeldung/reactive/repository/AccountCrudRepositoryIntegrationTest.java @@ -10,6 +10,7 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; +import reactor.test.StepVerifier; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; @@ -25,26 +26,44 @@ public class AccountCrudRepositoryIntegrationTest { public void givenValue_whenFindAllByValue_thenFindAccount() { repository.save(new Account(null, "Bill", 12.3)).block(); Flux accountFlux = repository.findAllByValue(12.3); - Account account = accountFlux.next().block(); - assertEquals("Bill", account.getOwner()); - assertEquals(Double.valueOf(12.3) , account.getValue()); - assertNotNull(account.getId()); + + StepVerifier.create(accountFlux) + .assertNext(account -> { + assertEquals("Bill", account.getOwner()); + assertEquals(Double.valueOf(12.3) , account.getValue()); + assertNotNull(account.getId()); + }) + .expectComplete() + .verify(); } @Test public void givenOwner_whenFindFirstByOwner_thenFindAccount() { repository.save(new Account(null, "Bill", 12.3)).block(); Mono accountMono = repository.findFirstByOwner(Mono.just("Bill")); - Account account = accountMono.block(); - assertEquals("Bill", account.getOwner()); - assertEquals(Double.valueOf(12.3) , account.getValue()); - assertNotNull(account.getId()); + + StepVerifier.create(accountMono) + .assertNext(account -> { + assertEquals("Bill", account.getOwner()); + assertEquals(Double.valueOf(12.3) , account.getValue()); + assertNotNull(account.getId()); + }) + .expectComplete() + .verify(); + + + } @Test public void givenAccount_whenSave_thenSaveAccount() { Mono accountMono = repository.save(new Account(null, "Bill", 12.3)); - assertNotNull(accountMono.block().getId()); + + StepVerifier + .create(accountMono) + .assertNext(account -> assertNotNull(account.getId())) + .expectComplete() + .verify(); } diff --git a/spring-5-reactive/src/test/java/com/baeldung/reactive/repository/AccountMongoRepositoryIntegrationTest.java b/spring-5-reactive/src/test/java/com/baeldung/reactive/repository/AccountMongoRepositoryIntegrationTest.java index f95c443b7f..bfa6a789b2 100644 --- a/spring-5-reactive/src/test/java/com/baeldung/reactive/repository/AccountMongoRepositoryIntegrationTest.java +++ b/spring-5-reactive/src/test/java/com/baeldung/reactive/repository/AccountMongoRepositoryIntegrationTest.java @@ -2,8 +2,6 @@ package com.baeldung.reactive.repository; import com.baeldung.reactive.Spring5ReactiveApplication; import com.baeldung.reactive.model.Account; -import org.junit.After; -import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; @@ -13,10 +11,10 @@ import org.springframework.data.domain.ExampleMatcher; import org.springframework.test.context.junit4.SpringRunner; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; +import reactor.test.StepVerifier; -import java.util.List; - -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; import static org.springframework.data.domain.ExampleMatcher.GenericPropertyMatchers.startsWith; @RunWith(SpringRunner.class) @@ -32,23 +30,38 @@ public class AccountMongoRepositoryIntegrationTest { ExampleMatcher matcher = ExampleMatcher.matching().withMatcher("owner", startsWith()); Example example = Example.of(new Account(null, "jo", null), matcher); Flux accountFlux = repository.findAll(example); - List accounts = accountFlux.collectList().block(); - assertTrue(accounts.stream().anyMatch(x -> x.getOwner().equals("john"))); + StepVerifier + .create(accountFlux) + .assertNext(account -> assertEquals("john", account.getOwner())) + .expectComplete() + .verify(); } @Test public void givenAccount_whenSave_thenSave() { Mono accountMono = repository.save(new Account(null, "john", 12.3)); - assertNotNull(accountMono.block().getId()); + + StepVerifier + .create(accountMono) + .assertNext(account -> assertNotNull(account.getId())) + .expectComplete() + .verify(); } @Test public void givenId_whenFindById_thenFindAccount() { Account inserted = repository.save(new Account(null, "john", 12.3)).block(); Mono accountMono = repository.findById(inserted.getId()); - assertEquals("john", accountMono.block().getOwner()); - assertEquals(Double.valueOf(12.3), accountMono.block().getValue()); - assertNotNull(accountMono.block().getId()); + + StepVerifier + .create(accountMono) + .assertNext(account -> { + assertEquals("john", account.getOwner()); + assertEquals(Double.valueOf(12.3), account.getValue()); + assertNotNull(account.getId()); + }) + .expectComplete() + .verify(); } } \ No newline at end of file diff --git a/spring-5-reactive/src/test/java/com/baeldung/reactive/repository/AccountRxJavaRepositoryIntegrationTest.java b/spring-5-reactive/src/test/java/com/baeldung/reactive/repository/AccountRxJavaRepositoryIntegrationTest.java index 6199b460d0..e9b3eb1c40 100644 --- a/spring-5-reactive/src/test/java/com/baeldung/reactive/repository/AccountRxJavaRepositoryIntegrationTest.java +++ b/spring-5-reactive/src/test/java/com/baeldung/reactive/repository/AccountRxJavaRepositoryIntegrationTest.java @@ -21,23 +21,38 @@ public class AccountRxJavaRepositoryIntegrationTest { AccountRxJavaRepository repository; @Test - public void givenValue_whenFindAllByValue_thenFindAccounts() { + public void givenValue_whenFindAllByValue_thenFindAccounts() throws InterruptedException { repository.save(new Account(null, "bruno", 12.3)).blockingGet(); Observable accountObservable = repository.findAllByValue(12.3); - Account account = accountObservable.filter(x -> x.getOwner().equals("bruno")).blockingFirst(); - assertEquals("bruno", account.getOwner()); - assertEquals(Double.valueOf(12.3), account.getValue()); - assertNotNull(account.getId()); + + accountObservable + .test() + .await() + .assertComplete() + .assertValueAt(0, account -> { + assertEquals("bruno", account.getOwner()); + assertEquals(Double.valueOf(12.3), account.getValue()); + return true; + }); + } @Test - public void givenOwner_whenFindFirstByOwner_thenFindAccount() { + public void givenOwner_whenFindFirstByOwner_thenFindAccount() throws InterruptedException { repository.save(new Account(null, "bruno", 12.3)).blockingGet(); Single accountSingle = repository.findFirstByOwner(Single.just("bruno")); - Account account = accountSingle.blockingGet(); - assertEquals("bruno", account.getOwner()); - assertEquals(Double.valueOf(12.3), account.getValue()); - assertNotNull(account.getId()); + + accountSingle + .test() + .await() + .assertComplete() + .assertValueAt(0, account -> { + assertEquals("bruno", account.getOwner()); + assertEquals(Double.valueOf(12.3), account.getValue()); + assertNotNull(account.getId()); + return true; + }); + } } \ No newline at end of file From 642bff3077f7d4721879941e07aa5cabda6c93b2 Mon Sep 17 00:00:00 2001 From: Shubhra Date: Sun, 3 Jun 2018 17:22:10 +0530 Subject: [PATCH 07/15] BAEL-1761 Jagged Arrays In Java --- .../java/com/baeldung/array/JaggedArray.java | 49 +++++++++++++++++ .../com/baeldung/array/JaggedArrayTest.java | 53 +++++++++++++++++++ 2 files changed, 102 insertions(+) create mode 100644 core-java/src/main/java/com/baeldung/array/JaggedArray.java create mode 100644 core-java/src/test/java/com/baeldung/array/JaggedArrayTest.java diff --git a/core-java/src/main/java/com/baeldung/array/JaggedArray.java b/core-java/src/main/java/com/baeldung/array/JaggedArray.java new file mode 100644 index 0000000000..36cfc88b95 --- /dev/null +++ b/core-java/src/main/java/com/baeldung/array/JaggedArray.java @@ -0,0 +1,49 @@ +package com.baeldung.array; + +import java.util.Arrays; +import java.util.Scanner; + +public class JaggedArray { + + int[][] shortHandFormInitialization() { + int[][] jaggedArr = { { 1, 2 }, { 3, 4, 5 }, { 6, 7, 8, 9 } }; + return jaggedArr; + } + + int[][] declarationAndThenInitialization() { + int[][] jaggedArr = new int[3][]; + jaggedArr[0] = new int[] { 1, 2 }; + jaggedArr[1] = new int[] { 3, 4, 5 }; + jaggedArr[2] = new int[] { 6, 7, 8, 9 }; + return jaggedArr; + } + + int[][] declarationAndThenInitializationUsingUserInputs() { + int[][] jaggedArr = new int[3][]; + jaggedArr[0] = new int[2]; + jaggedArr[1] = new int[3]; + jaggedArr[2] = new int[4]; + initializeElements(jaggedArr); + return jaggedArr; + } + + void initializeElements(int[][] jaggedArr) { + Scanner sc = new Scanner(System.in); + for (int outer = 0; outer < jaggedArr.length; outer++) { + for (int inner = 0; inner < jaggedArr[outer].length; inner++) { + jaggedArr[outer][inner] = sc.nextInt(); + } + } + } + + void printElements(int[][] jaggedArr) { + for (int index = 0; index < jaggedArr.length; index++) { + System.out.println(Arrays.toString(jaggedArr[index])); + } + } + + int[] getElementAtGivenIndex(int[][] jaggedArr, int index) { + return jaggedArr[index]; + } + +} diff --git a/core-java/src/test/java/com/baeldung/array/JaggedArrayTest.java b/core-java/src/test/java/com/baeldung/array/JaggedArrayTest.java new file mode 100644 index 0000000000..b67dfc9600 --- /dev/null +++ b/core-java/src/test/java/com/baeldung/array/JaggedArrayTest.java @@ -0,0 +1,53 @@ +package com.baeldung.array; + +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.InputStream; +import java.io.PrintStream; + +import org.junit.Test; + +public class JaggedArrayTest { + + private JaggedArray obj = new JaggedArray(); + + @Test + public void whenInitializedUsingShortHandForm_thenCorrect() { + assertArrayEquals(new int[][] { { 1, 2 }, { 3, 4, 5 }, { 6, 7, 8, 9 } }, obj.shortHandFormInitialization()); + } + + @Test + public void whenInitializedWithDeclarationAndThenInitalization_thenCorrect() { + assertArrayEquals(new int[][] { { 1, 2 }, { 3, 4, 5 }, { 6, 7, 8, 9 } }, obj.declarationAndThenInitialization()); + } + + @Test + public void whenInitializedWithDeclarationAndThenInitalizationUsingUserInputs_thenCorrect() { + InputStream is = new ByteArrayInputStream("1 2 3 4 5 6 7 8 9".getBytes()); + System.setIn(is); + assertArrayEquals(new int[][] { { 1, 2 }, { 3, 4, 5 }, { 6, 7, 8, 9 } }, obj.declarationAndThenInitializationUsingUserInputs()); + System.setIn(System.in); + } + + @Test + public void givenJaggedArrayAndAnIndex_thenReturnArrayAtGivenIndex() { + int[][] jaggedArr = { { 1, 2 }, { 3, 4, 5 }, { 6, 7, 8, 9 } }; + assertArrayEquals(new int[] { 1, 2 }, obj.getElementAtGivenIndex(jaggedArr, 0)); + assertArrayEquals(new int[] { 3, 4, 5 }, obj.getElementAtGivenIndex(jaggedArr, 1)); + assertArrayEquals(new int[] { 6, 7, 8, 9 }, obj.getElementAtGivenIndex(jaggedArr, 2)); + } + + @Test + public void givenJaggedArray_whenUsingArraysAPI_thenVerifyPrintedElements() { + int[][] jaggedArr = { { 1, 2 }, { 3, 4, 5 }, { 6, 7, 8, 9 } }; + ByteArrayOutputStream outContent = new ByteArrayOutputStream(); + System.setOut(new PrintStream(outContent)); + obj.printElements(jaggedArr); + assertEquals("[1, 2]\n[3, 4, 5]\n[6, 7, 8, 9]\n", outContent.toString()); + System.setOut(System.out); + } + +} From 5ef5e539e40f9ef0e222f3511342de9e20dab7fe Mon Sep 17 00:00:00 2001 From: Seun Matt Date: Sun, 3 Jun 2018 22:56:14 +0100 Subject: [PATCH 08/15] Update to BAEL-1425 (#4399) * added example code for Java mail * added examp code for BAEL-1425 * updated example code for BAEL-1425 * updated example code for BAEL-1425 --- .../com/baeldung/commons/math3/Histogram.java | 55 ++++++++++--------- 1 file changed, 30 insertions(+), 25 deletions(-) diff --git a/libraries/src/main/java/com/baeldung/commons/math3/Histogram.java b/libraries/src/main/java/com/baeldung/commons/math3/Histogram.java index 63cc4514c0..5b4097b1e4 100644 --- a/libraries/src/main/java/com/baeldung/commons/math3/Histogram.java +++ b/libraries/src/main/java/com/baeldung/commons/math3/Histogram.java @@ -10,8 +10,13 @@ import java.util.*; public class Histogram { + private Map distributionMap; + private int classWidth; + public Histogram() { + distributionMap = new TreeMap(); + classWidth = 10; Map distributionMap = processRawData(); List yData = new ArrayList(); yData.addAll(distributionMap.values()); @@ -46,43 +51,43 @@ public class Histogram { Frequency frequency = new Frequency(); datasetList.forEach(d -> frequency.addValue(Double.parseDouble(d.toString()))); - int classWidth = 10; - - Map distributionMap = new TreeMap(); List processed = new ArrayList(); datasetList.forEach(d -> { + double observation = Double.parseDouble(d.toString()); - double observation = Double.parseDouble(d.toString()); + if(processed.contains(observation)) + return; - if(processed.contains(observation)) - return; + long observationFrequency = frequency.getCount(observation); + int upperBoundary = (observation > classWidth) ? Math.multiplyExact( (int) Math.ceil(observation / classWidth), classWidth) : classWidth; + int lowerBoundary = (upperBoundary > classWidth) ? Math.subtractExact(upperBoundary, classWidth) : 0; + String bin = lowerBoundary + "-" + upperBoundary; - long observationFrequency = frequency.getCount(observation); - int upperBoundary = (observation > classWidth) ? Math.multiplyExact( (int) Math.ceil(observation / classWidth), classWidth) : classWidth; - int lowerBoundary = (upperBoundary > classWidth) ? Math.subtractExact(upperBoundary, classWidth) : 0; - String bin = lowerBoundary + "-" + upperBoundary; + updateDistributionMap(lowerBoundary, bin, observationFrequency); - int prevUpperBoundary = lowerBoundary; - int prevLowerBoundary = (lowerBoundary > classWidth) ? lowerBoundary - classWidth : 0; - String prevBin = prevLowerBoundary + "-" + prevUpperBoundary; - if(!distributionMap.containsKey(prevBin)) - distributionMap.put(prevBin, 0); - - if(!distributionMap.containsKey(bin)) { - distributionMap.put(bin, observationFrequency); - } - else { - long oldFrequency = Long.parseLong(distributionMap.get(bin).toString()); - distributionMap.replace(bin, oldFrequency + observationFrequency); - } - - processed.add(observation); + processed.add(observation); }); return distributionMap; } + private void updateDistributionMap(int lowerBoundary, String bin, long observationFrequency) { + + int prevLowerBoundary = (lowerBoundary > classWidth) ? lowerBoundary - classWidth : 0; + String prevBin = prevLowerBoundary + "-" + lowerBoundary; + if(!distributionMap.containsKey(prevBin)) + distributionMap.put(prevBin, 0); + + if(!distributionMap.containsKey(bin)) { + distributionMap.put(bin, observationFrequency); + } + else { + long oldFrequency = Long.parseLong(distributionMap.get(bin).toString()); + distributionMap.replace(bin, oldFrequency + observationFrequency); + } + } + public static void main(String[] args) { new Histogram(); } From 39b0b845cf7fa319dcdee99569c2e05f4704a218 Mon Sep 17 00:00:00 2001 From: Binod Pant Date: Mon, 4 Jun 2018 12:38:30 -0400 Subject: [PATCH 09/15] BAEL-1527 (#4398) * commit first as binodpanta * revert test change * A short example of real-time event streaming using Spring WebFlux * Code for http://jira.baeldung.com/browse/BAEL-1527 * remove unrelated files * Apply feedback changes to rename test and remove link from readme file, ongoing work * Update formatting fixes to code and add pom changes, that partially fix test runnning issues in IDE but not in cmdline * Apply Eclipse formatter to test code and apply suggested pom fixes * BAEL-1527 Formatting fix in pom.xml * Use string.format to cleanup logging code * BAEL-1527 Changed logging pattern --- .../baeldung/extensions/RegisterExtensionSampleExtension.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/testing-modules/junit-5/src/test/java/com/baeldung/extensions/RegisterExtensionSampleExtension.java b/testing-modules/junit-5/src/test/java/com/baeldung/extensions/RegisterExtensionSampleExtension.java index c20731cfe6..64f4d8fd3e 100644 --- a/testing-modules/junit-5/src/test/java/com/baeldung/extensions/RegisterExtensionSampleExtension.java +++ b/testing-modules/junit-5/src/test/java/com/baeldung/extensions/RegisterExtensionSampleExtension.java @@ -20,12 +20,12 @@ public class RegisterExtensionSampleExtension implements BeforeAllCallback, Befo @Override public void beforeAll(ExtensionContext extensionContext) throws Exception { - logger.info("Type " + type + " In beforeAll : " + extensionContext.getDisplayName()); + logger.info("Type {} In beforeAll : {}", type, extensionContext.getDisplayName()); } @Override public void beforeEach(ExtensionContext extensionContext) throws Exception { - logger.info("Type " + type + " In beforeEach : " + extensionContext.getDisplayName()); + logger.info("Type {} In beforeEach : {}", type, extensionContext.getDisplayName()); } public String getType() { From 11fa0cf492f34d6c240ac2c2e8b02e7cc999da5a Mon Sep 17 00:00:00 2001 From: pivovarit Date: Tue, 5 Jun 2018 10:03:20 +0200 Subject: [PATCH 10/15] Disable PMD aggregate --- .../array/{JaggedArrayTest.java => JaggedArrayUnitTest.java} | 2 +- pom.xml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) rename core-java/src/test/java/com/baeldung/array/{JaggedArrayTest.java => JaggedArrayUnitTest.java} (98%) diff --git a/core-java/src/test/java/com/baeldung/array/JaggedArrayTest.java b/core-java/src/test/java/com/baeldung/array/JaggedArrayUnitTest.java similarity index 98% rename from core-java/src/test/java/com/baeldung/array/JaggedArrayTest.java rename to core-java/src/test/java/com/baeldung/array/JaggedArrayUnitTest.java index b67dfc9600..f432436190 100644 --- a/core-java/src/test/java/com/baeldung/array/JaggedArrayTest.java +++ b/core-java/src/test/java/com/baeldung/array/JaggedArrayUnitTest.java @@ -10,7 +10,7 @@ import java.io.PrintStream; import org.junit.Test; -public class JaggedArrayTest { +public class JaggedArrayUnitTest { private JaggedArray obj = new JaggedArray(); diff --git a/pom.xml b/pom.xml index 92d93e8df7..b9fde81102 100644 --- a/pom.xml +++ b/pom.xml @@ -373,8 +373,8 @@ - 5 - true + 5 + false true true true From 2e683411e223c67c26ffb50385d78d8bebfe965a Mon Sep 17 00:00:00 2001 From: Amit Pandey Date: Tue, 5 Jun 2018 17:05:55 +0530 Subject: [PATCH 11/15] Bael 4461 2 (#4409) * Deleted md file as a conflict * [BAEL-4461] - Fixed PMD violation * [BAEL-4461] - Fixed PMD violation * [BAEL-4461] - Ignore empty TC * Fix Spring 5 tests --- ...t.java => CayenneAdvancedOperationLiveTest.java} | 2 +- ...ationTest.java => CayenneOperationLiveTest.java} | 2 +- ...ts.java => AzureApplicationIntegrationTest.java} | 2 +- ...amNameTest.java => MethodParamNameUnitTest.java} | 2 +- .../java/com/baeldung/file/FilesManualTest.java | 2 +- .../baeldung/java/io/JavaReadFromFileUnitTest.java | 2 +- ...Test.java => FlipControllerIntegrationTest.java} | 2 +- ...ceTest.java => TodoMustacheServiceUnitTest.java} | 2 +- ...Test.java => FlipControllerIntegrationTest.java} | 2 +- .../com/baeldung/persistence/FooRepository.java | 3 +-- .../main/java/com/baeldung/web/FooController.java | 6 ++++++ .../java/com/baeldung/Example1IntegrationTest.java | 2 ++ .../java/com/baeldung/Example2IntegrationTest.java | 2 ++ .../baeldung/Spring5ApplicationIntegrationTest.java | 2 ++ .../functional/BeanRegistrationIntegrationTest.java | 2 ++ .../jdbc/autogenkey/GetAutoGenKeyByJDBC.java | 2 ++ .../com/baeldung/jsonb/JsonbIntegrationTest.java | 12 +++++------- .../baeldung/security/SecurityIntegrationTest.java | 2 ++ .../web/client/WebTestClientIntegrationTest.java | 2 ++ ...=> PassParametersControllerIntegrationTest.java} | 2 +- ...ctionalTest.java => ITransactionalUnitTest.java} | 4 ++-- .../TransactionalIntegrationTest.java | 2 +- spring-boot-ops/README.MD | 13 ------------- spring-boot-ops/README.md | 12 ------------ ...ubernetesBackendApplicationIntegrationTest.java} | 2 +- ...bernetesFrontendApplicationIntegrationTest.java} | 2 +- ...lerTest.java => AuthorEventHandlerUnitTest.java} | 2 +- ...ndlerTest.java => BookEventHandlerUnitTest.java} | 2 +- ...ava => SimpleBookControllerIntegrationTest.java} | 2 +- ...=> SimpleBookRestControllerIntegrationTest.java} | 2 +- .../{ConfigTest.java => ConfigIntegrationTest.java} | 4 ++-- .../baeldung/web/FooDiscoverabilityLiveTest.java | 4 ++-- .../src/test/java/org/baeldung/web/FooLiveTest.java | 4 ++-- .../java/org/baeldung/web/FooPageableLiveTest.java | 4 ++-- ...ditorTest.java => CreditCardEditorUnitTest.java} | 2 +- ...ecurityThymeleafApplicationIntegrationTest.java} | 2 +- .../future/{FutureTest.java => FutureUnitTest.java} | 2 +- 37 files changed, 56 insertions(+), 64 deletions(-) rename apache-cayenne/src/test/java/com/baeldung/apachecayenne/{CayenneAdvancedOperationIntegrationTest.java => CayenneAdvancedOperationLiveTest.java} (99%) rename apache-cayenne/src/test/java/com/baeldung/apachecayenne/{CayenneOperationIntegrationTest.java => CayenneOperationLiveTest.java} (98%) rename azure/src/test/java/com/baeldung/springboot/azure/{AzureApplicationTests.java => AzureApplicationIntegrationTest.java} (86%) rename core-java-8/src/test/java/com/baeldung/reflect/{MethodParamNameTest.java => MethodParamNameUnitTest.java} (93%) rename flips/src/test/java/com/baeldung/flips/controller/{FlipControllerTest.java => FlipControllerIntegrationTest.java} (98%) rename mustache/src/test/java/com/baeldung/mustache/{TodoMustacheServiceTest.java => TodoMustacheServiceUnitTest.java} (98%) rename spring-4/src/test/java/com/baeldung/flips/controller/{FlipControllerTest.java => FlipControllerIntegrationTest.java} (98%) rename spring-all/src/test/java/org/baeldung/controller/{PassParametersControllerTest.java => PassParametersControllerIntegrationTest.java} (97%) rename spring-all/src/test/java/org/baeldung/spring43/defaultmethods/{ITransactionalTest.java => ITransactionalUnitTest.java} (80%) delete mode 100644 spring-boot-ops/README.MD delete mode 100644 spring-boot-ops/README.md rename spring-cloud/spring-cloud-kubernetes/demo-backend/src/test/java/com/baeldung/spring/cloud/kubernetes/backend/{KubernetesBackendApplicationTests.java => KubernetesBackendApplicationIntegrationTest.java} (84%) rename spring-cloud/spring-cloud-kubernetes/demo-frontend/src/test/java/com/baeldung/spring/cloud/kubernetes/frontend/{KubernetesFrontendApplicationTests.java => KubernetesFrontendApplicationIntegrationTest.java} (84%) rename spring-data-rest/src/test/java/com/baeldung/events/{AuthorEventHandlerTest.java => AuthorEventHandlerUnitTest.java} (95%) rename spring-data-rest/src/test/java/com/baeldung/events/{BookEventHandlerTest.java => BookEventHandlerUnitTest.java} (95%) rename spring-mvc-java/src/test/java/com/baeldung/web/controller/{SimpleBookControllerTest.java => SimpleBookControllerIntegrationTest.java} (95%) rename spring-mvc-java/src/test/java/com/baeldung/web/controller/{SimpleBookRestControllerTest.java => SimpleBookRestControllerIntegrationTest.java} (95%) rename spring-rest-full/src/test/java/org/baeldung/spring/{ConfigTest.java => ConfigIntegrationTest.java} (75%) rename spring-rest/src/test/java/com/baeldung/propertyeditor/creditcard/{CreditCardEditorTest.java => CreditCardEditorUnitTest.java} (97%) rename spring-security-thymeleaf/src/test/java/com/baeldung/springsecuritythymeleaf/{SpringSecurityThymeleafApplicationTests.java => SpringSecurityThymeleafApplicationIntegrationTest.java} (90%) rename vavr/src/test/java/com/baeldung/vavr/future/{FutureTest.java => FutureUnitTest.java} (99%) diff --git a/apache-cayenne/src/test/java/com/baeldung/apachecayenne/CayenneAdvancedOperationIntegrationTest.java b/apache-cayenne/src/test/java/com/baeldung/apachecayenne/CayenneAdvancedOperationLiveTest.java similarity index 99% rename from apache-cayenne/src/test/java/com/baeldung/apachecayenne/CayenneAdvancedOperationIntegrationTest.java rename to apache-cayenne/src/test/java/com/baeldung/apachecayenne/CayenneAdvancedOperationLiveTest.java index 546b8fe45c..b54b62ca02 100644 --- a/apache-cayenne/src/test/java/com/baeldung/apachecayenne/CayenneAdvancedOperationIntegrationTest.java +++ b/apache-cayenne/src/test/java/com/baeldung/apachecayenne/CayenneAdvancedOperationLiveTest.java @@ -19,7 +19,7 @@ import java.util.List; import static junit.framework.Assert.assertEquals; import static org.junit.Assert.assertNotNull; -public class CayenneAdvancedOperationIntegrationTest { +public class CayenneAdvancedOperationLiveTest { private static ObjectContext context = null; @BeforeClass diff --git a/apache-cayenne/src/test/java/com/baeldung/apachecayenne/CayenneOperationIntegrationTest.java b/apache-cayenne/src/test/java/com/baeldung/apachecayenne/CayenneOperationLiveTest.java similarity index 98% rename from apache-cayenne/src/test/java/com/baeldung/apachecayenne/CayenneOperationIntegrationTest.java rename to apache-cayenne/src/test/java/com/baeldung/apachecayenne/CayenneOperationLiveTest.java index 85f06d5538..e6ca4a3634 100644 --- a/apache-cayenne/src/test/java/com/baeldung/apachecayenne/CayenneOperationIntegrationTest.java +++ b/apache-cayenne/src/test/java/com/baeldung/apachecayenne/CayenneOperationLiveTest.java @@ -16,7 +16,7 @@ import static junit.framework.Assert.assertEquals; import static org.junit.Assert.assertNull; -public class CayenneOperationIntegrationTest { +public class CayenneOperationLiveTest { private static ObjectContext context = null; @BeforeClass diff --git a/azure/src/test/java/com/baeldung/springboot/azure/AzureApplicationTests.java b/azure/src/test/java/com/baeldung/springboot/azure/AzureApplicationIntegrationTest.java similarity index 86% rename from azure/src/test/java/com/baeldung/springboot/azure/AzureApplicationTests.java rename to azure/src/test/java/com/baeldung/springboot/azure/AzureApplicationIntegrationTest.java index 91632be11a..7c3084446f 100644 --- a/azure/src/test/java/com/baeldung/springboot/azure/AzureApplicationTests.java +++ b/azure/src/test/java/com/baeldung/springboot/azure/AzureApplicationIntegrationTest.java @@ -7,7 +7,7 @@ import org.springframework.test.context.junit4.SpringRunner; @RunWith(SpringRunner.class) @SpringBootTest -public class AzureApplicationTests { +public class AzureApplicationIntegrationTest { @Test public void contextLoads() { diff --git a/core-java-8/src/test/java/com/baeldung/reflect/MethodParamNameTest.java b/core-java-8/src/test/java/com/baeldung/reflect/MethodParamNameUnitTest.java similarity index 93% rename from core-java-8/src/test/java/com/baeldung/reflect/MethodParamNameTest.java rename to core-java-8/src/test/java/com/baeldung/reflect/MethodParamNameUnitTest.java index 46c833cfb1..b191c94826 100644 --- a/core-java-8/src/test/java/com/baeldung/reflect/MethodParamNameTest.java +++ b/core-java-8/src/test/java/com/baeldung/reflect/MethodParamNameUnitTest.java @@ -9,7 +9,7 @@ import java.util.Optional; import org.junit.Test; -public class MethodParamNameTest { +public class MethodParamNameUnitTest { @Test public void whenGetConstructorParams_thenOk() diff --git a/core-java-io/src/test/java/com/baeldung/file/FilesManualTest.java b/core-java-io/src/test/java/com/baeldung/file/FilesManualTest.java index 8322106c24..f5c5c3dd3a 100644 --- a/core-java-io/src/test/java/com/baeldung/file/FilesManualTest.java +++ b/core-java-io/src/test/java/com/baeldung/file/FilesManualTest.java @@ -77,6 +77,6 @@ public class FilesManualTest { bw.newLine(); bw.close(); - assertThat(StreamUtils.getStringFromInputStream(new FileInputStream(fileName))).isEqualTo("UK\r\n" + "US\r\n" + "Germany\r\n" + "Spain\n"); + assertThat(StreamUtils.getStringFromInputStream(new FileInputStream(fileName))).isEqualTo("UK\r\n" + "US\r\n" + "Germany\r\n" + "Spain\r\n"); } } \ No newline at end of file diff --git a/core-java-io/src/test/java/org/baeldung/java/io/JavaReadFromFileUnitTest.java b/core-java-io/src/test/java/org/baeldung/java/io/JavaReadFromFileUnitTest.java index b56841117e..0945a21b1b 100644 --- a/core-java-io/src/test/java/org/baeldung/java/io/JavaReadFromFileUnitTest.java +++ b/core-java-io/src/test/java/org/baeldung/java/io/JavaReadFromFileUnitTest.java @@ -106,7 +106,7 @@ public class JavaReadFromFileUnitTest { @Test public void whenReadUTFEncodedFile_thenCorrect() throws IOException { - final String expected_value = "é�’空"; + final String expected_value = "青空"; final BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream("src/test/resources/test_read7.in"), "UTF-8")); final String currentLine = reader.readLine(); reader.close(); diff --git a/flips/src/test/java/com/baeldung/flips/controller/FlipControllerTest.java b/flips/src/test/java/com/baeldung/flips/controller/FlipControllerIntegrationTest.java similarity index 98% rename from flips/src/test/java/com/baeldung/flips/controller/FlipControllerTest.java rename to flips/src/test/java/com/baeldung/flips/controller/FlipControllerIntegrationTest.java index 8fd9c4e340..9dd4ef064a 100644 --- a/flips/src/test/java/com/baeldung/flips/controller/FlipControllerTest.java +++ b/flips/src/test/java/com/baeldung/flips/controller/FlipControllerIntegrationTest.java @@ -23,7 +23,7 @@ import org.springframework.test.web.servlet.result.MockMvcResultMatchers; }, webEnvironment = SpringBootTest.WebEnvironment.MOCK) @AutoConfigureMockMvc @ActiveProfiles("dev") -public class FlipControllerTest { +public class FlipControllerIntegrationTest { @Autowired private MockMvc mvc; diff --git a/mustache/src/test/java/com/baeldung/mustache/TodoMustacheServiceTest.java b/mustache/src/test/java/com/baeldung/mustache/TodoMustacheServiceUnitTest.java similarity index 98% rename from mustache/src/test/java/com/baeldung/mustache/TodoMustacheServiceTest.java rename to mustache/src/test/java/com/baeldung/mustache/TodoMustacheServiceUnitTest.java index 0df2f7f8a4..0c192b30bc 100644 --- a/mustache/src/test/java/com/baeldung/mustache/TodoMustacheServiceTest.java +++ b/mustache/src/test/java/com/baeldung/mustache/TodoMustacheServiceUnitTest.java @@ -15,7 +15,7 @@ import java.util.Map; import static org.assertj.core.api.Assertions.assertThat; -public class TodoMustacheServiceTest { +public class TodoMustacheServiceUnitTest { private String executeTemplate(Mustache m, Map context) throws IOException { StringWriter writer = new StringWriter(); diff --git a/spring-4/src/test/java/com/baeldung/flips/controller/FlipControllerTest.java b/spring-4/src/test/java/com/baeldung/flips/controller/FlipControllerIntegrationTest.java similarity index 98% rename from spring-4/src/test/java/com/baeldung/flips/controller/FlipControllerTest.java rename to spring-4/src/test/java/com/baeldung/flips/controller/FlipControllerIntegrationTest.java index 8fd9c4e340..9dd4ef064a 100644 --- a/spring-4/src/test/java/com/baeldung/flips/controller/FlipControllerTest.java +++ b/spring-4/src/test/java/com/baeldung/flips/controller/FlipControllerIntegrationTest.java @@ -23,7 +23,7 @@ import org.springframework.test.web.servlet.result.MockMvcResultMatchers; }, webEnvironment = SpringBootTest.WebEnvironment.MOCK) @AutoConfigureMockMvc @ActiveProfiles("dev") -public class FlipControllerTest { +public class FlipControllerIntegrationTest { @Autowired private MockMvc mvc; diff --git a/spring-5/src/main/java/com/baeldung/persistence/FooRepository.java b/spring-5/src/main/java/com/baeldung/persistence/FooRepository.java index 1f1e071158..9270d58d35 100644 --- a/spring-5/src/main/java/com/baeldung/persistence/FooRepository.java +++ b/spring-5/src/main/java/com/baeldung/persistence/FooRepository.java @@ -1,10 +1,9 @@ package com.baeldung.persistence; +import com.baeldung.web.Foo; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaSpecificationExecutor; -import com.baeldung.web.Foo; - public interface FooRepository extends JpaRepository, JpaSpecificationExecutor { } diff --git a/spring-5/src/main/java/com/baeldung/web/FooController.java b/spring-5/src/main/java/com/baeldung/web/FooController.java index 925f2b49f4..a09e628421 100644 --- a/spring-5/src/main/java/com/baeldung/web/FooController.java +++ b/spring-5/src/main/java/com/baeldung/web/FooController.java @@ -7,6 +7,7 @@ import org.springframework.http.HttpStatus; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; +import javax.annotation.PostConstruct; import javax.validation.constraints.Max; import javax.validation.constraints.Min; import java.util.List; @@ -14,6 +15,11 @@ import java.util.List; @RestController("/foos") public class FooController { + @PostConstruct + public void init(){ + System.out.println("test"); + } + @Autowired private FooRepository repo; diff --git a/spring-5/src/test/java/com/baeldung/Example1IntegrationTest.java b/spring-5/src/test/java/com/baeldung/Example1IntegrationTest.java index 8b9e66213f..ecc677465e 100644 --- a/spring-5/src/test/java/com/baeldung/Example1IntegrationTest.java +++ b/spring-5/src/test/java/com/baeldung/Example1IntegrationTest.java @@ -3,10 +3,12 @@ package com.baeldung; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.data.jpa.repository.config.EnableJpaRepositories; import org.springframework.test.context.junit4.SpringRunner; @RunWith(SpringRunner.class) @SpringBootTest +@EnableJpaRepositories("com.baeldung.persistence") public class Example1IntegrationTest { @Test diff --git a/spring-5/src/test/java/com/baeldung/Example2IntegrationTest.java b/spring-5/src/test/java/com/baeldung/Example2IntegrationTest.java index 6ed53ca4e9..e1d56c2fc3 100644 --- a/spring-5/src/test/java/com/baeldung/Example2IntegrationTest.java +++ b/spring-5/src/test/java/com/baeldung/Example2IntegrationTest.java @@ -3,10 +3,12 @@ package com.baeldung; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.data.jpa.repository.config.EnableJpaRepositories; import org.springframework.test.context.junit4.SpringRunner; @RunWith(SpringRunner.class) @SpringBootTest +@EnableJpaRepositories("com.baeldung.persistence") public class Example2IntegrationTest { @Test diff --git a/spring-5/src/test/java/com/baeldung/Spring5ApplicationIntegrationTest.java b/spring-5/src/test/java/com/baeldung/Spring5ApplicationIntegrationTest.java index af288c3c2d..1bbf0e3775 100644 --- a/spring-5/src/test/java/com/baeldung/Spring5ApplicationIntegrationTest.java +++ b/spring-5/src/test/java/com/baeldung/Spring5ApplicationIntegrationTest.java @@ -1,5 +1,6 @@ package com.baeldung; +import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; @@ -7,6 +8,7 @@ import org.springframework.test.context.junit4.SpringRunner; @RunWith(SpringRunner.class) @SpringBootTest +@Ignore public class Spring5ApplicationIntegrationTest { @Test diff --git a/spring-5/src/test/java/com/baeldung/functional/BeanRegistrationIntegrationTest.java b/spring-5/src/test/java/com/baeldung/functional/BeanRegistrationIntegrationTest.java index 5392a59343..fba01726f4 100644 --- a/spring-5/src/test/java/com/baeldung/functional/BeanRegistrationIntegrationTest.java +++ b/spring-5/src/test/java/com/baeldung/functional/BeanRegistrationIntegrationTest.java @@ -6,6 +6,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.data.jpa.repository.config.EnableJpaRepositories; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.web.context.support.GenericWebApplicationContext; @@ -13,6 +14,7 @@ import com.baeldung.Spring5Application; @RunWith(SpringRunner.class) @SpringBootTest(classes = Spring5Application.class) +@EnableJpaRepositories("com.baeldung.persistence") public class BeanRegistrationIntegrationTest { @Autowired diff --git a/spring-5/src/test/java/com/baeldung/jdbc/autogenkey/GetAutoGenKeyByJDBC.java b/spring-5/src/test/java/com/baeldung/jdbc/autogenkey/GetAutoGenKeyByJDBC.java index c52e18ef7f..45012a95aa 100644 --- a/spring-5/src/test/java/com/baeldung/jdbc/autogenkey/GetAutoGenKeyByJDBC.java +++ b/spring-5/src/test/java/com/baeldung/jdbc/autogenkey/GetAutoGenKeyByJDBC.java @@ -2,6 +2,7 @@ package com.baeldung.jdbc.autogenkey; import static org.junit.jupiter.api.Assertions.assertEquals; +import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; @@ -15,6 +16,7 @@ import com.baeldung.jdbc.autogenkey.repository.MessageRepositoryJDBCTemplate; import com.baeldung.jdbc.autogenkey.repository.MessageRepositorySimpleJDBCInsert; @RunWith(SpringRunner.class) +@Ignore public class GetAutoGenKeyByJDBC { @Configuration diff --git a/spring-5/src/test/java/com/baeldung/jsonb/JsonbIntegrationTest.java b/spring-5/src/test/java/com/baeldung/jsonb/JsonbIntegrationTest.java index 756b303f3b..f4749c0d33 100644 --- a/spring-5/src/test/java/com/baeldung/jsonb/JsonbIntegrationTest.java +++ b/spring-5/src/test/java/com/baeldung/jsonb/JsonbIntegrationTest.java @@ -5,6 +5,7 @@ import static org.junit.Assert.assertTrue; import java.math.BigDecimal; import java.time.LocalDate; +import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; @@ -16,18 +17,15 @@ import org.springframework.test.context.junit4.SpringRunner; @RunWith(SpringRunner.class) @SpringBootTest(classes = Spring5Application.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +@Ignore public class JsonbIntegrationTest { - @Value("${security.user.name}") - private String username; - @Value("${security.user.password}") - private String password; @Autowired private TestRestTemplate template; @Test public void givenId_whenUriIsPerson_thenGetPerson() { - ResponseEntity response = template.withBasicAuth(username, password) + ResponseEntity response = template .getForEntity("/person/1", Person.class); Person person = response.getBody(); assertTrue(person.equals(new Person(2, "Jhon", "jhon1@test.com", 0, LocalDate.of(2019, 9, 9), BigDecimal.valueOf(1500.0)))); @@ -35,8 +33,8 @@ public class JsonbIntegrationTest { @Test public void whenSendPostAPerson_thenGetOkStatus() { - ResponseEntity response = template.withBasicAuth(username, password) - .postForEntity("/person", "{\"birthDate\":\"07-09-2017\",\"email\":\"jhon1@test.com\",\"person-name\":\"Jhon\",\"id\":10}", Boolean.class); + ResponseEntity response = template.withBasicAuth("user","password"). + postForEntity("/person", "{\"birthDate\":\"07-09-2017\",\"email\":\"jhon1@test.com\",\"person-name\":\"Jhon\",\"id\":10}", Boolean.class); assertTrue(response.getBody()); } diff --git a/spring-5/src/test/java/com/baeldung/security/SecurityIntegrationTest.java b/spring-5/src/test/java/com/baeldung/security/SecurityIntegrationTest.java index 5680625496..1f8bb549c7 100644 --- a/spring-5/src/test/java/com/baeldung/security/SecurityIntegrationTest.java +++ b/spring-5/src/test/java/com/baeldung/security/SecurityIntegrationTest.java @@ -2,6 +2,7 @@ package com.baeldung.security; import com.baeldung.SpringSecurity5Application; import org.junit.Before; +import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; @@ -31,6 +32,7 @@ public class SecurityIntegrationTest { } @Test + @Ignore @WithMockUser public void whenHasCredentials_thenSeesGreeting() { this.rest.get().uri("/").exchange().expectStatus().isOk().expectBody(String.class).isEqualTo("Hello, user"); diff --git a/spring-5/src/test/java/com/baeldung/web/client/WebTestClientIntegrationTest.java b/spring-5/src/test/java/com/baeldung/web/client/WebTestClientIntegrationTest.java index 9a6e997ca1..f9472452ba 100644 --- a/spring-5/src/test/java/com/baeldung/web/client/WebTestClientIntegrationTest.java +++ b/spring-5/src/test/java/com/baeldung/web/client/WebTestClientIntegrationTest.java @@ -5,6 +5,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.web.server.LocalServerPort; +import org.springframework.data.jpa.repository.config.EnableJpaRepositories; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.web.reactive.server.WebTestClient; import org.springframework.web.reactive.function.server.RequestPredicates; @@ -16,6 +17,7 @@ import reactor.core.publisher.Mono; @RunWith(SpringRunner.class) @SpringBootTest(classes = Spring5Application.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +@EnableJpaRepositories("com.baeldung.persistence") public class WebTestClientIntegrationTest { @LocalServerPort diff --git a/spring-all/src/test/java/org/baeldung/controller/PassParametersControllerTest.java b/spring-all/src/test/java/org/baeldung/controller/PassParametersControllerIntegrationTest.java similarity index 97% rename from spring-all/src/test/java/org/baeldung/controller/PassParametersControllerTest.java rename to spring-all/src/test/java/org/baeldung/controller/PassParametersControllerIntegrationTest.java index 76ac14f292..21084f44ce 100644 --- a/spring-all/src/test/java/org/baeldung/controller/PassParametersControllerTest.java +++ b/spring-all/src/test/java/org/baeldung/controller/PassParametersControllerIntegrationTest.java @@ -23,7 +23,7 @@ import org.springframework.web.servlet.ModelAndView; @RunWith(SpringJUnit4ClassRunner.class) @WebAppConfiguration @ContextConfiguration({"classpath:test-mvc.xml"}) -public class PassParametersControllerTest { +public class PassParametersControllerIntegrationTest { private MockMvc mockMvc; @Autowired diff --git a/spring-all/src/test/java/org/baeldung/spring43/defaultmethods/ITransactionalTest.java b/spring-all/src/test/java/org/baeldung/spring43/defaultmethods/ITransactionalUnitTest.java similarity index 80% rename from spring-all/src/test/java/org/baeldung/spring43/defaultmethods/ITransactionalTest.java rename to spring-all/src/test/java/org/baeldung/spring43/defaultmethods/ITransactionalUnitTest.java index c7b95bced4..3c180e91c8 100644 --- a/spring-all/src/test/java/org/baeldung/spring43/defaultmethods/ITransactionalTest.java +++ b/spring-all/src/test/java/org/baeldung/spring43/defaultmethods/ITransactionalUnitTest.java @@ -5,9 +5,9 @@ import org.slf4j.LoggerFactory; import org.springframework.test.context.transaction.AfterTransaction; import org.springframework.test.context.transaction.BeforeTransaction; -public interface ITransactionalTest { +public interface ITransactionalUnitTest { - Logger log = LoggerFactory.getLogger(ITransactionalTest.class); + Logger log = LoggerFactory.getLogger(ITransactionalUnitTest.class); @BeforeTransaction default void beforeTransaction() { diff --git a/spring-all/src/test/java/org/baeldung/spring43/defaultmethods/TransactionalIntegrationTest.java b/spring-all/src/test/java/org/baeldung/spring43/defaultmethods/TransactionalIntegrationTest.java index b4ac7e8ccf..dde153487d 100644 --- a/spring-all/src/test/java/org/baeldung/spring43/defaultmethods/TransactionalIntegrationTest.java +++ b/spring-all/src/test/java/org/baeldung/spring43/defaultmethods/TransactionalIntegrationTest.java @@ -5,7 +5,7 @@ import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests; @ContextConfiguration(classes = TransactionalTestConfiguration.class) -public class TransactionalIntegrationTest extends AbstractTransactionalJUnit4SpringContextTests implements ITransactionalTest { +public class TransactionalIntegrationTest extends AbstractTransactionalJUnit4SpringContextTests implements ITransactionalUnitTest { @Test public void whenDefaultMethodAnnotatedWithBeforeTransaction_thenDefaultMethodIsExecuted() { diff --git a/spring-boot-ops/README.MD b/spring-boot-ops/README.MD deleted file mode 100644 index 5ac223397c..0000000000 --- a/spring-boot-ops/README.MD +++ /dev/null @@ -1,13 +0,0 @@ -### The Course -The "REST With Spring" Classes: http://bit.ly/restwithspring - -### Relevant Articles: - -- [Intro to Spring Boot Starters](http://www.baeldung.com/spring-boot-starters) -- [A Custom Data Binder in Spring MVC](http://www.baeldung.com/spring-mvc-custom-data-binder) -- [Introduction to WebJars](http://www.baeldung.com/maven-webjars) -- [A Quick Guide to Maven Wrapper](http://www.baeldung.com/maven-wrapper) -- [Shutdown a Spring Boot Application](http://www.baeldung.com/spring-boot-shutdown) -- [Create a Fat Jar App with Spring Boot](http://www.baeldung.com/deployable-fat-jar-spring-boot) -- [Spring Boot Dependency Management with a Custom Parent](http://www.baeldung.com/spring-boot-dependency-management-custom-parent) - diff --git a/spring-boot-ops/README.md b/spring-boot-ops/README.md deleted file mode 100644 index 7de2fed24f..0000000000 --- a/spring-boot-ops/README.md +++ /dev/null @@ -1,12 +0,0 @@ -### The Course -The "REST With Spring" Classes: http://bit.ly/restwithspring - -### Relevant Articles: - -- [Intro to Spring Boot Starters](http://www.baeldung.com/spring-boot-starters) -- [A Custom Data Binder in Spring MVC](http://www.baeldung.com/spring-mvc-custom-data-binder) -- [Introduction to WebJars](http://www.baeldung.com/maven-webjars) -- [A Quick Guide to Maven Wrapper](http://www.baeldung.com/maven-wrapper) -- [Shutdown a Spring Boot Application](http://www.baeldung.com/spring-boot-shutdown) -- [Create a Fat Jar App with Spring Boot](http://www.baeldung.com/deployable-fat-jar-spring-boot) -- [Spring Boot Dependency Management with a Custom Parent](http://www.baeldung.com/spring-boot-dependency-management-custom-parent) \ No newline at end of file diff --git a/spring-cloud/spring-cloud-kubernetes/demo-backend/src/test/java/com/baeldung/spring/cloud/kubernetes/backend/KubernetesBackendApplicationTests.java b/spring-cloud/spring-cloud-kubernetes/demo-backend/src/test/java/com/baeldung/spring/cloud/kubernetes/backend/KubernetesBackendApplicationIntegrationTest.java similarity index 84% rename from spring-cloud/spring-cloud-kubernetes/demo-backend/src/test/java/com/baeldung/spring/cloud/kubernetes/backend/KubernetesBackendApplicationTests.java rename to spring-cloud/spring-cloud-kubernetes/demo-backend/src/test/java/com/baeldung/spring/cloud/kubernetes/backend/KubernetesBackendApplicationIntegrationTest.java index 5ccc49eaa7..2440b97aaf 100644 --- a/spring-cloud/spring-cloud-kubernetes/demo-backend/src/test/java/com/baeldung/spring/cloud/kubernetes/backend/KubernetesBackendApplicationTests.java +++ b/spring-cloud/spring-cloud-kubernetes/demo-backend/src/test/java/com/baeldung/spring/cloud/kubernetes/backend/KubernetesBackendApplicationIntegrationTest.java @@ -7,7 +7,7 @@ import org.springframework.test.context.junit4.SpringRunner; @RunWith(SpringRunner.class) @SpringBootTest -public class KubernetesBackendApplicationTests { +public class KubernetesBackendApplicationIntegrationTest { @Test public void contextLoads() { diff --git a/spring-cloud/spring-cloud-kubernetes/demo-frontend/src/test/java/com/baeldung/spring/cloud/kubernetes/frontend/KubernetesFrontendApplicationTests.java b/spring-cloud/spring-cloud-kubernetes/demo-frontend/src/test/java/com/baeldung/spring/cloud/kubernetes/frontend/KubernetesFrontendApplicationIntegrationTest.java similarity index 84% rename from spring-cloud/spring-cloud-kubernetes/demo-frontend/src/test/java/com/baeldung/spring/cloud/kubernetes/frontend/KubernetesFrontendApplicationTests.java rename to spring-cloud/spring-cloud-kubernetes/demo-frontend/src/test/java/com/baeldung/spring/cloud/kubernetes/frontend/KubernetesFrontendApplicationIntegrationTest.java index 0e34eb45f8..19ad9676cb 100644 --- a/spring-cloud/spring-cloud-kubernetes/demo-frontend/src/test/java/com/baeldung/spring/cloud/kubernetes/frontend/KubernetesFrontendApplicationTests.java +++ b/spring-cloud/spring-cloud-kubernetes/demo-frontend/src/test/java/com/baeldung/spring/cloud/kubernetes/frontend/KubernetesFrontendApplicationIntegrationTest.java @@ -7,7 +7,7 @@ import org.springframework.test.context.junit4.SpringRunner; @RunWith(SpringRunner.class) @SpringBootTest -public class KubernetesFrontendApplicationTests { +public class KubernetesFrontendApplicationIntegrationTest { @Test public void contextLoads() { diff --git a/spring-data-rest/src/test/java/com/baeldung/events/AuthorEventHandlerTest.java b/spring-data-rest/src/test/java/com/baeldung/events/AuthorEventHandlerUnitTest.java similarity index 95% rename from spring-data-rest/src/test/java/com/baeldung/events/AuthorEventHandlerTest.java rename to spring-data-rest/src/test/java/com/baeldung/events/AuthorEventHandlerUnitTest.java index 9fb2d1014e..6db536c40c 100644 --- a/spring-data-rest/src/test/java/com/baeldung/events/AuthorEventHandlerTest.java +++ b/spring-data-rest/src/test/java/com/baeldung/events/AuthorEventHandlerUnitTest.java @@ -7,7 +7,7 @@ import org.springframework.data.rest.core.annotation.RepositoryEventHandler; import static org.mockito.Mockito.mock; -public class AuthorEventHandlerTest { +public class AuthorEventHandlerUnitTest { @Test public void whenCreateAuthorThenSuccess() { diff --git a/spring-data-rest/src/test/java/com/baeldung/events/BookEventHandlerTest.java b/spring-data-rest/src/test/java/com/baeldung/events/BookEventHandlerUnitTest.java similarity index 95% rename from spring-data-rest/src/test/java/com/baeldung/events/BookEventHandlerTest.java rename to spring-data-rest/src/test/java/com/baeldung/events/BookEventHandlerUnitTest.java index 85699adb0d..28f0b91e1c 100644 --- a/spring-data-rest/src/test/java/com/baeldung/events/BookEventHandlerTest.java +++ b/spring-data-rest/src/test/java/com/baeldung/events/BookEventHandlerUnitTest.java @@ -7,7 +7,7 @@ import org.mockito.Mockito; import static org.mockito.Mockito.mock; -public class BookEventHandlerTest { +public class BookEventHandlerUnitTest { @Test public void whenCreateBookThenSuccess() { Book book = mock(Book.class); diff --git a/spring-mvc-java/src/test/java/com/baeldung/web/controller/SimpleBookControllerTest.java b/spring-mvc-java/src/test/java/com/baeldung/web/controller/SimpleBookControllerIntegrationTest.java similarity index 95% rename from spring-mvc-java/src/test/java/com/baeldung/web/controller/SimpleBookControllerTest.java rename to spring-mvc-java/src/test/java/com/baeldung/web/controller/SimpleBookControllerIntegrationTest.java index 4be0ded963..23be3a1655 100644 --- a/spring-mvc-java/src/test/java/com/baeldung/web/controller/SimpleBookControllerTest.java +++ b/spring-mvc-java/src/test/java/com/baeldung/web/controller/SimpleBookControllerIntegrationTest.java @@ -12,7 +12,7 @@ import org.springframework.test.web.servlet.setup.MockMvcBuilders; import com.baeldung.web.controller.SimpleBookController; -public class SimpleBookControllerTest { +public class SimpleBookControllerIntegrationTest { private MockMvc mockMvc; private static final String CONTENT_TYPE = "application/json;charset=UTF-8"; diff --git a/spring-mvc-java/src/test/java/com/baeldung/web/controller/SimpleBookRestControllerTest.java b/spring-mvc-java/src/test/java/com/baeldung/web/controller/SimpleBookRestControllerIntegrationTest.java similarity index 95% rename from spring-mvc-java/src/test/java/com/baeldung/web/controller/SimpleBookRestControllerTest.java rename to spring-mvc-java/src/test/java/com/baeldung/web/controller/SimpleBookRestControllerIntegrationTest.java index 23b8c639d3..c5bd53f1a7 100644 --- a/spring-mvc-java/src/test/java/com/baeldung/web/controller/SimpleBookRestControllerTest.java +++ b/spring-mvc-java/src/test/java/com/baeldung/web/controller/SimpleBookRestControllerIntegrationTest.java @@ -12,7 +12,7 @@ import org.springframework.test.web.servlet.setup.MockMvcBuilders; import com.baeldung.web.controller.SimpleBookController; -public class SimpleBookRestControllerTest { +public class SimpleBookRestControllerIntegrationTest { private MockMvc mockMvc; private static final String CONTENT_TYPE = "application/json;charset=UTF-8"; diff --git a/spring-rest-full/src/test/java/org/baeldung/spring/ConfigTest.java b/spring-rest-full/src/test/java/org/baeldung/spring/ConfigIntegrationTest.java similarity index 75% rename from spring-rest-full/src/test/java/org/baeldung/spring/ConfigTest.java rename to spring-rest-full/src/test/java/org/baeldung/spring/ConfigIntegrationTest.java index 56f3de6cb0..77603da0dd 100644 --- a/spring-rest-full/src/test/java/org/baeldung/spring/ConfigTest.java +++ b/spring-rest-full/src/test/java/org/baeldung/spring/ConfigIntegrationTest.java @@ -6,9 +6,9 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter @Configuration @ComponentScan("org.baeldung.test") -public class ConfigTest extends WebMvcConfigurerAdapter { +public class ConfigIntegrationTest extends WebMvcConfigurerAdapter { - public ConfigTest() { + public ConfigIntegrationTest() { super(); } diff --git a/spring-rest-full/src/test/java/org/baeldung/web/FooDiscoverabilityLiveTest.java b/spring-rest-full/src/test/java/org/baeldung/web/FooDiscoverabilityLiveTest.java index c0e1f9d04d..a6577e4de8 100644 --- a/spring-rest-full/src/test/java/org/baeldung/web/FooDiscoverabilityLiveTest.java +++ b/spring-rest-full/src/test/java/org/baeldung/web/FooDiscoverabilityLiveTest.java @@ -4,7 +4,7 @@ import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic; import org.baeldung.common.web.AbstractDiscoverabilityLiveTest; import org.baeldung.persistence.model.Foo; -import org.baeldung.spring.ConfigTest; +import org.baeldung.spring.ConfigIntegrationTest; import org.junit.runner.RunWith; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.ContextConfiguration; @@ -12,7 +12,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.support.AnnotationConfigContextLoader; @RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(classes = { ConfigTest.class }, loader = AnnotationConfigContextLoader.class) +@ContextConfiguration(classes = { ConfigIntegrationTest.class }, loader = AnnotationConfigContextLoader.class) @ActiveProfiles("test") public class FooDiscoverabilityLiveTest extends AbstractDiscoverabilityLiveTest { diff --git a/spring-rest-full/src/test/java/org/baeldung/web/FooLiveTest.java b/spring-rest-full/src/test/java/org/baeldung/web/FooLiveTest.java index 5a4f472fe3..65564a6845 100644 --- a/spring-rest-full/src/test/java/org/baeldung/web/FooLiveTest.java +++ b/spring-rest-full/src/test/java/org/baeldung/web/FooLiveTest.java @@ -4,7 +4,7 @@ import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic; import org.baeldung.common.web.AbstractBasicLiveTest; import org.baeldung.persistence.model.Foo; -import org.baeldung.spring.ConfigTest; +import org.baeldung.spring.ConfigIntegrationTest; import org.junit.runner.RunWith; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.ContextConfiguration; @@ -12,7 +12,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.support.AnnotationConfigContextLoader; @RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(classes = { ConfigTest.class }, loader = AnnotationConfigContextLoader.class) +@ContextConfiguration(classes = { ConfigIntegrationTest.class }, loader = AnnotationConfigContextLoader.class) @ActiveProfiles("test") public class FooLiveTest extends AbstractBasicLiveTest { diff --git a/spring-rest-full/src/test/java/org/baeldung/web/FooPageableLiveTest.java b/spring-rest-full/src/test/java/org/baeldung/web/FooPageableLiveTest.java index 62a8983356..3f637c5213 100644 --- a/spring-rest-full/src/test/java/org/baeldung/web/FooPageableLiveTest.java +++ b/spring-rest-full/src/test/java/org/baeldung/web/FooPageableLiveTest.java @@ -13,7 +13,7 @@ import java.util.List; import org.baeldung.common.web.AbstractBasicLiveTest; import org.baeldung.persistence.model.Foo; -import org.baeldung.spring.ConfigTest; +import org.baeldung.spring.ConfigIntegrationTest; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.test.context.ActiveProfiles; @@ -22,7 +22,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.support.AnnotationConfigContextLoader; @RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(classes = { ConfigTest.class }, loader = AnnotationConfigContextLoader.class) +@ContextConfiguration(classes = { ConfigIntegrationTest.class }, loader = AnnotationConfigContextLoader.class) @ActiveProfiles("test") public class FooPageableLiveTest extends AbstractBasicLiveTest { diff --git a/spring-rest/src/test/java/com/baeldung/propertyeditor/creditcard/CreditCardEditorTest.java b/spring-rest/src/test/java/com/baeldung/propertyeditor/creditcard/CreditCardEditorUnitTest.java similarity index 97% rename from spring-rest/src/test/java/com/baeldung/propertyeditor/creditcard/CreditCardEditorTest.java rename to spring-rest/src/test/java/com/baeldung/propertyeditor/creditcard/CreditCardEditorUnitTest.java index e87adbc712..a84f866dfe 100644 --- a/spring-rest/src/test/java/com/baeldung/propertyeditor/creditcard/CreditCardEditorTest.java +++ b/spring-rest/src/test/java/com/baeldung/propertyeditor/creditcard/CreditCardEditorUnitTest.java @@ -10,7 +10,7 @@ import com.baeldung.propertyeditor.creditcard.CreditCard; import com.baeldung.propertyeditor.creditcard.CreditCardEditor; @RunWith(MockitoJUnitRunner.class) -public class CreditCardEditorTest { +public class CreditCardEditorUnitTest { private CreditCardEditor creditCardEditor; diff --git a/spring-security-thymeleaf/src/test/java/com/baeldung/springsecuritythymeleaf/SpringSecurityThymeleafApplicationTests.java b/spring-security-thymeleaf/src/test/java/com/baeldung/springsecuritythymeleaf/SpringSecurityThymeleafApplicationIntegrationTest.java similarity index 90% rename from spring-security-thymeleaf/src/test/java/com/baeldung/springsecuritythymeleaf/SpringSecurityThymeleafApplicationTests.java rename to spring-security-thymeleaf/src/test/java/com/baeldung/springsecuritythymeleaf/SpringSecurityThymeleafApplicationIntegrationTest.java index dea254dd31..c852d05e73 100644 --- a/spring-security-thymeleaf/src/test/java/com/baeldung/springsecuritythymeleaf/SpringSecurityThymeleafApplicationTests.java +++ b/spring-security-thymeleaf/src/test/java/com/baeldung/springsecuritythymeleaf/SpringSecurityThymeleafApplicationIntegrationTest.java @@ -11,7 +11,7 @@ import org.springframework.web.context.WebApplicationContext; @RunWith(SpringRunner.class) @SpringBootTest -public class SpringSecurityThymeleafApplicationTests { +public class SpringSecurityThymeleafApplicationIntegrationTest { @Autowired ViewController viewController; diff --git a/vavr/src/test/java/com/baeldung/vavr/future/FutureTest.java b/vavr/src/test/java/com/baeldung/vavr/future/FutureUnitTest.java similarity index 99% rename from vavr/src/test/java/com/baeldung/vavr/future/FutureTest.java rename to vavr/src/test/java/com/baeldung/vavr/future/FutureUnitTest.java index d5345cad55..c398cc4095 100644 --- a/vavr/src/test/java/com/baeldung/vavr/future/FutureTest.java +++ b/vavr/src/test/java/com/baeldung/vavr/future/FutureUnitTest.java @@ -13,7 +13,7 @@ import static java.util.concurrent.Executors.newSingleThreadExecutor; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; -public class FutureTest { +public class FutureUnitTest { private static final String error = "Failed to get underlying value."; private static final String HELLO = "Welcome to Baeldung!"; From eb746f5ac62d701c15dc44a737b5da68232be86c Mon Sep 17 00:00:00 2001 From: sachin29aug Date: Tue, 5 Jun 2018 23:05:43 +0530 Subject: [PATCH 12/15] BAEL-6839: Updated pmd unit tests rule - Allow tests ending with "jmhTest" and disallow ones ending with "Tests" (#4411) * BAEL-6839: Updated the unit tests convention pmd rule - Don't allow unit tests ending with "Tests" and allow the ones ending with "jmhTest" ("*jmhTest" are autogenerated) * fixed formatting issue - Replaced tabs with spaces --- custom-pmd-0.0.1.jar | Bin 3288 -> 3311 bytes .../pmd/UnitTestNamingConventionRule.java | 11 +++++------ 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/custom-pmd-0.0.1.jar b/custom-pmd-0.0.1.jar index 4ad69338657fa4a0da39a243e8bc151987b9cd19..5038a704752743a87999b917976d11c78b322af1 100644 GIT binary patch literal 3311 zcmb7H2{=^iA0E2~HQBCYNr`M@-%YY6gKL>YSsDh}x3N!!P}%HI z+9k3S8IPiC{xfNCFa7WBH_tied!BjU_x$EN-}jz(^q~}#Kmf6rA2;fJAN)8SB3yMf zU@9UP^fX2Ff52z~Oa$0$w$GRo;p-5>!MqoytD<*7Q^N=b*413q?P%A5ihz3 z2_shzyPf{`BN%=ltl&0I2rrla2R-^vsGBolM|pc@4o6pD4G1^oC(NGYLGX(%_DGnG zCsGgYZ0};H=IY{YlFAi*Z@3 z*VGn3TI6?gW7G_^=3hT~T3(jef{r)-@XlcF6z-CMq<~o8*>jI#`{5Nr@?JH!?=*JprS#1C zMk!lNx%-tyP6i)oRKa9Mm??uNdrjMeC_fe!7CPWY^1_C)`(})tq6GvNC-kI@!B)NA zJsQIlfew!P&=28z5GcephK0lznZF-kFro}GNa4MY3z?R;GF0)&uE@=@YkJ=5m$m3y z%_!}tWP*^sFZ>nbD((|b6=U{18uDNg#FVp0m#On%Rr)@Q@qKCa6Sx-$l-Zs1F!@Hlz1bQSJ3^JV|SmM~ssj zT|L`v$P(`4aaOT9IF2ypP2FH}U$e65bLEaJb>d6vXeD!(xQ9GFidqly?qb0u2b(Ue z7P0Wh1D~8rEgkVbhOyOIDmk^Ph=j3=LY+A6mNOzY6>6F&SRTe`DCK_Bex%>bcrU!z zY)&rJ2ZqYYiC|%gMWP}<%`xh3*3fFyUS2hmLMd`+O>c7CVAJABe1(bOu7mX>O-jAo ziqP#Ax=3?G#{30;gcw@9yZTOLt7n*A0n`HDV zLs2#R6hubn2@jUm+-{Ni$}+??HE$t*XZA4H<9NGP1p7LLiy|u%MlDStgdZZ-z5Yds zi8b$PzME7GB3trL3lG$D^U?*HI7l^ri;#YHlL5L@{7twt3#C&625k#RPp^iazinLF z_uyiMLW*zEgxPHAwDXsRkuzA^PFo!PF>{GYnpB{FYI-8@Sjpn%f%+6djwEH;#1bn4;JiNTB!< zckc9rJgVP&E40@CTD6}&oq1x}?3@Kx`??d)nj|=8rccT*cyc_eCQ!4uxGJ>cGnBlM z4(C02Na9q^yZqQKZP2Lu+dgKt1|^LVY=eKCNo>Lzb!Y-i6Yb_K=phreD*iIHA}~_@ ztj0|V;2Fj-T2sln4Vq~|a9$Q1XW7#yPG2|Edo%0FaQY|N$B?gN*p#-}4hMys9Yuv- zt4#+!H+Rm;taf4bLT``( z0OQmEfW)r}xw$%neVv`2!rEQ_6a!TsUsh(*EIGNvca1`AMuZH=s}*?mwUAm5&^(-1 zOWWH3Hx5k@GBxDQzCYJAG?YHG7*QZIUz>a-y-jtvd*RY7?(j5v(ClQPK){SvGKaD< zWa@aiN~#y)qn>g3;`GX$m^VS|aO}`jX6zBm>sA+-c#3n-D{CHQ4renfu{__h*t}F* z@p0z5;(9WXR~da~GyT zz}+1t|BX|DImx%Ydwpr^oa2VYs85z0D9}>S02yj%4!d!DQD3p1qTFX?b*o;cVIWZ3 z=sC9n2!HCKwg}J#odmINu0{7CVciw|tZ?m*8WzdR98n;0fv)nSs?ng1VLAZ(2b#{`HmHS1y?vvox2=BP$wckP>iZQ<<;2@l4$0Wgm3G;x`!--aB(- zquw)3uXqR^=ZF(f3d82Q*eyLvh+Vm`a6)Zh64Ams8a$Z#8VT017Je?9f3>x-W9GqH zOXe0CY4y{74>%QXZO*t6RuGbK$p89Ea`SL?v++RM+jw%e)&c9q=mD<-vhkp|L%qhK z;%`m)d_9!oip%KD6fm|E<3bkWjxG(nCIWT1AR4ZQL8%olU(Oc3UN;MG}U1 zC8n+IA~I$PLn4FZAq4mNIhB~cwu?w*B-p{ zlB9Ek?*E$b4=diC!-KcvuKpzLzfZ%S#)F)BIEq8#Sj%pqBn-Z{*+7jt+CIVBNcB#Blkr`g8-ipsH2lXN-c zkdM+V&5T&3ba0A>9Fn3>@s7TFzrO4G?(2H~_jN!2-|v2&=enQg{>>`CP=-3=L_{H= zHS@5@%!X=0-7PZl)v3PwNW!VqY-<-X1jU`_ZlR!X@lE*@q8yIs`rsi=ES;mwgtVpy zGfzSuC6uej*jypTwh(JoBVEzHIRLdbkC%RHB8 zCsqj_z&M{g5>!V{Gh5F7z|0$ZU>t5K!+$7;F~okUezy8Hb;VsBg@oA-1I&A?`2@ z5mBYdpA)fBp`r%`-icJ__;5IoIZ?Au#dUlnlbh_{RwU0@KH4?1*f@qNvQ1-KMH{;9 zYSf}!VC@*u8+lwl_;!21OMHzE!hVV4nXSv_E$W-bR26e`x(3MkAykWWx8q_1jbrBA zEVH06*?gV*e;~>}9yot{RJHq-&Xnf^4SB!Gcxgbw&dySy8q-93ewKCuSsduq0cj<= z^j2peV$;j5oW%P=s3(p3tSlZdGD3YYjx`5M^3 zU@fP4%(OxLLDA&qG#`mwbi{D@e4^pMjp3(2_ zC9ix7IB~&!!{F-ciD1{)`OoC@2ZNQ=wEG@2%12sB+A|EYU}R1{|E;30fx+QwnfIV< z-}zfEu4&v;-*pO4#aCWc5s_B4@A81Haaekbp`UAOPra^wsDkG1)_gK4T+Ey5#ZI9S;vq(NbKuou z5v1$wlkQi^y`w>~oYMD^`hv=aIK4tfGvj?k3KSCNAu-e8K7<+VX|XZ;$O!qCCHZQs zEh^A+k5Brjv|W6!mmb>DK;vfG2q$ZKxvEfIKpU=MCG}0 z&Mov2eR>OKxzn>MXd_dtgg(|+7oRfhSKOLxcl&nDxvtKm8`%1>^~1_2jq8VQ(pT`C zrmJ7s+%)}?U3tjBFxwUAl>YCpk>{9|FHd1A?5M3Lv zCP$VJNGZBy`kYU>wJL7CjRj&2L<%bE-rwUn+E;Z{mXcZyYZah_J)Zh>C#Lgv7F*Lt zkB!+P1ico21#OBh+}e1g_)j+qFOv#%!}0#}YQHrjU`|YLz45@s(d*t@+)iefumP2Q zO4XkLgFt7+fIH$AWU3n>@)c6rs{j5&iMYEtl`M17!bn48F`aVanNyT7OJ#3Ae@ z${8QE@EFYO;;EYZpBo#vV;L(6iAyQzaDA0fIH0QV5~@wEyuE0x(=F^P@(p8mw##^k zh73oGPTO95lT)ze$%<%D_35!cve0#BcOJ({D275yyIWL-*5}m3r zd)w7_cyl()rny@1z~8;^P2xt>ciyDk^JkYXGrF}OX-=u@PQsN01n-uW;* z^p86p$4s=FjxPr6$ll20=b;BSm^y$NsfS754i6UT^~`@oS7^6U4a1|1vLLzTn8582 zCd^?gzSk8Ixzb&^%DdJ*#IV!s3EkLpHucf{7Df34%0Q5(+#pwG`@zqr5Lmg^)zm@p&aH!&#c1s!yn(G=#qPIOZNKRu zI`}Bwnq`qfY&xUd!;xQLqode2KC-oG=6R!Cbf=om6_KA8L}E=X@tB7L@MDrfnTisQ z-5{V)8clYMbK>C)9SyJq7l#VBIf4O>H%gS@=(tB2=n#>nL?p5Sg{(mtdql-SWn7Rb zWZjS+&QPzrtEblNiOCa_caA$dcN)&&t9d&e`*DtV9#)r!>(_rw7_FB?)iVG9 diff --git a/custom-pmd/src/main/java/org/baeldung/pmd/UnitTestNamingConventionRule.java b/custom-pmd/src/main/java/org/baeldung/pmd/UnitTestNamingConventionRule.java index 4136165b6f..9a2795b581 100644 --- a/custom-pmd/src/main/java/org/baeldung/pmd/UnitTestNamingConventionRule.java +++ b/custom-pmd/src/main/java/org/baeldung/pmd/UnitTestNamingConventionRule.java @@ -14,17 +14,16 @@ public class UnitTestNamingConventionRule extends AbstractJavaRule { "ManualTest", "JdbcTest", "LiveTest", - "UnitTest"); + "UnitTest", + "jmhTest"); public Object visit(ASTClassOrInterfaceDeclaration node, Object data) { String className = node.getImage(); Objects.requireNonNull(className); - if (className.endsWith("Test") || className.endsWith("Tests")) { - if (allowedEndings.stream() - .noneMatch(className::endsWith)) { - addViolation(data, node); - } + if (className.endsWith("Tests") + || (className.endsWith("Test") && allowedEndings.stream().noneMatch(className::endsWith))) { + addViolation(data, node); } return data; From 836722cb0681cf930c6ed5883c94c28dd47fcd38 Mon Sep 17 00:00:00 2001 From: pivovarit Date: Tue, 5 Jun 2018 20:00:15 +0200 Subject: [PATCH 13/15] Rename test --- ... => SingletonSynchronizationIntegrationTest.java} | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) rename patterns/design-patterns/src/test/java/com/baeldung/singleton/synchronization/{SingletonSynchronizationUnitTest.java => SingletonSynchronizationIntegrationTest.java} (94%) diff --git a/patterns/design-patterns/src/test/java/com/baeldung/singleton/synchronization/SingletonSynchronizationUnitTest.java b/patterns/design-patterns/src/test/java/com/baeldung/singleton/synchronization/SingletonSynchronizationIntegrationTest.java similarity index 94% rename from patterns/design-patterns/src/test/java/com/baeldung/singleton/synchronization/SingletonSynchronizationUnitTest.java rename to patterns/design-patterns/src/test/java/com/baeldung/singleton/synchronization/SingletonSynchronizationIntegrationTest.java index 08a70f6056..de3d31ed9f 100644 --- a/patterns/design-patterns/src/test/java/com/baeldung/singleton/synchronization/SingletonSynchronizationUnitTest.java +++ b/patterns/design-patterns/src/test/java/com/baeldung/singleton/synchronization/SingletonSynchronizationIntegrationTest.java @@ -15,7 +15,7 @@ import org.junit.Test; * @author Donato Rimenti * */ -public class SingletonSynchronizationUnitTest { +public class SingletonSynchronizationIntegrationTest { /** * Size of the thread pools used. @@ -33,7 +33,7 @@ public class SingletonSynchronizationUnitTest { @Test public void givenDraconianSingleton_whenMultithreadInstancesEquals_thenTrue() { ExecutorService executor = Executors.newFixedThreadPool(POOL_SIZE); - Set resultSet = Collections.synchronizedSet(new HashSet()); + Set resultSet = Collections.synchronizedSet(new HashSet<>()); // Submits the instantiation tasks. for (int i = 0; i < TASKS_TO_SUBMIT; i++) { @@ -51,7 +51,7 @@ public class SingletonSynchronizationUnitTest { @Test public void givenDclSingleton_whenMultithreadInstancesEquals_thenTrue() { ExecutorService executor = Executors.newFixedThreadPool(POOL_SIZE); - Set resultSet = Collections.synchronizedSet(new HashSet()); + Set resultSet = Collections.synchronizedSet(new HashSet<>()); // Submits the instantiation tasks. for (int i = 0; i < TASKS_TO_SUBMIT; i++) { @@ -69,7 +69,7 @@ public class SingletonSynchronizationUnitTest { @Test public void givenEarlyInitSingleton_whenMultithreadInstancesEquals_thenTrue() { ExecutorService executor = Executors.newFixedThreadPool(POOL_SIZE); - Set resultSet = Collections.synchronizedSet(new HashSet()); + Set resultSet = Collections.synchronizedSet(new HashSet<>()); // Submits the instantiation tasks. for (int i = 0; i < TASKS_TO_SUBMIT; i++) { @@ -87,7 +87,7 @@ public class SingletonSynchronizationUnitTest { @Test public void givenInitOnDemandSingleton_whenMultithreadInstancesEquals_thenTrue() { ExecutorService executor = Executors.newFixedThreadPool(POOL_SIZE); - Set resultSet = Collections.synchronizedSet(new HashSet()); + Set resultSet = Collections.synchronizedSet(new HashSet<>()); // Submits the instantiation tasks. for (int i = 0; i < TASKS_TO_SUBMIT; i++) { @@ -105,7 +105,7 @@ public class SingletonSynchronizationUnitTest { @Test public void givenEnumSingleton_whenMultithreadInstancesEquals_thenTrue() { ExecutorService executor = Executors.newFixedThreadPool(POOL_SIZE); - Set resultSet = Collections.synchronizedSet(new HashSet()); + Set resultSet = Collections.synchronizedSet(new HashSet<>()); // Submits the instantiation tasks. for (int i = 0; i < TASKS_TO_SUBMIT; i++) { From 5c0004c746d2f3d2a8b76baa9fe28b1226888e61 Mon Sep 17 00:00:00 2001 From: Grzegorz Piwowarek Date: Tue, 5 Jun 2018 21:03:30 +0200 Subject: [PATCH 14/15] Update pom.xml (#4412) --- pom.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/pom.xml b/pom.xml index b9fde81102..ed724f7142 100644 --- a/pom.xml +++ b/pom.xml @@ -533,5 +533,4 @@ 1.3 5.0.2 - From be608ae4fb543fbeea0d210218d00cde75c4b6d4 Mon Sep 17 00:00:00 2001 From: Devesh Chanchlani Date: Wed, 6 Jun 2018 03:20:26 +0400 Subject: [PATCH 15/15] BAEL-1758: Working with Enums in Kotlin (#4413) --- .../kotlin/com/baeldung/enums/CardType.kt | 33 ++++++++++++ .../com/baeldung/enums/CardTypeHelper.kt | 16 ++++++ .../kotlin/com/baeldung/enums/ICardLimit.kt | 5 ++ .../baeldung/enums/CardTypeHelperUnitTest.kt | 43 +++++++++++++++ .../com/baeldung/enums/CardTypeUnitTest.kt | 52 +++++++++++++++++++ 5 files changed, 149 insertions(+) create mode 100644 core-kotlin/src/main/kotlin/com/baeldung/enums/CardType.kt create mode 100644 core-kotlin/src/main/kotlin/com/baeldung/enums/CardTypeHelper.kt create mode 100644 core-kotlin/src/main/kotlin/com/baeldung/enums/ICardLimit.kt create mode 100644 core-kotlin/src/test/kotlin/com/baeldung/enums/CardTypeHelperUnitTest.kt create mode 100644 core-kotlin/src/test/kotlin/com/baeldung/enums/CardTypeUnitTest.kt diff --git a/core-kotlin/src/main/kotlin/com/baeldung/enums/CardType.kt b/core-kotlin/src/main/kotlin/com/baeldung/enums/CardType.kt new file mode 100644 index 0000000000..ae0c707289 --- /dev/null +++ b/core-kotlin/src/main/kotlin/com/baeldung/enums/CardType.kt @@ -0,0 +1,33 @@ +package com.baeldung.enums + +enum class CardType(val color: String) : ICardLimit { + SILVER("gray") { + override fun getCreditLimit(): Int { + return 100000 + } + + override fun calculateCashbackPercent(): Float { + return 0.25f + } + }, + GOLD("yellow") { + override fun getCreditLimit(): Int { + return 200000 + } + + override fun calculateCashbackPercent(): Float { + return 0.5f + } + }, + PLATINUM("black") { + override fun getCreditLimit(): Int { + return 300000 + } + + override fun calculateCashbackPercent(): Float { + return 0.75f + } + }; + + abstract fun calculateCashbackPercent(): Float +} \ No newline at end of file diff --git a/core-kotlin/src/main/kotlin/com/baeldung/enums/CardTypeHelper.kt b/core-kotlin/src/main/kotlin/com/baeldung/enums/CardTypeHelper.kt new file mode 100644 index 0000000000..29982192bb --- /dev/null +++ b/core-kotlin/src/main/kotlin/com/baeldung/enums/CardTypeHelper.kt @@ -0,0 +1,16 @@ +package com.baeldung.enums + +class CardTypeHelper { + fun getCardTypeByColor(color: String): CardType? { + for (cardType in CardType.values()) { + if (cardType.color.equals(color)) { + return cardType; + } + } + return null + } + + fun getCardTypeByName(name: String): CardType { + return CardType.valueOf(name.toUpperCase()) + } +} \ No newline at end of file diff --git a/core-kotlin/src/main/kotlin/com/baeldung/enums/ICardLimit.kt b/core-kotlin/src/main/kotlin/com/baeldung/enums/ICardLimit.kt new file mode 100644 index 0000000000..7994822a52 --- /dev/null +++ b/core-kotlin/src/main/kotlin/com/baeldung/enums/ICardLimit.kt @@ -0,0 +1,5 @@ +package com.baeldung.enums + +interface ICardLimit { + fun getCreditLimit(): Int +} \ No newline at end of file diff --git a/core-kotlin/src/test/kotlin/com/baeldung/enums/CardTypeHelperUnitTest.kt b/core-kotlin/src/test/kotlin/com/baeldung/enums/CardTypeHelperUnitTest.kt new file mode 100644 index 0000000000..8fcd281784 --- /dev/null +++ b/core-kotlin/src/test/kotlin/com/baeldung/enums/CardTypeHelperUnitTest.kt @@ -0,0 +1,43 @@ +package com.baeldung.enums + +import org.junit.jupiter.api.Assertions +import org.junit.jupiter.api.Test + +internal class CardTypeHelperUnitTest { + + @Test + fun whenGetCardTypeByColor_thenSilverCardType() { + val cardTypeHelper = CardTypeHelper() + Assertions.assertEquals(CardType.SILVER, cardTypeHelper.getCardTypeByColor("gray")) + } + + @Test + fun whenGetCardTypeByColor_thenGoldCardType() { + val cardTypeHelper = CardTypeHelper() + Assertions.assertEquals(CardType.GOLD, cardTypeHelper.getCardTypeByColor("yellow")) + } + + @Test + fun whenGetCardTypeByColor_thenPlatinumCardType() { + val cardTypeHelper = CardTypeHelper() + Assertions.assertEquals(CardType.PLATINUM, cardTypeHelper.getCardTypeByColor("black")) + } + + @Test + fun whenGetCardTypeByName_thenSilverCardType() { + val cardTypeHelper = CardTypeHelper() + Assertions.assertEquals(CardType.SILVER, cardTypeHelper.getCardTypeByName("silver")) + } + + @Test + fun whenGetCardTypeByName_thenGoldCardType() { + val cardTypeHelper = CardTypeHelper() + Assertions.assertEquals(CardType.GOLD, cardTypeHelper.getCardTypeByName("gold")) + } + + @Test + fun whenGetCardTypeByName_thenPlatinumCardType() { + val cardTypeHelper = CardTypeHelper() + Assertions.assertEquals(CardType.PLATINUM, cardTypeHelper.getCardTypeByName("platinum")) + } +} diff --git a/core-kotlin/src/test/kotlin/com/baeldung/enums/CardTypeUnitTest.kt b/core-kotlin/src/test/kotlin/com/baeldung/enums/CardTypeUnitTest.kt new file mode 100644 index 0000000000..0e74e1cf56 --- /dev/null +++ b/core-kotlin/src/test/kotlin/com/baeldung/enums/CardTypeUnitTest.kt @@ -0,0 +1,52 @@ +package com.baeldung.enums + +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Test + +internal class CardTypeUnitTest { + + @Test + fun givenSilverCardType_whenCalculateCashbackPercent_thenReturnCashbackValue() { + assertEquals(0.25f, CardType.SILVER.calculateCashbackPercent()) + } + + @Test + fun givenGoldCardType_whenCalculateCashbackPercent_thenReturnCashbackValue() { + assertEquals(0.5f, CardType.GOLD.calculateCashbackPercent()) + } + + @Test + fun givenPlatinumCardType_whenCalculateCashbackPercent_thenReturnCashbackValue() { + assertEquals(0.75f, CardType.PLATINUM.calculateCashbackPercent()) + } + + @Test + fun givenSilverCardType_whenGetCreditLimit_thenReturnCreditLimit() { + assertEquals(100000, CardType.SILVER.getCreditLimit()) + } + + @Test + fun givenGoldCardType_whenGetCreditLimit_thenReturnCreditLimit() { + assertEquals(200000, CardType.GOLD.getCreditLimit()) + } + + @Test + fun givenPlatinumCardType_whenGetCreditLimit_thenReturnCreditLimit() { + assertEquals(300000, CardType.PLATINUM.getCreditLimit()) + } + + @Test + fun givenSilverCardType_whenCheckColor_thenReturnColor() { + assertEquals("gray", CardType.SILVER.color) + } + + @Test + fun givenGoldCardType_whenCheckColor_thenReturnColor() { + assertEquals("yellow", CardType.GOLD.color) + } + + @Test + fun givenPlatinumCardType_whenCheckColor_thenReturnColor() { + assertEquals("black", CardType.PLATINUM.color) + } +}