merge upstream

This commit is contained in:
Jon Cook 2019-03-02 22:41:25 +01:00
commit 96adba789d
265 changed files with 17380 additions and 676 deletions

View File

@ -41,7 +41,6 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<akka.http.version>10.0.11</akka.http.version>
<akka.stream.version>2.5.11</akka.stream.version>
</properties>

View File

@ -54,7 +54,6 @@
</build>
<properties>
<lombok.version>1.16.12</lombok.version>
<commons-math3.version>3.6.1</commons-math3.version>
<io.jenetics.version>3.7.0</io.jenetics.version>
<org.assertj.core.version>3.9.0</org.assertj.core.version>

View File

@ -74,7 +74,6 @@
</reporting>
<properties>
<lombok.version>1.16.12</lombok.version>
<commons-math3.version>3.6.1</commons-math3.version>
<org.assertj.core.version>3.9.0</org.assertj.core.version>
<commons-codec.version>1.11</commons-codec.version>

View File

@ -84,7 +84,6 @@
</reporting>
<properties>
<lombok.version>1.16.12</lombok.version>
<commons-math3.version>3.6.1</commons-math3.version>
<tradukisto.version>1.0.1</tradukisto.version>
<org.jgrapht.core.version>1.0.1</org.jgrapht.core.version>

View File

@ -49,7 +49,6 @@
</build>
<properties>
<lombok.version>1.16.12</lombok.version>
<commons-math3.version>3.6.1</commons-math3.version>
<org.assertj.core.version>3.9.0</org.assertj.core.version>
<commons-codec.version>1.11</commons-codec.version>

View File

@ -82,7 +82,6 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<compiler-plugin.version>3.5</compiler-plugin.version>
<avro.version>1.8.2</avro.version>
<java.version>1.8</java.version>
<slf4j.version>1.7.25</slf4j.version>
</properties>

View File

@ -39,7 +39,7 @@
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson-databind.version}</version>
<version>${jackson.version}</version>
</dependency>
<!-- test scoped -->
<dependency>
@ -59,7 +59,6 @@
<properties>
<curator.version>4.0.1</curator.version>
<zookeeper.version>3.4.11</zookeeper.version>
<jackson-databind.version>2.9.7</jackson-databind.version>
<!-- testing -->
<assertj.version>3.6.1</assertj.version>
<avaitility.version>1.7.0</avaitility.version>

View File

@ -32,8 +32,8 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
</plugins>
@ -41,7 +41,5 @@
<properties>
<geode.core>1.6.0</geode.core>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
</project>

View File

@ -56,8 +56,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
@ -85,8 +85,6 @@
<org.apache.spark.spark-streaming-kafka.version>2.3.0</org.apache.spark.spark-streaming-kafka.version>
<com.datastax.spark.spark-cassandra-connector.version>2.3.0</com.datastax.spark.spark-cassandra-connector.version>
<com.datastax.spark.spark-cassandra-connector-java.version>1.5.2</com.datastax.spark.spark-cassandra-connector-java.version>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven-compiler-plugin.version>3.2</maven-compiler-plugin.version>
</properties>

View File

@ -127,7 +127,6 @@
<docker.image.prefix>${azure.containerRegistry}.azurecr.io</docker.image.prefix>
<docker-maven-plugin.version>1.1.0</docker-maven-plugin.version>
<azure-webapp-maven-plugin.version>1.1.0</azure-webapp-maven-plugin.version>
<java.version>1.8</java.version>
</properties>
</project>

View File

@ -66,7 +66,6 @@
<aspectjweaver.version>1.9.2</aspectjweaver.version>
<hamcrest-core.version>1.3</hamcrest-core.version>
<assertj-core.version>3.10.0</assertj-core.version>
<junit.version>4.12</junit.version>
<spring.version>5.1.2.RELEASE</spring.version>
</properties>
</project>

View File

@ -23,6 +23,12 @@
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>${groovy-all.version}</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-dateutil</artifactId>
<version>${groovy.version}</version>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
@ -103,9 +109,12 @@
<properties>
<junit.platform.version>1.0.0</junit.platform.version>
<groovy.version>2.4.13</groovy.version>
<groovy-all.version>2.4.13</groovy-all.version>
<groovy-sql.version>2.4.13</groovy-sql.version>
<!-- <groovy.version>2.4.13</groovy.version> -->
<!-- <groovy-all.version>2.4.13</groovy-all.version> -->
<!-- <groovy-sql.version>2.4.13</groovy-sql.version> -->
<groovy.version>2.5.6</groovy.version>
<groovy-all.version>2.5.6</groovy-all.version>
<groovy-sql.version>2.5.6</groovy-sql.version>
<hsqldb.version>2.4.0</hsqldb.version>
<spock-core.version>1.1-groovy-2.4</spock-core.version>
<gmavenplus-plugin.version>1.6</gmavenplus-plugin.version>

View File

@ -0,0 +1,57 @@
package com.baeldung.groovy.sql
import static org.junit.Assert.*
import java.util.Calendar.*
import java.time.LocalDate
import java.text.SimpleDateFormat
import org.junit.Test
class DateTest {
def dateStr = "2019-02-28"
def pattern = "yyyy-MM-dd"
@Test
void whenGetStringRepresentation_thenCorrectlyConvertIntoDate() {
def dateFormat = new SimpleDateFormat(pattern)
def date = dateFormat.parse(dateStr)
println(" String to Date with DateFormatter : " + date)
def cal = new GregorianCalendar();
cal.setTime(date);
assertEquals(cal.get(Calendar.YEAR),2019)
assertEquals(cal.get(Calendar.DAY_OF_MONTH),28)
assertEquals(cal.get(Calendar.MONTH),java.util.Calendar.FEBRUARY)
}
@Test
void whenGetStringRepresentation_thenCorrectlyConvertWithDateUtilsExtension() {
def date = Date.parse(pattern, dateStr)
println(" String to Date with Date.parse : " + date)
def cal = new GregorianCalendar();
cal.setTime(date);
assertEquals(cal.get(Calendar.YEAR),2019)
assertEquals(cal.get(Calendar.DAY_OF_MONTH),28)
assertEquals(cal.get(Calendar.MONTH),java.util.Calendar.FEBRUARY)
}
@Test
void whenGetStringRepresentation_thenCorrectlyConvertIntoDateWithLocalDate() {
def date = LocalDate.parse(dateStr, pattern)
println(" String to Date with LocalDate : " + date)
assertEquals(date.getYear(),2019)
assertEquals(date.getMonth(),java.time.Month.FEBRUARY)
assertEquals(date.getDayOfMonth(),28)
}
}

View File

@ -0,0 +1,18 @@
package com.baeldung.epsilongc;
public class MemoryPolluter {
private static final int MEGABYTE_IN_BYTES = 1024 * 1024;
private static final int ITERATION_COUNT = 1024 * 10;
public static void main(String[] args) {
System.out.println("Starting pollution");
for (int i = 0; i < ITERATION_COUNT; i++) {
byte[] array = new byte[MEGABYTE_IN_BYTES];
}
System.out.println("Terminating");
}
}

View File

@ -180,7 +180,6 @@
<commons-collections4.version>4.1</commons-collections4.version>
<collections-generic.version>4.01</collections-generic.version>
<commons-codec.version>1.10</commons-codec.version>
<lombok.version>1.16.12</lombok.version>
<vavr.version>0.9.0</vavr.version>
<protonpack.version>1.13</protonpack.version>
<joda.version>2.10</joda.version>

View File

@ -0,0 +1,62 @@
package com.baeldung.streamreduce.application;
import com.baeldung.streamreduce.entities.User;
import com.baeldung.streamreduce.utilities.NumberUtils;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class Application {
public static void main(String[] args) {
List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5, 6);
int result1 = numbers.stream().reduce(0, (a, b) -> a + b);
System.out.println(result1);
int result2 = numbers.stream().reduce(0, Integer::sum);
System.out.println(result2);
List<String> letters = Arrays.asList("a", "b", "c", "d", "e");
String result3 = letters.stream().reduce("", (a, b) -> a + b);
System.out.println(result3);
String result4 = letters.stream().reduce("", String::concat);
System.out.println(result4);
String result5 = letters.stream().reduce("", (a, b) -> a.toUpperCase() + b.toUpperCase());
System.out.println(result5);
List<User> users = Arrays.asList(new User("John", 30), new User("Julie", 35));
int result6 = users.stream().reduce(0, (partialAgeResult, user) -> partialAgeResult + user.getAge(), Integer::sum);
System.out.println(result6);
String result7 = letters.parallelStream().reduce("", String::concat);
System.out.println(result7);
int result8 = users.parallelStream().reduce(0, (partialAgeResult, user) -> partialAgeResult + user.getAge(), Integer::sum);
System.out.println(result8);
List<User> userList = new ArrayList<>();
for (int i = 0; i <= 1000000; i++) {
userList.add(new User("John" + i, i));
}
long t1 = System.currentTimeMillis();
int result9 = userList.stream().reduce(0, (partialAgeResult, user) -> partialAgeResult + user.getAge(), Integer::sum);
long t2 = System.currentTimeMillis();
System.out.println(result9);
System.out.println("Sequential stream time: " + (t2 - t1) + "ms");
long t3 = System.currentTimeMillis();
int result10 = userList.parallelStream().reduce(0, (partialAgeResult, user) -> partialAgeResult + user.getAge(), Integer::sum);
long t4 = System.currentTimeMillis();
System.out.println(result10);
System.out.println("Parallel stream time: " + (t4 - t3) + "ms");
int result11 = NumberUtils.divideListElements(numbers, 1);
System.out.println(result11);
int result12 = NumberUtils.divideListElementsWithExtractedTryCatchBlock(numbers, 0);
System.out.println(result12);
}
}

View File

@ -0,0 +1,25 @@
package com.baeldung.streamreduce.entities;
public class User {
private final String name;
private final int age;
public User(String name, int age) {
this.name = name;
this.age = age;
}
public String getName() {
return name;
}
public int getAge() {
return age;
}
@Override
public String toString() {
return "User{" + "name=" + name + ", age=" + age + '}';
}
}

View File

@ -0,0 +1,52 @@
package com.baeldung.streamreduce.utilities;
import java.util.List;
import java.util.function.BiFunction;
import java.util.logging.Level;
import java.util.logging.Logger;
public abstract class NumberUtils {
private static final Logger LOGGER = Logger.getLogger(NumberUtils.class.getName());
public static int divideListElements(List<Integer> values, Integer divider) {
return values.stream()
.reduce(0, (a, b) -> {
try {
return a / divider + b / divider;
} catch (ArithmeticException e) {
LOGGER.log(Level.INFO, "Arithmetic Exception: Division by Zero");
}
return 0;
});
}
public static int divideListElementsWithExtractedTryCatchBlock(List<Integer> values, int divider) {
return values.stream().reduce(0, (a, b) -> divide(a, divider) + divide(b, divider));
}
public static int divideListElementsWithApplyFunctionMethod(List<Integer> values, int divider) {
BiFunction<Integer, Integer, Integer> division = (a, b) -> a / b;
return values.stream().reduce(0, (a, b) -> applyFunction(division, a, divider) + applyFunction(division, b, divider));
}
private static int divide(int value, int factor) {
int result = 0;
try {
result = value / factor;
} catch (ArithmeticException e) {
LOGGER.log(Level.INFO, "Arithmetic Exception: Division by Zero");
}
return result;
}
private static int applyFunction(BiFunction<Integer, Integer, Integer> function, int a, int b) {
try {
return function.apply(a, b);
}
catch(Exception e) {
LOGGER.log(Level.INFO, "Exception occurred!");
}
return 0;
}
}

View File

@ -0,0 +1,126 @@
package com.baeldung.streamreduce.tests;
import com.baeldung.streamreduce.entities.User;
import com.baeldung.streamreduce.utilities.NumberUtils;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.Test;
public class StreamReduceManualTest {
@Test
public void givenIntegerList_whenReduceWithSumAccumulatorLambda_thenCorrect() {
List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5, 6);
int result = numbers.stream().reduce(0, (a, b) -> a + b);
assertThat(result).isEqualTo(21);
}
@Test
public void givenIntegerList_whenReduceWithSumAccumulatorMethodReference_thenCorrect() {
List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5, 6);
int result = numbers.stream().reduce(0, Integer::sum);
assertThat(result).isEqualTo(21);
}
@Test
public void givenStringList_whenReduceWithConcatenatorAccumulatorLambda_thenCorrect() {
List<String> letters = Arrays.asList("a", "b", "c", "d", "e");
String result = letters.stream().reduce("", (a, b) -> a + b);
assertThat(result).isEqualTo("abcde");
}
@Test
public void givenStringList_whenReduceWithConcatenatorAccumulatorMethodReference_thenCorrect() {
List<String> letters = Arrays.asList("a", "b", "c", "d", "e");
String result = letters.stream().reduce("", String::concat);
assertThat(result).isEqualTo("abcde");
}
@Test
public void givenStringList_whenReduceWithUppercaseConcatenatorAccumulator_thenCorrect() {
List<String> letters = Arrays.asList("a", "b", "c", "d", "e");
String result = letters.stream().reduce("", (a, b) -> a.toUpperCase() + b.toUpperCase());
assertThat(result).isEqualTo("ABCDE");
}
@Test
public void givenUserList_whenReduceWithAgeAccumulatorAndSumCombiner_thenCorrect() {
List<User> users = Arrays.asList(new User("John", 30), new User("Julie", 35));
int result = users.stream().reduce(0, (partialAgeResult, user) -> partialAgeResult + user.getAge(), Integer::sum);
assertThat(result).isEqualTo(65);
}
@Test
public void givenStringList_whenReduceWithParallelStream_thenCorrect() {
List<String> letters = Arrays.asList("a", "b", "c", "d", "e");
String result = letters.parallelStream().reduce("", String::concat);
assertThat(result).isEqualTo("abcde");
}
@Test
public void givenNumberUtilsClass_whenCalledDivideListElements_thenCorrect() {
List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5, 6);
assertThat(NumberUtils.divideListElements(numbers, 1)).isEqualTo(21);
}
@Test
public void givenNumberUtilsClass_whenCalledDivideListElementsWithExtractedTryCatchBlock_thenCorrect() {
List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5, 6);
assertThat(NumberUtils.divideListElementsWithExtractedTryCatchBlock(numbers, 1)).isEqualTo(21);
}
@Test
public void givenNumberUtilsClass_whenCalledDivideListElementsWithExtractedTryCatchBlockAndListContainsZero_thenCorrect() {
List<Integer> numbers = Arrays.asList(0, 1, 2, 3, 4, 5, 6);
assertThat(NumberUtils.divideListElementsWithExtractedTryCatchBlock(numbers, 1)).isEqualTo(21);
}
@Test
public void givenNumberUtilsClass_whenCalledDivideListElementsWithExtractedTryCatchBlockAndDividerIsZero_thenCorrect() {
List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5, 6);
assertThat(NumberUtils.divideListElementsWithExtractedTryCatchBlock(numbers, 0)).isEqualTo(0);
}
@Test
public void givenStream_whneCalleddivideListElementsWithApplyFunctionMethod_thenCorrect() {
List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5, 6);
assertThat(NumberUtils.divideListElementsWithApplyFunctionMethod(numbers, 1)).isEqualTo(21);
}
@Test
public void givenTwoStreams_whenCalledReduceOnParallelizedStream_thenFasterExecutionTime() {
List<User> userList = new ArrayList<>();
for (int i = 0; i <= 1000000; i++) {
userList.add(new User("John" + i, i));
}
long currentTime1 = System.currentTimeMillis();
userList.stream().reduce(0, (partialAgeResult, user) -> partialAgeResult + user.getAge(), Integer::sum);
long sequentialExecutionTime = System.currentTimeMillis() -currentTime1;
long currentTime2 = System.currentTimeMillis();
userList.parallelStream().reduce(0, (partialAgeResult, user) -> partialAgeResult + user.getAge(), Integer::sum);
long parallelizedExecutionTime = System.currentTimeMillis() - currentTime2;
assertThat(parallelizedExecutionTime).isLessThan(sequentialExecutionTime);
}
}

View File

@ -390,7 +390,6 @@
<!-- util -->
<commons-lang3.version>3.8.1</commons-lang3.version>
<lombok.version>1.16.12</lombok.version>
<jmh-core.version>1.19</jmh-core.version>
<jmh-generator-annprocess.version>1.19</jmh-generator-annprocess.version>

View File

@ -27,3 +27,4 @@
- [Flattening Nested Collections in Java](http://www.baeldung.com/java-flatten-nested-collections)
- [Intersection of Two Lists in Java](https://www.baeldung.com/java-lists-intersection)
- [Multi Dimensional ArrayList in Java](https://www.baeldung.com/java-multi-dimensional-arraylist)
- [Determine If All Elements Are the Same in a Java List](https://www.baeldung.com/java-list-all-equal)

View File

@ -70,7 +70,6 @@
<commons-lang3.version>3.8.1</commons-lang3.version>
<avaitility.version>1.7.0</avaitility.version>
<assertj.version>3.11.1</assertj.version>
<lombok.version>1.16.12</lombok.version>
<trove4j.version>3.0.2</trove4j.version>
<fastutil.version>8.1.0</fastutil.version>
<colt.version>1.2.0</colt.version>

View File

@ -73,7 +73,6 @@
<avaitility.version>1.7.0</avaitility.version>
<assertj.version>3.11.1</assertj.version>
<eclipse.collections.version>7.1.0</eclipse.collections.version>
<lombok.version>1.16.12</lombok.version>
<commons-exec.version>1.3</commons-exec.version>
</properties>
</project>

View File

@ -246,8 +246,6 @@
</profiles>
<properties>
<!-- marshalling -->
<jackson.version>2.9.7</jackson.version>
<!-- util -->
<commons-lang3.version>3.5</commons-lang3.version>
@ -259,7 +257,6 @@
<collections-generic.version>4.01</collections-generic.version>
<unix4j.version>0.4</unix4j.version>
<grep4j.version>1.8.7</grep4j.version>
<lombok.version>1.16.12</lombok.version>
<fscontext.version>4.6-b01</fscontext.version>
<protonpack.version>1.13</protonpack.version>
<streamex.version>0.6.5</streamex.version>

View File

@ -82,7 +82,6 @@
<!-- util -->
<commons-lang3.version>3.5</commons-lang3.version>
<lombok.version>1.16.12</lombok.version>
<!-- testing -->
<assertj-core.version>3.10.0</assertj-core.version>
<equalsverifier.version>3.0.3</equalsverifier.version>

View File

@ -74,14 +74,10 @@
</build>
<properties>
<!-- marshalling -->
<jackson.version>2.9.7</jackson.version>
<gson.version>2.8.2</gson.version>
<!-- util -->
<commons-lang3.version>3.5</commons-lang3.version>
<lombok.version>1.16.12</lombok.version>
<javax.mail.version>1.5.0-b01</javax.mail.version>

View File

@ -14,3 +14,4 @@
- [A Guide to Java Sockets](http://www.baeldung.com/a-guide-to-java-sockets)
- [URL Encoding and Decoding in Java](http://www.baeldung.com/java-url-encoding-decoding)
- [How to Perform a Simple HTTP Request in Java](http://www.baeldung.com/java-http-request)
- [Difference between URL and URI](http://www.baeldung.com/java-url-vs-uri)

View File

@ -261,8 +261,6 @@
</profiles>
<properties>
<!-- marshalling -->
<jackson.version>2.9.7</jackson.version>
<!-- util -->
<guava.version>23.0</guava.version>
@ -275,7 +273,6 @@
<collections-generic.version>4.01</collections-generic.version>
<unix4j.version>0.4</unix4j.version>
<grep4j.version>1.8.7</grep4j.version>
<lombok.version>1.16.12</lombok.version>
<fscontext.version>4.6-b01</fscontext.version>
<protonpack.version>1.13</protonpack.version>
<streamex.version>0.6.5</streamex.version>

View File

@ -19,7 +19,6 @@
- [Introduction to Java Serialization](http://www.baeldung.com/java-serialization)
- [Guide to UUID in Java](http://www.baeldung.com/java-uuid)
- [Guide to Escaping Characters in Java RegExps](http://www.baeldung.com/java-regexp-escape-char)
- [Difference between URL and URI](http://www.baeldung.com/java-url-vs-uri)
- [Creating a Java Compiler Plugin](http://www.baeldung.com/java-build-compiler-plugin)
- [Quick Guide to Java Stack](http://www.baeldung.com/java-stack)
- [Compiling Java *.class Files with javac](http://www.baeldung.com/javac)

View File

@ -451,7 +451,6 @@
<properties>
<!-- marshalling -->
<jackson.version>2.9.7</jackson.version>
<gson.version>2.8.2</gson.version>
<!-- util -->
@ -461,7 +460,6 @@
<decimal4j.version>1.0.3</decimal4j.version>
<unix4j.version>0.4</unix4j.version>
<grep4j.version>1.8.7</grep4j.version>
<lombok.version>1.16.12</lombok.version>
<fscontext.version>4.6-b01</fscontext.version>
<protonpack.version>1.13</protonpack.version>
<streamex.version>0.6.5</streamex.version>

View File

@ -0,0 +1,46 @@
package com.baeldung.urlconnection;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
public class PostJSONWithHttpURLConnection {
public static void main (String []args) throws IOException{
//Change the URL with any other publicly accessible POST resource, which accepts JSON request body
URL url = new URL ("https://reqres.in/api/users");
HttpURLConnection con = (HttpURLConnection)url.openConnection();
con.setRequestMethod("POST");
con.setRequestProperty("Content-Type", "application/json; utf-8");
con.setRequestProperty("Accept", "application/json");
con.setDoOutput(true);
//JSON String need to be constructed for the specific resource.
//We may construct complex JSON using any third-party JSON libraries such as jackson or org.json
String jsonInputString = "{\"name\": \"Upendra\", \"job\": \"Programmer\"}";
try(OutputStream os = con.getOutputStream()){
byte[] input = jsonInputString.getBytes("utf-8");
os.write(input, 0, input.length);
}
int code = con.getResponseCode();
System.out.println(code);
try(BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream(), "utf-8"))){
StringBuilder response = new StringBuilder();
String responseLine = null;
while ((responseLine = br.readLine()) != null) {
response.append(responseLine.trim());
}
System.out.println(response.toString());
}
}
}

View File

@ -1 +1,3 @@
## Relevant articles:
- [Void Type in Kotlin](https://www.baeldung.com/kotlin-void-type)

View File

@ -0,0 +1,47 @@
package stringcomparison
import org.junit.Test
import kotlin.test.assertFalse
import kotlin.test.assertTrue
class StringComparisonUnitTest {
@Test
fun `compare using equals operator`() {
val first = "kotlin"
val second = "kotlin"
val firstCapitalized = "KOTLIN"
assertTrue { first == second }
assertFalse { first == firstCapitalized }
}
@Test
fun `compare using referential equals operator`() {
val first = "kotlin"
val second = "kotlin"
val copyOfFirst = buildString { "kotlin" }
assertTrue { first === second }
assertFalse { first === copyOfFirst }
}
@Test
fun `compare using equals method`() {
val first = "kotlin"
val second = "kotlin"
val firstCapitalized = "KOTLIN"
assertTrue { first.equals(second) }
assertFalse { first.equals(firstCapitalized) }
assertTrue { first.equals(firstCapitalized, true) }
}
@Test
fun `compare using compare method`() {
val first = "kotlin"
val second = "kotlin"
val firstCapitalized = "KOTLIN"
assertTrue { first.compareTo(second) == 0 }
assertTrue { first.compareTo(firstCapitalized) == 32 }
assertTrue { firstCapitalized.compareTo(first) == -32 }
assertTrue { first.compareTo(firstCapitalized, true) == 0 }
}
}

View File

@ -0,0 +1,114 @@
package com.baeldung.kotlin.dsl
abstract class Condition {
fun and(initializer: Condition.() -> Unit) {
addCondition(And().apply(initializer))
}
fun or(initializer: Condition.() -> Unit) {
addCondition(Or().apply(initializer))
}
infix fun String.eq(value: Any?) {
addCondition(Eq(this, value))
}
protected abstract fun addCondition(condition: Condition)
}
open class CompositeCondition(private val sqlOperator: String) : Condition() {
private val conditions = mutableListOf<Condition>()
override fun addCondition(condition: Condition) {
conditions += condition
}
override fun toString(): String {
return if (conditions.size == 1) {
conditions.first().toString()
} else {
conditions.joinToString(prefix = "(", postfix = ")", separator = " $sqlOperator ") {
"$it"
}
}
}
}
class And : CompositeCondition("and")
class Or : CompositeCondition("or")
class Eq(private val column: String, private val value: Any?) : Condition() {
init {
if (value != null && value !is Number && value !is String) {
throw IllegalArgumentException("Only <null>, numbers and strings values can be used in the 'where' clause")
}
}
override fun addCondition(condition: Condition) {
throw IllegalStateException("Can't add a nested condition to the sql 'eq'")
}
override fun toString(): String {
return when (value) {
null -> "$column is null"
is String -> "$column = '$value'"
else -> "$column = $value"
}
}
}
class SqlSelectBuilder {
private val columns = mutableListOf<String>()
private lateinit var table: String
private var condition: Condition? = null
fun select(vararg columns: String) {
if (columns.isEmpty()) {
throw IllegalArgumentException("At least one column should be defined")
}
if (this.columns.isNotEmpty()) {
throw IllegalStateException("Detected an attempt to re-define columns to fetch. Current columns list: "
+ "${this.columns}, new columns list: $columns")
}
this.columns.addAll(columns)
}
fun from(table: String) {
this.table = table
}
fun where(initializer: Condition.() -> Unit) {
condition = And().apply(initializer)
}
fun build(): String {
if (!::table.isInitialized) {
throw IllegalStateException("Failed to build an sql select - target table is undefined")
}
return toString()
}
override fun toString(): String {
val columnsToFetch =
if (columns.isEmpty()) {
"*"
} else {
columns.joinToString(", ")
}
val conditionString =
if (condition == null) {
""
} else {
" where $condition"
}
return "select $columnsToFetch from $table$conditionString"
}
}
fun query(initializer: SqlSelectBuilder.() -> Unit): SqlSelectBuilder {
return SqlSelectBuilder().apply(initializer)
}

View File

@ -0,0 +1,74 @@
package com.baeldung.kotlin.dsl
import org.assertj.core.api.Assertions.assertThat
import org.junit.Test
import java.lang.Exception
class SqlDslTest {
@Test
fun `when no columns are specified then star is used`() {
doTest("select * from table1") {
from ("table1")
}
}
@Test
fun `when no condition is specified then correct query is built`() {
doTest("select column1, column2 from table1") {
select("column1", "column2")
from ("table1")
}
}
@Test(expected = Exception::class)
fun `when no table is specified then an exception is thrown`() {
query {
select("column1")
}.build()
}
@Test
fun `when a list of conditions is specified then it's respected`() {
doTest("select * from table1 where (column3 = 4 and column4 is null)") {
from ("table1")
where {
"column3" eq 4
"column4" eq null
}
}
}
@Test
fun `when 'or' conditions are specified then they are respected`() {
doTest("select * from table1 where (column3 = 4 or column4 is null)") {
from ("table1")
where {
or {
"column3" eq 4
"column4" eq null
}
}
}
}
@Test
fun `when either 'and' or 'or' conditions are specified then they are respected`() {
doTest("select * from table1 where ((column3 = 4 or column4 is null) and column5 = 42)") {
from ("table1")
where {
and {
or {
"column3" eq 4
"column4" eq null
}
"column5" eq 42
}
}
}
}
private fun doTest(expected: String, sql: SqlSelectBuilder.() -> Unit) {
assertThat(query(sql).build()).isEqualTo(expected)
}
}

View File

@ -25,7 +25,7 @@
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson-version}</version>
<version>${jackson.version}</version>
</dependency>
<!-- Spring Context for Dependency Injection -->
<dependency>
@ -70,7 +70,6 @@
<couchbase.client.version>2.5.0</couchbase.client.version>
<spring-framework.version>4.3.5.RELEASE</spring-framework.version>
<commons-lang3.version>3.5</commons-lang3.version>
<jackson-version>2.9.7</jackson-version>
</properties>
</project>

View File

@ -9,10 +9,10 @@
<description>DDD series examples</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.6.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
<artifactId>parent-boot-2</artifactId>
<groupId>com.baeldung</groupId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../parent-boot-2</relativePath>
</parent>
<dependencies>
@ -86,6 +86,7 @@
<properties>
<joda-money.version>1.0.1</joda-money.version>
<maven-surefire-plugin.version>2.22.0</maven-surefire-plugin.version>
<spring-boot.version>2.0.6.RELEASE</spring-boot.version>
</properties>
</project>

View File

@ -11,7 +11,7 @@ import org.joda.money.Money;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
class OrderTest {
class OrderUnitTest {
@DisplayName("given order with two items, when calculate total cost, then sum is returned")
@Test
void test0() throws Exception {

View File

@ -7,7 +7,7 @@ import java.math.BigDecimal;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
public class ViolateOrderBusinessRulesTest {
public class ViolateOrderBusinessRulesUnitTest {
@DisplayName("given two non-zero order line items, when create an order with them, it's possible to set total cost to zero")
@Test
void test() throws Exception {

View File

@ -208,15 +208,12 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
<tomcat.version>8.5.4</tomcat.version>
<ethereumj-core.version>1.5.0-RELEASE</ethereumj-core.version>
<web3j.core.version>3.3.1</web3j.core.version>
<spring.boot.version>1.5.6.RELEASE</spring.boot.version>
<mockito.version>2.21.0</mockito.version>
<jackson-databind.version>2.9.7</jackson-databind.version>
<hamcrest.version>1.3</hamcrest.version>
<jackson.version>2.9.7</jackson.version>
<javax-jsp.version>2.3.1</javax-jsp.version>
<javax-servlet.version>3.1.0</javax-servlet.version>
<jsonpath.version>2.4.0</jsonpath.version>

View File

@ -56,7 +56,6 @@
<properties>
<feign.version>9.4.0</feign.version>
<lombok.version>1.16.12</lombok.version>
<spring-boot-maven-plugin.version>1.4.2.RELEASE</spring-boot-maven-plugin.version>
</properties>

View File

@ -33,24 +33,11 @@
</dependencies>
<repositories>
<repository>
<id>maven2-repository.dev.java.net</id>
<name>Java.net repository</name>
<url>http://download.java.net/maven/2</url>
</repository>
<repository>
<id>osgeo</id>
<name>Open Source Geospatial Foundation Repository</name>
<url>http://download.osgeo.org/webdav/geotools/</url>
</repository>
<repository>
<snapshots>
<enabled>true</enabled>
</snapshots>
<id>opengeo</id>
<name>OpenGeo Maven Repository</name>
<url>http://repo.opengeo.org</url>
</repository>
</repositories>
<properties>

View File

@ -0,0 +1,33 @@
package org.baeldung.gson.conversion;
import com.google.gson.*;
import org.junit.Assert;
import org.junit.jupiter.api.Test;
public class JsonObjectConversionsUnitTest {
@Test
void whenUsingJsonParser_thenConvertToJsonObject() throws Exception {
// Example 1: Using JsonParser
String json = "{ \"name\": \"Baeldung\", \"java\": true }";
JsonObject jsonObject = new JsonParser().parse(json).getAsJsonObject();
Assert.assertTrue(jsonObject.isJsonObject());
Assert.assertTrue(jsonObject.get("name").getAsString().equals("Baeldung"));
Assert.assertTrue(jsonObject.get("java").getAsBoolean() == true);
}
@Test
void whenUsingGsonInstanceFromJson_thenConvertToJsonObject() throws Exception {
// Example 2: Using fromJson
String json = "{ \"name\": \"Baeldung\", \"java\": true }";
JsonObject convertedObject = new Gson().fromJson(json, JsonObject.class);
Assert.assertTrue(convertedObject.isJsonObject());
Assert.assertTrue(convertedObject.get("name").getAsString().equals("Baeldung"));
Assert.assertTrue(convertedObject.get("java").getAsBoolean() == true);
}
}

View File

@ -21,7 +21,7 @@ import com.stackify.Application;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = Application.class)
@WebAppConfiguration
public class EmployeeControllerTest {
public class EmployeeControllerUnitTest {
private static final String CONTENT_TYPE = "application/json;charset=UTF-8";

View File

@ -117,8 +117,6 @@
</build>
<properties>
<!-- marshalling -->
<jackson.version>2.9.7</jackson.version>
<!-- util -->
<commons-lang3.version>3.8</commons-lang3.version>
<joda-time.version>2.10</joda-time.version>

View File

@ -1,16 +1,9 @@
package com.baeldung.jackson.dtos;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
public class Address {
@JacksonXmlProperty(localName = "street_number")
String streetNumber;
@JacksonXmlProperty(localName = "street_name")
String streetName;
@JacksonXmlProperty(localName = "city")
String city;
public String getStreetNumber() {

View File

@ -3,16 +3,13 @@ package com.baeldung.jackson.dtos;
import java.util.ArrayList;
import java.util.List;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
@JacksonXmlRootElement(localName = "person")
public final class Person {
private String firstName;
private String lastName;
@JacksonXmlElementWrapper(useWrapping = false)
private List<String> phoneNumbers = new ArrayList<>();
@JacksonXmlElementWrapper(localName = "addresses")
private List<Address> address = new ArrayList<>();
public List<Address> getAddress() {
@ -38,6 +35,7 @@ public final class Person {
public void setLastName(String lastName) {
this.lastName = lastName;
}
public List<String> getPhoneNumbers() {
return phoneNumbers;
}
@ -46,6 +44,4 @@ public final class Person {
this.phoneNumbers = phoneNumbers;
}
}

View File

@ -2,8 +2,10 @@ package com.baeldung.jackson.xml;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
@ -56,17 +58,14 @@ public class XMLSerializeDeserializeUnitTest {
@Test
public void whenJavaGotFromXmlStrWithCapitalElem_thenCorrect() throws IOException {
XmlMapper xmlMapper = new XmlMapper();
SimpleBeanForCapitalizedFields value = xmlMapper.
readValue("<SimpleBeanForCapitalizedFields><X>1</X><y>2</y></SimpleBeanForCapitalizedFields>",
SimpleBeanForCapitalizedFields.class);
SimpleBeanForCapitalizedFields value = xmlMapper.readValue("<SimpleBeanForCapitalizedFields><X>1</X><y>2</y></SimpleBeanForCapitalizedFields>", SimpleBeanForCapitalizedFields.class);
assertTrue(value.getX() == 1 && value.getY() == 2);
}
@Test
public void whenJavaSerializedToXmlFileWithCapitalizedField_thenCorrect() throws IOException {
XmlMapper xmlMapper = new XmlMapper();
xmlMapper.writeValue(new File("target/simple_bean_capitalized.xml"),
new SimpleBeanForCapitalizedFields());
xmlMapper.writeValue(new File("target/simple_bean_capitalized.xml"), new SimpleBeanForCapitalizedFields());
File file = new File("target/simple_bean_capitalized.xml");
assertNotNull(file);
}
@ -74,7 +73,9 @@ public class XMLSerializeDeserializeUnitTest {
@Test
public void whenJavaDeserializedFromXmlFile_thenCorrect() throws IOException {
XmlMapper xmlMapper = new XmlMapper();
Person value = xmlMapper.readValue(new File("src/test/resources/person.xml"), Person.class);
String xml = "<person><firstName>Rohan</firstName><lastName>Daye</lastName><phoneNumbers><phoneNumbers>9911034731</phoneNumbers><phoneNumbers>9911033478</phoneNumbers></phoneNumbers><address><address><streetNumber>1</streetNumber><streetName>Name1</streetName><city>City1</city></address><address><streetNumber>2</streetNumber><streetName>Name2</streetName><city>City2</city></address></address></person>";
Person value = xmlMapper.readValue(xml, Person.class);
assertTrue(value.getAddress()
.get(0)
@ -90,33 +91,38 @@ public class XMLSerializeDeserializeUnitTest {
public void whenJavaSerializedToXmlFile_thenSuccess() throws IOException {
XmlMapper xmlMapper = new XmlMapper();
String expectedXml = "<person><firstName>Rohan</firstName><lastName>Daye</lastName><phoneNumbers><phoneNumbers>9911034731</phoneNumbers><phoneNumbers>9911033478</phoneNumbers></phoneNumbers><address><address><streetNumber>1</streetNumber><streetName>Name1</streetName><city>City1</city></address><address><streetNumber>2</streetNumber><streetName>Name2</streetName><city>City2</city></address></address></person>";
Person person = new Person();
person.setFirstName("Rohan");
person.setLastName("Daye");
List<String> ph = new ArrayList<>();
ph.add("9911778981");
ph.add("9991111111");
ph.add("9911034731");
ph.add("9911033478");
person.setPhoneNumbers(ph);
List<Address> addresses = new ArrayList<>();
Address address1 = new Address();
address1.setStreetNumber("1");
address1.setStreetName("streetname1");
address1.setCity("city1");
address1.setStreetName("Name1");
address1.setCity("City1");
Address address2 = new Address();
address2.setStreetNumber("2");
address2.setStreetName("streetname2");
address2.setCity("city2");
address2.setStreetName("Name2");
address2.setCity("City2");
addresses.add(address1);
addresses.add(address2);
person.setAddress(addresses);
xmlMapper.writeValue(new File("src/test/resources/PersonGenerated.xml"), person);
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
xmlMapper.writeValue(byteArrayOutputStream, person);
assertEquals(expectedXml, byteArrayOutputStream.toString());
}
private static String inputStreamToString(InputStream is) throws IOException {

View File

@ -1,18 +0,0 @@
<person>
<firstName></firstName>
<lastName></lastName>
<phoneNumbers>9911778981</phoneNumbers>
<phoneNumbers>9991111111</phoneNumbers>
<addresses>
<address>
<street_number>1</street_number>
<street_name>streetname1</street_name>
<city>city1</city>
</address>
<address>
<street_number>2</street_number>
<street_name>streetname2</street_name>
<city>city2</city>
</address>
</addresses>
</person>

View File

@ -1,19 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<person>
<firstName>Rohan</firstName>
<lastName>Daye</lastName>
<phoneNumbers>9911034731</phoneNumbers>
<phoneNumbers>9911033478</phoneNumbers>
<addresses>
<address>
<street_number>1</street_number>
<street_name>Name1</street_name>
<city>City1</city>
</address>
<address>
<street_number>2</street_number>
<street_name>Name2</street_name>
<city>City2</city>
</address>
</addresses>
</person>

View File

@ -76,7 +76,6 @@
<properties>
<!-- util -->
<commons-lang3.version>3.5</commons-lang3.version>
<lombok.version>1.16.12</lombok.version>
<joda-time.version>2.10</joda-time.version>
<!-- testing -->
<assertj.version>3.6.1</assertj.version>

View File

@ -58,6 +58,13 @@
</plugins>
</build>
<modules>
<module>app-auth-basic-store-db</module>
<module>app-auth-form-store-ldap</module>
<module>app-auth-custom-form-store-custom</module>
<module>app-auth-custom-no-store</module>
</modules>
<properties>
<defaultHttpPort>9080</defaultHttpPort>
<defaultHttpsPort>9443</defaultHttpsPort>
@ -70,11 +77,4 @@
<maven-war-plugin.version>3.2.2</maven-war-plugin.version>
</properties>
<modules>
<module>app-auth-basic-store-db</module>
<module>app-auth-form-store-ldap</module>
<module>app-auth-custom-form-store-custom</module>
<module>app-auth-custom-no-store</module>
</modules>
</project>

View File

@ -95,7 +95,6 @@
<activeweb.version>1.15</activeweb.version>
<mysql.connector.java.version>5.1.45</mysql.connector.java.version>
<sun.tools.version>1.7.0</sun.tools.version>
<jackson.version>2.9.7</jackson.version>
<activeweb-testing.version>1.15</activeweb-testing.version>
</properties>

View File

@ -108,7 +108,6 @@
<!-- util -->
<jmh.version>1.21</jmh.version>
<commons-lang3.version>3.5</commons-lang3.version>
<lombok.version>1.16.12</lombok.version>
<vavr.version>0.9.0</vavr.version>
<protonpack.version>1.15</protonpack.version>
<streamex.version>0.6.5</streamex.version>

View File

@ -0,0 +1,70 @@
package com.baeldung.reduce.application;
import com.baeldung.reduce.entities.User;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Fork;
import org.openjdk.jmh.annotations.Mode;
import org.openjdk.jmh.annotations.Warmup;
public class Application {
public static void main(String[] args) throws Exception {
List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5, 6);
int result1 = numbers.stream().reduce(0, (subtotal, element) -> subtotal + element);
System.out.println(result1);
int result2 = numbers.stream().reduce(0, Integer::sum);
System.out.println(result2);
List<String> letters = Arrays.asList("a", "b", "c", "d", "e");
String result3 = letters.stream().reduce("", (partialString, element) -> partialString + element);
System.out.println(result3);
String result4 = letters.stream().reduce("", String::concat);
System.out.println(result4);
String result5 = letters.stream().reduce("", (partialString, element) -> partialString.toUpperCase() + element.toUpperCase());
System.out.println(result5);
List<User> users = Arrays.asList(new User("John", 30), new User("Julie", 35));
int result6 = users.stream().reduce(0, (partialAgeResult, user) -> partialAgeResult + user.getAge(), Integer::sum);
System.out.println(result6);
String result7 = letters.parallelStream().reduce("", String::concat);
System.out.println(result7);
int result8 = users.parallelStream().reduce(0, (partialAgeResult, user) -> partialAgeResult + user.getAge(), Integer::sum);
System.out.println(result8);
org.openjdk.jmh.Main.main(args);
}
@Benchmark
@Fork(value = 1, warmups = 2)
@Warmup(iterations = 2)
@BenchmarkMode(Mode.AverageTime)
public void executeReduceOnParallelizedStream() {
List<User> userList = new ArrayList<>();
for (int i = 0; i <= 1000000; i++) {
userList.add(new User("John" + i, i));
}
userList.parallelStream().reduce(0, (partialAgeResult, user) -> partialAgeResult + user.getAge(), Integer::sum);
}
@Benchmark
@Fork(value = 1, warmups = 2)
@Warmup(iterations = 2)
@BenchmarkMode(Mode.AverageTime)
public void executeReduceOnSequentialStream() {
List<User> userList = new ArrayList<>();
for (int i = 0; i <= 1000000; i++) {
userList.add(new User("John" + i, i));
}
userList.stream().reduce(0, (partialAgeResult, user) -> partialAgeResult + user.getAge(), Integer::sum);
}
}

View File

@ -0,0 +1,25 @@
package com.baeldung.reduce.entities;
public class User {
private final String name;
private final int age;
public User(String name, int age) {
this.name = name;
this.age = age;
}
public String getName() {
return name;
}
public int getAge() {
return age;
}
@Override
public String toString() {
return "User{" + "name=" + name + ", age=" + age + '}';
}
}

View File

@ -0,0 +1,52 @@
package com.baeldung.reduce.utilities;
import java.util.List;
import java.util.function.BiFunction;
import java.util.logging.Level;
import java.util.logging.Logger;
public abstract class NumberUtils {
private static final Logger LOGGER = Logger.getLogger(NumberUtils.class.getName());
public static int divideListElements(List<Integer> values, Integer divider) {
return values.stream()
.reduce(0, (a, b) -> {
try {
return a / divider + b / divider;
} catch (ArithmeticException e) {
LOGGER.log(Level.INFO, "Arithmetic Exception: Division by Zero");
}
return 0;
});
}
public static int divideListElementsWithExtractedTryCatchBlock(List<Integer> values, int divider) {
return values.stream().reduce(0, (a, b) -> divide(a, divider) + divide(b, divider));
}
public static int divideListElementsWithApplyFunctionMethod(List<Integer> values, int divider) {
BiFunction<Integer, Integer, Integer> division = (a, b) -> a / b;
return values.stream().reduce(0, (a, b) -> applyFunction(division, a, divider) + applyFunction(division, b, divider));
}
private static int divide(int value, int factor) {
int result = 0;
try {
result = value / factor;
} catch (ArithmeticException e) {
LOGGER.log(Level.INFO, "Arithmetic Exception: Division by Zero");
}
return result;
}
private static int applyFunction(BiFunction<Integer, Integer, Integer> function, int a, int b) {
try {
return function.apply(a, b);
}
catch(Exception e) {
LOGGER.log(Level.INFO, "Exception occurred!");
}
return 0;
}
}

View File

@ -0,0 +1,79 @@
package com.baeldung.reduce.tests;
import com.baeldung.reduce.entities.User;
import com.baeldung.reduce.utilities.NumberUtils;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.Test;
public class StreamReduceUnitTest {
@Test
public void givenIntegerList_whenReduceWithSumAccumulatorLambda_thenCorrect() {
List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5, 6);
int result = numbers.stream().reduce(0, (a, b) -> a + b);
assertThat(result).isEqualTo(21);
}
@Test
public void givenIntegerList_whenReduceWithSumAccumulatorMethodReference_thenCorrect() {
List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5, 6);
int result = numbers.stream().reduce(0, Integer::sum);
assertThat(result).isEqualTo(21);
}
@Test
public void givenStringList_whenReduceWithConcatenatorAccumulatorLambda_thenCorrect() {
List<String> letters = Arrays.asList("a", "b", "c", "d", "e");
String result = letters.stream().reduce("", (a, b) -> a + b);
assertThat(result).isEqualTo("abcde");
}
@Test
public void givenStringList_whenReduceWithConcatenatorAccumulatorMethodReference_thenCorrect() {
List<String> letters = Arrays.asList("a", "b", "c", "d", "e");
String result = letters.stream().reduce("", String::concat);
assertThat(result).isEqualTo("abcde");
}
@Test
public void givenStringList_whenReduceWithUppercaseConcatenatorAccumulator_thenCorrect() {
List<String> letters = Arrays.asList("a", "b", "c", "d", "e");
String result = letters.stream().reduce("", (a, b) -> a.toUpperCase() + b.toUpperCase());
assertThat(result).isEqualTo("ABCDE");
}
@Test
public void givenUserList_whenReduceWithAgeAccumulatorAndSumCombiner_thenCorrect() {
List<User> users = Arrays.asList(new User("John", 30), new User("Julie", 35));
int result = users.stream().reduce(0, (partialAgeResult, user) -> partialAgeResult + user.getAge(), Integer::sum);
assertThat(result).isEqualTo(65);
}
@Test
public void givenStringList_whenReduceWithParallelStream_thenCorrect() {
List<String> letters = Arrays.asList("a", "b", "c", "d", "e");
String result = letters.parallelStream().reduce("", String::concat);
assertThat(result).isEqualTo("abcde");
}
@Test
public void givenNumberUtilsClass_whenCalledDivideListElements_thenCorrect() {
List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5, 6);
assertThat(NumberUtils.divideListElements(numbers, 1)).isEqualTo(21);
}
@Test
public void givenNumberUtilsClass_whenCalledDivideListElementsWithExtractedTryCatchBlock_thenCorrect() {
List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5, 6);
assertThat(NumberUtils.divideListElementsWithExtractedTryCatchBlock(numbers, 1)).isEqualTo(21);
}
@Test
public void givenStream_whneCalleddivideListElementsWithApplyFunctionMethod_thenCorrect() {
List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5, 6);
assertThat(NumberUtils.divideListElementsWithApplyFunctionMethod(numbers, 1)).isEqualTo(21);
}
}

View File

@ -56,7 +56,6 @@
<hibernate-validator.version>6.0.13.Final</hibernate-validator.version>
<javax.el.version>3.0.0</javax.el.version>
<org.springframework.version>5.0.2.RELEASE</org.springframework.version>
<junit.version>4.12</junit.version>
<assertj.version>3.11.1</assertj.version>
</properties>
</project>

View File

@ -7,6 +7,8 @@ public final class AuthoritiesConstants {
public static final String ADMIN = "ROLE_ADMIN";
public static final String MANAGER = "ROLE_MANAGER";
public static final String USER = "ROLE_USER";
public static final String ANONYMOUS = "ROLE_ANONYMOUS";

View File

@ -1,3 +1,4 @@
name
ROLE_ADMIN
ROLE_MANAGER
ROLE_USER

1 name
2 ROLE_ADMIN
3 ROLE_MANAGER
4 ROLE_USER

View File

@ -2,9 +2,8 @@
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.baeldung.jhipster</groupId>
<artifactId>jhipster-microservice-uaa</artifactId>
<name>JHipster Microservice with UAA</name>
<artifactId>jhipster-uaa</artifactId>
<name>jhipster-uaa</name>
<packaging>pom</packaging>
<parent>

View File

@ -39,7 +39,6 @@
</build>
<properties>
<java.version>1.8</java.version>
<jib-maven-plugin.version>0.9.10</jib-maven-plugin.version>
</properties>
</project>

View File

@ -42,7 +42,7 @@
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson-databind.version}</version>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>javax.json.bind</groupId>
@ -73,6 +73,12 @@
<version>${commons-collections4.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>${assertj-core.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<properties>
@ -83,9 +89,8 @@
<yasson.version>1.0.1</yasson.version>
<json.version>20171018</json.version>
<gson.version>2.8.5</gson.version>
<jackson-databind.version>2.9.7</jackson-databind.version>
<junit.version>4.12</junit.version>
<javax.version>1.1.2</javax.version>
<assertj-core.version>3.11.1</assertj-core.version>
</properties>
</project>

View File

@ -0,0 +1,50 @@
package com.baeldung.jsonobject.iterate;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import org.json.JSONArray;
import org.json.JSONObject;
public class JSONObjectIterator {
private Map<String, Object> keyValuePairs;
public JSONObjectIterator() {
keyValuePairs = new HashMap<>();
}
public void handleValue(String key, Object value) {
if (value instanceof JSONArray) {
handleJSONArray(key, (JSONArray) value);
} else if (value instanceof JSONObject) {
handleJSONObject((JSONObject) value);
}
keyValuePairs.put(key, value);
}
public void handleJSONObject(JSONObject jsonObject) {
Iterator<String> jsonObjectIterator = jsonObject.keys();
jsonObjectIterator.forEachRemaining(key -> {
Object value = jsonObject.get(key);
handleValue(key, value);
});
}
public void handleJSONArray(String key, JSONArray jsonArray) {
Iterator<Object> jsonArrayIterator = jsonArray.iterator();
jsonArrayIterator.forEachRemaining(element -> {
handleValue(key, element);
});
}
public Map<String, Object> getKeyValuePairs() {
return keyValuePairs;
}
public void setKeyValuePairs(Map<String, Object> keyValuePairs) {
this.keyValuePairs = keyValuePairs;
}
}

View File

@ -0,0 +1,79 @@
package com.baeldung.jsonobject.iterate;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.Map;
import org.json.JSONArray;
import org.json.JSONObject;
import org.junit.Test;
public class JSONObjectIteratorUnitTest {
private JSONObjectIterator jsonObjectIterator = new JSONObjectIterator();
@Test
public void givenJSONObject_whenIterating_thenGetKeyValuePairs() {
JSONObject jsonObject = getJsonObject();
jsonObjectIterator.handleJSONObject(jsonObject);
Map<String, Object> keyValuePairs = jsonObjectIterator.getKeyValuePairs();
assertThat(keyValuePairs.get("rType")).isEqualTo("Regular");
assertThat(keyValuePairs.get("rId")).isEqualTo("1001");
assertThat(keyValuePairs.get("cType")).isEqualTo("Chocolate");
assertThat(keyValuePairs.get("cId")).isEqualTo("1002");
assertThat(keyValuePairs.get("bType")).isEqualTo("BlueBerry");
assertThat(keyValuePairs.get("bId")).isEqualTo("1003");
assertThat(keyValuePairs.get("name")).isEqualTo("Cake");
assertThat(keyValuePairs.get("cakeId")).isEqualTo("0001");
assertThat(keyValuePairs.get("type")).isEqualTo("donut");
assertThat(keyValuePairs.get("Type")).isEqualTo("Maple");
assertThat(keyValuePairs.get("tId")).isEqualTo("5001");
assertThat(keyValuePairs.get("batters")
.toString()).isEqualTo("[{\"rType\":\"Regular\",\"rId\":\"1001\"},{\"cType\":\"Chocolate\",\"cId\":\"1002\"},{\"bType\":\"BlueBerry\",\"bId\":\"1003\"}]");
assertThat(keyValuePairs.get("cakeShapes")
.toString()).isEqualTo("[\"square\",\"circle\",\"heart\"]");
assertThat(keyValuePairs.get("topping")
.toString()).isEqualTo("{\"Type\":\"Maple\",\"tId\":\"5001\"}");
}
private JSONObject getJsonObject() {
JSONObject cake = new JSONObject();
cake.put("cakeId", "0001");
cake.put("type", "donut");
cake.put("name", "Cake");
JSONArray batters = new JSONArray();
JSONObject regular = new JSONObject();
regular.put("rId", "1001");
regular.put("rType", "Regular");
batters.put(regular);
JSONObject chocolate = new JSONObject();
chocolate.put("cId", "1002");
chocolate.put("cType", "Chocolate");
batters.put(chocolate);
JSONObject blueberry = new JSONObject();
blueberry.put("bId", "1003");
blueberry.put("bType", "BlueBerry");
batters.put(blueberry);
JSONArray cakeShapes = new JSONArray();
cakeShapes.put("square");
cakeShapes.put("circle");
cakeShapes.put("heart");
cake.put("cakeShapes", cakeShapes);
cake.put("batters", batters);
JSONObject topping = new JSONObject();
topping.put("tId", "5001");
topping.put("Type", "Maple");
cake.put("topping", topping);
return cake;
}
}

View File

@ -10,10 +10,10 @@
<description>JEE JTA demo</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.4.RELEASE</version>
<relativePath/>
<artifactId>parent-boot-2</artifactId>
<groupId>com.baeldung</groupId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../parent-boot-2</relativePath>
</parent>
<dependencies>
@ -85,5 +85,6 @@
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<hsqldb.version>2.4.1</hsqldb.version>
<spring-boot.version>2.0.4.RELEASE</spring-boot.version>
</properties>
</project>

View File

@ -434,7 +434,6 @@
<kryo.version>4.0.1</kryo.version>
<h2.version>1.4.196</h2.version>
<reladomo.version>16.5.1</reladomo.version>
<junit.version>4.12</junit.version>
<maven-compiler-plugin.version>3.7.0</maven-compiler-plugin.version>
<ormlite.version>5.0</ormlite.version>
<kafka.version>1.0.0</kafka.version>

View File

@ -51,7 +51,6 @@
</dependencies>
<properties>
<junit.version>4.12</junit.version>
<spring-boot-maven-plugin.version>2.0.4.RELEASE</spring-boot-maven-plugin.version>
<scribejava.version>5.6.0</scribejava.version>
<spring-security-oauth2.version>2.3.3.RELEASE</spring-security-oauth2.version>

View File

@ -105,7 +105,6 @@
<jetty.version>9.4.8.v20171121</jetty.version>
<netty.version>4.1.20.Final</netty.version>
<commons.collections.version>4.1</commons.collections.version>
<junit.version>4.12</junit.version>
<tomcat.version>8.5.24</tomcat.version>
<smack.version>4.3.1</smack.version>
<eclipse.paho.client.mqttv3.version>1.2.0</eclipse.paho.client.mqttv3.version>

View File

@ -223,6 +223,12 @@
<artifactId>serenity-spring</artifactId>
<version>${serenity.version}</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>net.serenity-bdd</groupId>
@ -318,6 +324,12 @@
<artifactId>pact-jvm-consumer-junit_2.11</artifactId>
<version>${pact.version}</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
@ -675,6 +687,17 @@
<version>${mockftpserver.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.asciidoctor</groupId>
<artifactId>asciidoctor-maven-plugin</artifactId>
<version>1.5.7.1</version>
</dependency>
<!-- Reflections -->
<dependency>
<groupId>org.reflections</groupId>
<artifactId>reflections</artifactId>
<version>${reflections.version}</version>
</dependency>
</dependencies>
@ -687,10 +710,6 @@
<name>bintray</name>
<url>http://dl.bintray.com/cuba-platform/main</url>
</repository>
<repository>
<id>Apache Staging</id>
<url>https://repository.apache.org/content/groups/staging</url>
</repository>
<repository>
<id>nm-repo</id>
<name>Numerical Method's Maven Repository</name>
@ -734,7 +753,7 @@
<api>JDO</api>
<props>${basedir}/datanucleus.properties</props>
<log4jConfiguration>${basedir}/log4j.properties</log4jConfiguration>
<verbose>true</verbose>
<verbose>false</verbose>
<fork>false</fork>
<!-- Solve windows line too long error -->
</configuration>
@ -826,7 +845,6 @@
<serenity.jira.version>1.9.0</serenity.jira.version>
<serenity.plugin.version>1.9.27</serenity.plugin.version>
<jUnitParams.version>1.1.0</jUnitParams.version>
<junit.version>4.12</junit.version>
<java-lsh.version>0.10</java-lsh.version>
<pact.version>3.5.0</pact.version>
<awaitility.version>3.0.0</awaitility.version>
@ -897,6 +915,8 @@
<derive4j.version>1.1.0</derive4j.version>
<mockftpserver.version>2.7.1</mockftpserver.version>
<commons-net.version>3.6</commons-net.version>
<reflections.version>0.9.11</reflections.version>
</properties>
</project>

View File

@ -6,7 +6,7 @@ import org.derive4j.Make;
@Data(value = @Derive(
inClass = "{ClassName}Impl",
make = {Make.lazyConstructor, Make.constructors}
make = {Make.lazyConstructor, Make.constructors, Make.getters}
))
public interface LazyRequest {
interface Cases<R>{

View File

@ -0,0 +1,71 @@
package com.baeldung.reflections;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.util.Date;
import java.util.Set;
import java.util.regex.Pattern;
import org.reflections.Reflections;
import org.reflections.scanners.MethodAnnotationsScanner;
import org.reflections.scanners.MethodParameterScanner;
import org.reflections.scanners.ResourcesScanner;
import org.reflections.scanners.Scanner;
import org.reflections.scanners.SubTypesScanner;
import org.reflections.util.ClasspathHelper;
import org.reflections.util.ConfigurationBuilder;
public class ReflectionsApp {
public Set<Class<? extends Scanner>> getReflectionsSubTypes() {
Reflections reflections = new Reflections("org.reflections");
Set<Class<? extends Scanner>> scannersSet = reflections.getSubTypesOf(Scanner.class);
return scannersSet;
}
public Set<Class<?>> getJDKFunctinalInterfaces() {
Reflections reflections = new Reflections("java.util.function");
Set<Class<?>> typesSet = reflections.getTypesAnnotatedWith(FunctionalInterface.class);
return typesSet;
}
public Set<Method> getDateDeprecatedMethods() {
Reflections reflections = new Reflections(java.util.Date.class, new MethodAnnotationsScanner());
Set<Method> deprecatedMethodsSet = reflections.getMethodsAnnotatedWith(Deprecated.class);
return deprecatedMethodsSet;
}
@SuppressWarnings("rawtypes")
public Set<Constructor> getDateDeprecatedConstructors() {
Reflections reflections = new Reflections(java.util.Date.class, new MethodAnnotationsScanner());
Set<Constructor> constructorsSet = reflections.getConstructorsAnnotatedWith(Deprecated.class);
return constructorsSet;
}
public Set<Method> getMethodsWithDateParam() {
Reflections reflections = new Reflections(java.text.SimpleDateFormat.class, new MethodParameterScanner());
Set<Method> methodsSet = reflections.getMethodsMatchParams(Date.class);
return methodsSet;
}
public Set<Method> getMethodsWithVoidReturn() {
Reflections reflections = new Reflections(java.text.SimpleDateFormat.class, new MethodParameterScanner());
Set<Method> methodsSet = reflections.getMethodsReturn(void.class);
return methodsSet;
}
public Set<String> getPomXmlPaths() {
Reflections reflections = new Reflections(new ResourcesScanner());
Set<String> resourcesSet = reflections.getResources(Pattern.compile(".*pom\\.xml"));
return resourcesSet;
}
public Set<Class<? extends Scanner>> getReflectionsSubTypesUsingBuilder() {
Reflections reflections = new Reflections(new ConfigurationBuilder().setUrls(ClasspathHelper.forPackage("org.reflections"))
.setScanners(new SubTypesScanner()));
Set<Class<? extends Scanner>> scannersSet = reflections.getSubTypesOf(Scanner.class);
return scannersSet;
}
}

View File

@ -26,7 +26,7 @@ import com.google.api.services.sheets.v4.model.ValueRange;
import static org.assertj.core.api.Assertions.*;
public class GoogleSheetsIntegrationTest {
public class GoogleSheetsLiveTest {
private static Sheets sheetsService;

View File

@ -0,0 +1,50 @@
package com.baeldung.reflections;
import static org.junit.jupiter.api.Assertions.assertFalse;
import org.junit.jupiter.api.Test;
public class ReflectionsUnitTest {
@Test
public void givenTypeThenGetAllSubTypes() {
ReflectionsApp reflectionsApp = new ReflectionsApp();
assertFalse(reflectionsApp.getReflectionsSubTypes()
.isEmpty());
}
@Test
public void givenTypeAndUsingBuilderThenGetAllSubTypes() {
ReflectionsApp reflectionsApp = new ReflectionsApp();
assertFalse(reflectionsApp.getReflectionsSubTypesUsingBuilder()
.isEmpty());
}
@Test
public void givenAnnotationThenGetAllAnnotatedMethods() {
ReflectionsApp reflectionsApp = new ReflectionsApp();
assertFalse(reflectionsApp.getDateDeprecatedMethods()
.isEmpty());
}
@Test
public void givenAnnotationThenGetAllAnnotatedConstructors() {
ReflectionsApp reflectionsApp = new ReflectionsApp();
assertFalse(reflectionsApp.getDateDeprecatedConstructors()
.isEmpty());
}
@Test
public void givenParamTypeThenGetAllMethods() {
ReflectionsApp reflectionsApp = new ReflectionsApp();
assertFalse(reflectionsApp.getMethodsWithDateParam()
.isEmpty());
}
@Test
public void givenReturnTypeThenGetAllMethods() {
ReflectionsApp reflectionsApp = new ReflectionsApp();
assertFalse(reflectionsApp.getMethodsWithVoidReturn()
.isEmpty());
}
}

View File

@ -12,9 +12,10 @@ import static org.junit.Assert.*;
public class SmooksIntegrationTest {
private static final String EDIFACT_MESSAGE = "UNA:+.? '\r\n" + "UNH+771+IN_PROGRESS+2018-01-14'\r\n" + "CTA+CompanyX+1234567'\r\n" + "LIN+1+PX1234+9.99'\r\n" + "LIN+2+RX990+120.32'\r\n";
private static final String EMAIL_MESSAGE = "Hi,\r\n" + "Order number #771 created on 2018-01-14 is currently in IN_PROGRESS status.\r\n" + "Consider contact supplier \"CompanyX\" with phone number: \"1234567\".\r\n" + "Order items:\r\n"
+ "1 X PX1234 (total price 9.99)\r\n" + "2 X RX990 (total price 240.64)\r\n";
private static final String EDIFACT_MESSAGE = "UNA:+.? '" + System.lineSeparator() + "UNH+771+IN_PROGRESS+2018-01-14'" + System.lineSeparator() + "CTA+CompanyX+1234567'" + System.lineSeparator() + "LIN+1+PX1234+9.99'" + System.lineSeparator()
+ "LIN+2+RX990+120.32'" + System.lineSeparator();
private static final String EMAIL_MESSAGE = "Hi," + System.lineSeparator() + "Order number #771 created on 2018-01-14 is currently in IN_PROGRESS status." + System.lineSeparator() + "Consider contact supplier \"CompanyX\" with phone number: \"1234567\"."
+ System.lineSeparator() + "Order items:" + System.lineSeparator() + "1 X PX1234 (total price 9.99)" + System.lineSeparator() + "2 X RX990 (total price 240.64)" + System.lineSeparator();
@Test
public void givenOrderXML_whenConvert_thenPOJOsConstructedCorrectly() throws Exception {
@ -37,7 +38,10 @@ public class SmooksIntegrationTest {
assertThat(validationResult.getErrors(), hasSize(1));
// 1234567 didn't match ^[0-9\\-\\+]{9,15}$
assertThat(validationResult.getErrors().get(0).getFailRuleResult().getRuleName(), is("supplierPhone"));
assertThat(validationResult.getErrors()
.get(0)
.getFailRuleResult()
.getRuleName(), is("supplierPhone"));
}
@Test

View File

@ -5,6 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<artifactId>lombok-custom</artifactId>
<name>lombok-custom</name>
<version>0.1-SNAPSHOT</version>
<parent>

1
maven/.gitignore vendored
View File

@ -1 +1,2 @@
/output-resources
/.idea/

70
maven/custom-rule/pom.xml Normal file
View File

@ -0,0 +1,70 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>maven</artifactId>
<groupId>com.baeldung</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>custom-rule</artifactId>
<name>custom-rule</name>
<properties>
<api.version>3.0.0-M2</api.version>
<maven.version>2.0.9</maven.version>
</properties>
<dependencies>
<!-- dependencies for maven plugin-->
<dependency>
<groupId>org.apache.maven.enforcer</groupId>
<artifactId>enforcer-api</artifactId>
<version>${api.version}</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-project</artifactId>
<version>${maven.version}</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-core</artifactId>
<version>${maven.version}</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-artifact</artifactId>
<version>${maven.version}</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>${maven.version}</version>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-container-default</artifactId>
<version>1.0-alpha-9</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-verifier-plugin</artifactId>
<version>${maven.verifier.version}</version>
<configuration>
<verificationFile>../input-resources/verifications.xml</verificationFile>
<failOnError>false</failOnError>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,43 @@
/*
* Copyright (c) 2019 PloyRef
* Created by Seun Matt <smatt382@gmail.com>
* on 19 - 2 - 2019
*/
package com.baeldung.enforcer;
import org.apache.maven.enforcer.rule.api.EnforcerRule;
import org.apache.maven.enforcer.rule.api.EnforcerRuleException;
import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper;
import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException;
public class MyCustomRule implements EnforcerRule {
public void execute(EnforcerRuleHelper enforcerRuleHelper) throws EnforcerRuleException {
try {
String groupId = (String) enforcerRuleHelper.evaluate("${project.groupId}");
if (groupId == null || !groupId.startsWith("org.baeldung")) {
throw new EnforcerRuleException("Project group id does not start with org.baeldung");
}
}
catch (ExpressionEvaluationException ex ) {
throw new EnforcerRuleException( "Unable to lookup an expression " + ex.getLocalizedMessage(), ex );
}
}
public boolean isCacheable() {
return false;
}
public boolean isResultValid(EnforcerRule enforcerRule) {
return false;
}
public String getCacheId() {
return null;
}
}

View File

@ -0,0 +1,75 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>maven</artifactId>
<groupId>com.baeldung</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>maven-enforcer</artifactId>
<name>maven-enforcer</name>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>3.0.0-M2</version>
<!--<dependencies>-->
<!--<dependency>-->
<!--<groupId>com.baeldung</groupId>-->
<!--<artifactId>custom-rule</artifactId>-->
<!--<version>1.0</version>-->
<!--</dependency>-->
<!--</dependencies>-->
<executions>
<execution>
<id>enforce</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<banDuplicatePomDependencyVersions/>
<requireMavenVersion>
<version>3.0</version>
<message>Invalid Maven version. It should, at least, be 3.0</message>
</requireMavenVersion>
<requireJavaVersion>
<version>1.8</version>
</requireJavaVersion>
<requireEnvironmentVariable>
<variableName>ui</variableName>
<level>WARN</level>
</requireEnvironmentVariable>
<requireEnvironmentVariable>
<variableName>cook</variableName>
<level>WARN</level>
</requireEnvironmentVariable>
<requireActiveProfile>
<profiles>local,base</profiles>
<message>Missing active profiles</message>
<level>WARN</level>
</requireActiveProfile>
<!--other rules -->
<!--<myCustomRule implementation="com.baeldung.enforcer.MyCustomRule"/>-->
</rules>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-verifier-plugin</artifactId>
<version>${maven.verifier.version}</version>
<configuration>
<verificationFile>../input-resources/verifications.xml</verificationFile>
<failOnError>false</failOnError>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@ -4,8 +4,12 @@
<groupId>com.baeldung</groupId>
<artifactId>maven</artifactId>
<version>0.0.1-SNAPSHOT</version>
<modules>
<module>custom-rule</module>
<module>maven-enforcer</module>
</modules>
<name>maven</name>
<packaging>war</packaging>
<packaging>pom</packaging>
<dependencies>
<dependency>

View File

@ -3,6 +3,7 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>osgi-intro-sample-activator</artifactId>
<name>osgi-intro-sample-activator</name>
<!-- Please, note this is not the usual 'jar'. -->
<packaging>bundle</packaging>

View File

@ -5,6 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<!-- mvn:com.baeldung/osgi-intro-sample-client/1.0-SNAPSHOT -->
<artifactId>osgi-intro-sample-client</artifactId>
<name>osgi-intro-sample-client</name>
<packaging>bundle</packaging>
<parent>

View File

@ -3,6 +3,7 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>osgi-intro-sample-service</artifactId>
<name>osgi-intro-sample-service</name>
<!-- Please, note this is not the usual 'jar'. -->
<packaging>bundle</packaging>

View File

@ -55,7 +55,7 @@
<properties>
<rest-assured.version>3.1.0</rest-assured.version>
<spring-boot.version>1.5.16.RELEASE</spring-boot.version>
<spring-boot.version>1.5.19.RELEASE</spring-boot.version>
</properties>
</project>

View File

@ -77,9 +77,7 @@
<properties>
<rest-assured.version>3.1.0</rest-assured.version>
<!-- plugins -->
<thin.version>1.0.11.RELEASE</thin.version>
<spring-boot.version>2.1.1.RELEASE</spring-boot.version>
<thin.version>1.0.21.RELEASE</thin.version>
<spring-boot.version>2.1.3.RELEASE</spring-boot.version>
</properties>
</project>

View File

@ -29,7 +29,7 @@
</dependencies>
<properties>
<spring.version>4.3.20.RELEASE</spring.version>
<spring.version>4.3.22.RELEASE</spring.version>
<junit.jupiter.version>5.0.2</junit.jupiter.version>
</properties>

View File

@ -31,7 +31,6 @@
<properties>
<spring.version>5.1.2.RELEASE</spring.version>
<junit.jupiter.version>5.0.2</junit.jupiter.version>
<jackson-databind.version>2.9.6</jackson-databind.version>
<jackson.version>2.9.6</jackson.version>
<spring-security.version>5.1.2.RELEASE</spring-security.version>
</properties>

View File

@ -18,3 +18,4 @@
- [Chain of Responsibility Design Pattern in Java](http://www.baeldung.com/chain-of-responsibility-pattern)
- [The Command Pattern in Java](http://www.baeldung.com/java-command-pattern)
- [Java Constructors vs Static Factory Methods](https://www.baeldung.com/java-constructors-vs-static-factory-methods)
- [The Adapter Pattern in Java](https://www.baeldung.com/java-adapter-pattern)

View File

@ -5,6 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.baeldung</groupId>
<artifactId>solid</artifactId>
<name>solid</name>
<version>1.0-SNAPSHOT</version>
<parent>

View File

@ -11,10 +11,10 @@
<description>Demo Spring Boot applications that starts H2 in memory database</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.4.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
<artifactId>parent-boot-2</artifactId>
<groupId>com.baeldung</groupId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../../../parent-boot-2</relativePath>
</parent>
<dependencies>
@ -48,6 +48,7 @@
<java.version>1.8</java.version>
<!-- The main class to start by executing java -jar -->
<start-class>com.baeldung.h2db.demo.server.SpringBootApp</start-class>
<spring-boot.version>2.0.4.RELEASE</spring-boot.version>
</properties>
</project>

View File

@ -12,7 +12,7 @@ import org.springframework.test.context.support.DependencyInjectionTestExecution
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = { MultiBucketCouchbaseConfig.class, MultiBucketIntegrationTestConfig.class })
@TestExecutionListeners(listeners = { DependencyInjectionTestExecutionListener.class })
public class SpringContextIntegrationTest {
public class SpringContextLiveTest {
@Test
public void whenSpringContextIsBootstrapped_thenNoExceptions() {

View File

@ -3,7 +3,7 @@ package org.baeldung.spring.data.couchbase.service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
public class PersonRepositoryServiceIntegrationTest extends PersonServiceIntegrationTest {
public class PersonRepositoryServiceLiveTest extends PersonServiceLiveTest {
@Autowired
@Qualifier("PersonRepositoryService")

View File

@ -20,7 +20,7 @@ import com.couchbase.client.java.CouchbaseCluster;
import com.couchbase.client.java.document.JsonDocument;
import com.couchbase.client.java.document.json.JsonObject;
public abstract class PersonServiceIntegrationTest extends IntegrationTest {
public abstract class PersonServiceLiveTest extends IntegrationTest {
static final String typeField = "_class";
static final String john = "John";

View File

@ -3,7 +3,7 @@ package org.baeldung.spring.data.couchbase.service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
public class PersonTemplateServiceIntegrationTest extends PersonServiceIntegrationTest {
public class PersonTemplateServiceLiveTest extends PersonServiceLiveTest {
@Autowired
@Qualifier("PersonTemplateService")

View File

@ -3,7 +3,7 @@ package org.baeldung.spring.data.couchbase.service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
public class StudentRepositoryServiceIntegrationTest extends StudentServiceIntegrationTest {
public class StudentRepositoryServiceLiveTest extends StudentServiceLiveTest {
@Autowired
@Qualifier("StudentRepositoryService")

View File

@ -22,7 +22,7 @@ import com.couchbase.client.java.CouchbaseCluster;
import com.couchbase.client.java.document.JsonDocument;
import com.couchbase.client.java.document.json.JsonObject;
public abstract class StudentServiceIntegrationTest extends IntegrationTest {
public abstract class StudentServiceLiveTest extends IntegrationTest {
static final String typeField = "_class";
static final String joe = "Joe";

View File

@ -3,7 +3,7 @@ package org.baeldung.spring.data.couchbase.service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
public class StudentTemplateServiceIntegrationTest extends StudentServiceIntegrationTest {
public class StudentTemplateServiceLiveTest extends StudentServiceLiveTest {
@Autowired
@Qualifier("StudentTemplateService")

View File

@ -9,6 +9,6 @@ import org.springframework.test.context.support.DependencyInjectionTestExecution
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = { MultiBucketCouchbaseConfig.class, MultiBucketIntegrationTestConfig.class })
@TestExecutionListeners(listeners = { DependencyInjectionTestExecutionListener.class })
public abstract class MultiBucketIntegrationTest {
public abstract class MultiBucketLiveTest {
}

Some files were not shown because too many files have changed in this diff Show More