Merge remote-tracking branch 'eugenp/master'
This commit is contained in:
commit
ca2fada012
@ -1,5 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?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">
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>com.baeldung</groupId>
|
<groupId>com.baeldung</groupId>
|
||||||
<artifactId>JGitSnippets</artifactId>
|
<artifactId>JGitSnippets</artifactId>
|
||||||
@ -45,7 +46,6 @@
|
|||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
|
||||||
<org.eclipse.jgit.version>4.5.0.201609210915-r</org.eclipse.jgit.version>
|
<org.eclipse.jgit.version>4.5.0.201609210915-r</org.eclipse.jgit.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
<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/maven-v4_0_0.xsd">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
<groupId>com.mabsisa</groupId>
|
<groupId>com.mabsisa</groupId>
|
||||||
<artifactId>Twitter4J</artifactId>
|
<artifactId>Twitter4J</artifactId>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
@ -14,17 +15,11 @@
|
|||||||
<version>1.0.0-SNAPSHOT</version>
|
<version>1.0.0-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<properties>
|
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
|
||||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
|
||||||
<java.version>1.8</java.version>
|
|
||||||
</properties>
|
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.twitter4j</groupId>
|
<groupId>org.twitter4j</groupId>
|
||||||
<artifactId>twitter4j-stream</artifactId>
|
<artifactId>twitter4j-stream</artifactId>
|
||||||
<version>4.0.6</version>
|
<version>${twitter4j-stream.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
@ -49,4 +44,8 @@
|
|||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<twitter4j-stream.version>4.0.6</twitter4j-stream.version>
|
||||||
|
</properties>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
@ -15,12 +15,6 @@
|
|||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
|
||||||
<groupId>junit</groupId>
|
|
||||||
<artifactId>junit</artifactId>
|
|
||||||
<version>${junit.version}</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.javalite</groupId>
|
<groupId>org.javalite</groupId>
|
||||||
<artifactId>activejdbc</artifactId>
|
<artifactId>activejdbc</artifactId>
|
||||||
@ -133,10 +127,8 @@
|
|||||||
</pluginRepositories>
|
</pluginRepositories>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
|
||||||
<activejdbc.version>1.4.13</activejdbc.version>
|
<activejdbc.version>1.4.13</activejdbc.version>
|
||||||
<environments>development.test,development</environments>
|
<environments>development.test,development</environments>
|
||||||
<org.slf4j.version>1.7.9</org.slf4j.version>
|
|
||||||
<mysql.connector.version>5.1.34</mysql.connector.version>
|
<mysql.connector.version>5.1.34</mysql.connector.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
|
@ -5,7 +5,6 @@
|
|||||||
- [Ant Colony Optimization](http://www.baeldung.com/java-ant-colony-optimization)
|
- [Ant Colony Optimization](http://www.baeldung.com/java-ant-colony-optimization)
|
||||||
- [Validating Input With Finite Automata in Java](http://www.baeldung.com/java-finite-automata)
|
- [Validating Input With Finite Automata in Java](http://www.baeldung.com/java-finite-automata)
|
||||||
- [Introduction to Jenetics Library](http://www.baeldung.com/jenetics)
|
- [Introduction to Jenetics Library](http://www.baeldung.com/jenetics)
|
||||||
- [Check If a Number Is Prime in Java](http://www.baeldung.com/java-prime-numbers)
|
|
||||||
- [Example of Hill Climbing Algorithm](http://www.baeldung.com/java-hill-climbing-algorithm)
|
- [Example of Hill Climbing Algorithm](http://www.baeldung.com/java-hill-climbing-algorithm)
|
||||||
- [Monte Carlo Tree Search for Tic-Tac-Toe Game](http://www.baeldung.com/java-monte-carlo-tree-search)
|
- [Monte Carlo Tree Search for Tic-Tac-Toe Game](http://www.baeldung.com/java-monte-carlo-tree-search)
|
||||||
- [String Search Algorithms for Large Texts](http://www.baeldung.com/java-full-text-search-algorithms)
|
- [String Search Algorithms for Large Texts](http://www.baeldung.com/java-full-text-search-algorithms)
|
||||||
@ -21,7 +20,6 @@
|
|||||||
- [Create a Sudoku Solver in Java](http://www.baeldung.com/java-sudoku)
|
- [Create a Sudoku Solver in Java](http://www.baeldung.com/java-sudoku)
|
||||||
- [Displaying Money Amounts in Words](http://www.baeldung.com/java-money-into-words)
|
- [Displaying Money Amounts in Words](http://www.baeldung.com/java-money-into-words)
|
||||||
- [A Collaborative Filtering Recommendation System in Java](http://www.baeldung.com/java-collaborative-filtering-recommendations)
|
- [A Collaborative Filtering Recommendation System in Java](http://www.baeldung.com/java-collaborative-filtering-recommendations)
|
||||||
- [Find All Pairs of Numbers in an Array That Add Up to a Given Sum](http://www.baeldung.com/java-algorithm-number-pairs-sum)
|
|
||||||
- [Converting Between Roman and Arabic Numerals in Java](http://www.baeldung.com/java-convert-roman-arabic)
|
- [Converting Between Roman and Arabic Numerals in Java](http://www.baeldung.com/java-convert-roman-arabic)
|
||||||
- [Practical Java Examples of the Big O Notation](http://www.baeldung.com/java-algorithm-complexity)
|
- [Practical Java Examples of the Big O Notation](http://www.baeldung.com/java-algorithm-complexity)
|
||||||
- [Find the Middle Element of a Linked List](http://www.baeldung.com/java-linked-list-middle-element)
|
- [Find the Middle Element of a Linked List](http://www.baeldung.com/java-linked-list-middle-element)
|
||||||
|
@ -79,7 +79,6 @@
|
|||||||
</reporting>
|
</reporting>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<exec-maven-plugin.version>1.5.0</exec-maven-plugin.version>
|
|
||||||
<lombok.version>1.16.12</lombok.version>
|
<lombok.version>1.16.12</lombok.version>
|
||||||
<commons-math3.version>3.6.1</commons-math3.version>
|
<commons-math3.version>3.6.1</commons-math3.version>
|
||||||
<tradukisto.version>1.0.1</tradukisto.version>
|
<tradukisto.version>1.0.1</tradukisto.version>
|
||||||
|
@ -6,7 +6,6 @@ import com.baeldung.algorithms.ga.annealing.SimulatedAnnealing;
|
|||||||
import com.baeldung.algorithms.ga.ant_colony.AntColonyOptimization;
|
import com.baeldung.algorithms.ga.ant_colony.AntColonyOptimization;
|
||||||
import com.baeldung.algorithms.ga.binary.SimpleGeneticAlgorithm;
|
import com.baeldung.algorithms.ga.binary.SimpleGeneticAlgorithm;
|
||||||
import com.baeldung.algorithms.slope_one.SlopeOne;
|
import com.baeldung.algorithms.slope_one.SlopeOne;
|
||||||
import com.baeldung.algorithms.pairsaddupnumber.FindPairs;
|
|
||||||
|
|
||||||
public class RunAlgorithm {
|
public class RunAlgorithm {
|
||||||
|
|
||||||
@ -39,12 +38,6 @@ public class RunAlgorithm {
|
|||||||
case 5:
|
case 5:
|
||||||
System.out.println("Please run the DijkstraAlgorithmTest.");
|
System.out.println("Please run the DijkstraAlgorithmTest.");
|
||||||
break;
|
break;
|
||||||
case 6:
|
|
||||||
final FindPairs findPairs = new FindPairs();
|
|
||||||
final int[] input = {1, 4, 3, 2, 1, 4, 4, 3, 3};
|
|
||||||
final int sum = 6;
|
|
||||||
findPairs.execute(input, sum);
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
System.out.println("Unknown option");
|
System.out.println("Unknown option");
|
||||||
break;
|
break;
|
||||||
|
@ -1,59 +0,0 @@
|
|||||||
package com.baeldung.algorithms.prime;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
import java.util.stream.IntStream;
|
|
||||||
|
|
||||||
public class PrimeGenerator {
|
|
||||||
public static List<Integer> sieveOfEratosthenes(int n) {
|
|
||||||
final boolean prime[] = new boolean[n + 1];
|
|
||||||
Arrays.fill(prime, true);
|
|
||||||
|
|
||||||
for (int p = 2; p * p <= n; p++) {
|
|
||||||
if (prime[p]) {
|
|
||||||
for (int i = p * 2; i <= n; i += p)
|
|
||||||
prime[i] = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final List<Integer> primes = new LinkedList<>();
|
|
||||||
for (int i = 2; i <= n; i++) {
|
|
||||||
if (prime[i])
|
|
||||||
primes.add(i);
|
|
||||||
}
|
|
||||||
return primes;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static List<Integer> primeNumbersBruteForce(int max) {
|
|
||||||
final List<Integer> primeNumbers = new LinkedList<Integer>();
|
|
||||||
for (int i = 2; i <= max; i++) {
|
|
||||||
if (isPrimeBruteForce(i)) {
|
|
||||||
primeNumbers.add(i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return primeNumbers;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static boolean isPrimeBruteForce(int x) {
|
|
||||||
for (int i = 2; i < x; i++) {
|
|
||||||
if (x % i == 0) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static List<Integer> primeNumbersTill(int max) {
|
|
||||||
return IntStream.rangeClosed(2, max)
|
|
||||||
.filter(x -> isPrime(x))
|
|
||||||
.boxed()
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
}
|
|
||||||
|
|
||||||
private static boolean isPrime(int x) {
|
|
||||||
return IntStream.rangeClosed(2, (int) (Math.sqrt(x)))
|
|
||||||
.allMatch(n -> x % n != 0);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,28 +0,0 @@
|
|||||||
package com.baeldung.algorithms.prime;
|
|
||||||
|
|
||||||
import static com.baeldung.algorithms.prime.PrimeGenerator.*;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
import org.junit.Test;
|
|
||||||
import static org.junit.Assert.*;
|
|
||||||
|
|
||||||
public class PrimeGeneratorUnitTest {
|
|
||||||
@Test
|
|
||||||
public void whenBruteForced_returnsSuccessfully() {
|
|
||||||
final List<Integer> primeNumbers = primeNumbersBruteForce(20);
|
|
||||||
assertEquals(Arrays.asList(new Integer[] { 2, 3, 5, 7, 11, 13, 17, 19 }), primeNumbers);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void whenOptimized_returnsSuccessfully() {
|
|
||||||
final List<Integer> primeNumbers = primeNumbersTill(20);
|
|
||||||
assertEquals(Arrays.asList(new Integer[] { 2, 3, 5, 7, 11, 13, 17, 19 }), primeNumbers);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void whenSieveOfEratosthenes_returnsSuccessfully() {
|
|
||||||
final List<Integer> primeNumbers = sieveOfEratosthenes(20);
|
|
||||||
assertEquals(Arrays.asList(new Integer[] { 2, 3, 5, 7, 11, 13, 17, 19 }), primeNumbers);
|
|
||||||
}
|
|
||||||
}
|
|
@ -14,15 +14,6 @@
|
|||||||
<version>1.0.0-SNAPSHOT</version>
|
<version>1.0.0-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<dependencies>
|
|
||||||
<dependency>
|
|
||||||
<groupId>junit</groupId>
|
|
||||||
<artifactId>junit</artifactId>
|
|
||||||
<version>${junit.version}</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
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">
|
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>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<artifactId>annotation-processing</artifactId>
|
<artifactId>annotation-processing</artifactId>
|
||||||
|
@ -50,17 +50,9 @@
|
|||||||
<artifactId>antlr4-runtime</artifactId>
|
<artifactId>antlr4-runtime</artifactId>
|
||||||
<version>${antlr.version}</version>
|
<version>${antlr.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>junit</groupId>
|
|
||||||
<artifactId>junit</artifactId>
|
|
||||||
<version>${junit.version}</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<properties>
|
<properties>
|
||||||
<java.version>1.8</java.version>
|
|
||||||
<antlr.version>4.7.1</antlr.version>
|
<antlr.version>4.7.1</antlr.version>
|
||||||
<junit.version>4.12</junit.version>
|
|
||||||
<mojo.version>3.0.0</mojo.version>
|
<mojo.version>3.0.0</mojo.version>
|
||||||
</properties>
|
</properties>
|
||||||
</project>
|
</project>
|
@ -28,12 +28,6 @@
|
|||||||
<scope>runtime</scope>
|
<scope>runtime</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>junit</groupId>
|
|
||||||
<artifactId>junit</artifactId>
|
|
||||||
<version>${junit.version}</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
@ -47,12 +41,8 @@
|
|||||||
</build>
|
</build>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
|
||||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
|
||||||
<java.version>1.8</java.version>
|
|
||||||
<mysql.connector.version>5.1.44</mysql.connector.version>
|
<mysql.connector.version>5.1.44</mysql.connector.version>
|
||||||
<cayenne.version>4.0.M5</cayenne.version>
|
<cayenne.version>4.0.M5</cayenne.version>
|
||||||
<junit.version>4.12</junit.version>
|
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
@ -17,8 +17,4 @@
|
|||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<properties>
|
|
||||||
<cxf.version>3.1.8</cxf.version>
|
|
||||||
</properties>
|
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
@ -36,9 +36,4 @@
|
|||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
<properties>
|
|
||||||
<cxf.version>3.1.8</cxf.version>
|
|
||||||
<surefire.version>2.19.1</surefire.version>
|
|
||||||
</properties>
|
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
@ -48,10 +48,7 @@
|
|||||||
</build>
|
</build>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
|
||||||
<cxf.version>3.1.8</cxf.version>
|
|
||||||
<httpclient.version>4.5.2</httpclient.version>
|
<httpclient.version>4.5.2</httpclient.version>
|
||||||
<surefire.version>2.19.1</surefire.version>
|
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
@ -101,11 +101,7 @@
|
|||||||
</profiles>
|
</profiles>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<cxf.version>3.1.8</cxf.version>
|
|
||||||
<spring.version>4.3.4.RELEASE</spring.version>
|
<spring.version>4.3.4.RELEASE</spring.version>
|
||||||
<javax.servlet-api.version>3.1.0</javax.servlet-api.version>
|
|
||||||
<maven-war-plugin.version>2.6</maven-war-plugin.version>
|
|
||||||
<surefire.version>2.19.1</surefire.version>
|
|
||||||
<cargo-maven2-plugin.version>1.6.1</cargo-maven2-plugin.version>
|
<cargo-maven2-plugin.version>1.6.1</cargo-maven2-plugin.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@
|
|||||||
</build>
|
</build>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<exec-maven-plugin.version>1.5.0</exec-maven-plugin.version>
|
<cxf.version>3.1.8</cxf.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
57
apache-meecrowave/pom.xml
Normal file
57
apache-meecrowave/pom.xml
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<groupId>com.baeldung</groupId>
|
||||||
|
<artifactId>apache-meecrowave</artifactId>
|
||||||
|
<version>0.0.1</version>
|
||||||
|
<name>apache-meecrowave</name>
|
||||||
|
<description>A sample REST API application with Meecrowave</description>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<maven.compiler.source>1.8</maven.compiler.source>
|
||||||
|
<maven.compiler.target>1.8</maven.compiler.target>
|
||||||
|
</properties>
|
||||||
|
<dependencies>
|
||||||
|
<!-- https://mvnrepository.com/artifact/org.apache.meecrowave/meecrowave-core -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.meecrowave</groupId>
|
||||||
|
<artifactId>meecrowave-core</artifactId>
|
||||||
|
<version>1.2.1</version>
|
||||||
|
</dependency>
|
||||||
|
<!-- https://mvnrepository.com/artifact/org.apache.meecrowave/meecrowave-jpa -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.meecrowave</groupId>
|
||||||
|
<artifactId>meecrowave-jpa</artifactId>
|
||||||
|
<version>1.2.1</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.squareup.okhttp3</groupId>
|
||||||
|
<artifactId>okhttp</artifactId>
|
||||||
|
<version>3.10.0</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.meecrowave</groupId>
|
||||||
|
<artifactId>meecrowave-junit</artifactId>
|
||||||
|
<version>1.2.0</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<!-- https://mvnrepository.com/artifact/junit/junit -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>junit</groupId>
|
||||||
|
<artifactId>junit</artifactId>
|
||||||
|
<version>4.10</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
</dependencies>
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.meecrowave</groupId>
|
||||||
|
<artifactId>meecrowave-maven-plugin</artifactId>
|
||||||
|
<version>1.2.1</version>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</project>
|
@ -0,0 +1,30 @@
|
|||||||
|
package com.baeldung.meecrowave;
|
||||||
|
|
||||||
|
public class Article {
|
||||||
|
private String name;
|
||||||
|
private String author;
|
||||||
|
|
||||||
|
public Article() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public Article(String name, String author) {
|
||||||
|
this.author = author;
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAuthor() {
|
||||||
|
return author;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAuthor(String author) {
|
||||||
|
this.author = author;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,32 @@
|
|||||||
|
package com.baeldung.meecrowave;
|
||||||
|
|
||||||
|
import javax.enterprise.context.RequestScoped;
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import javax.ws.rs.GET;
|
||||||
|
import javax.ws.rs.POST;
|
||||||
|
import javax.ws.rs.Path;
|
||||||
|
import javax.ws.rs.core.Response;
|
||||||
|
import javax.ws.rs.core.Response.Status;
|
||||||
|
|
||||||
|
@RequestScoped
|
||||||
|
@Path("article")
|
||||||
|
public class ArticleEndpoints {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
ArticleService articleService;
|
||||||
|
|
||||||
|
@GET
|
||||||
|
public Response getArticle() {
|
||||||
|
return Response.ok()
|
||||||
|
.entity(new Article("name", "author"))
|
||||||
|
.build();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@POST
|
||||||
|
public Response createArticle(Article article) {
|
||||||
|
return Response.status(Status.CREATED)
|
||||||
|
.entity(articleService.createArticle(article))
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,10 @@
|
|||||||
|
package com.baeldung.meecrowave;
|
||||||
|
|
||||||
|
import javax.enterprise.context.ApplicationScoped;
|
||||||
|
|
||||||
|
@ApplicationScoped
|
||||||
|
public class ArticleService {
|
||||||
|
public Article createArticle(Article article) {
|
||||||
|
return article;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,16 @@
|
|||||||
|
package com.baeldung.meecrowave;
|
||||||
|
|
||||||
|
import org.apache.meecrowave.Meecrowave;
|
||||||
|
|
||||||
|
public class Server {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
final Meecrowave.Builder builder = new Meecrowave.Builder();
|
||||||
|
builder.setScanningPackageIncludes("com.baeldung.meecrowave");
|
||||||
|
builder.setJaxrsMapping("/api/*");
|
||||||
|
builder.setJsonpPrettify(true);
|
||||||
|
|
||||||
|
try (Meecrowave meecrowave = new Meecrowave(builder)) {
|
||||||
|
meecrowave.bake().await();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,41 @@
|
|||||||
|
package com.baeldung.meecrowave;
|
||||||
|
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import org.apache.meecrowave.Meecrowave;
|
||||||
|
import org.apache.meecrowave.junit.MonoMeecrowave;
|
||||||
|
import org.apache.meecrowave.testing.ConfigurationInject;
|
||||||
|
import org.junit.BeforeClass;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
|
||||||
|
import okhttp3.OkHttpClient;
|
||||||
|
import okhttp3.Request;
|
||||||
|
import okhttp3.Response;
|
||||||
|
|
||||||
|
@RunWith(MonoMeecrowave.Runner.class)
|
||||||
|
public class ArticleEndpointsTest {
|
||||||
|
|
||||||
|
@ConfigurationInject
|
||||||
|
private Meecrowave.Builder config;
|
||||||
|
private static OkHttpClient client;
|
||||||
|
|
||||||
|
@BeforeClass
|
||||||
|
public static void setup() {
|
||||||
|
client = new OkHttpClient();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenRetunedArticle_thenCorrect() throws IOException {
|
||||||
|
final String base = "http://localhost:"+config.getHttpPort();
|
||||||
|
|
||||||
|
Request request = new Request.Builder()
|
||||||
|
.url(base+"/article")
|
||||||
|
.build();
|
||||||
|
Response response = client.newCall(request).execute();
|
||||||
|
assertEquals(200, response.code());
|
||||||
|
}
|
||||||
|
}
|
@ -24,12 +24,6 @@
|
|||||||
<version>${org.assertj.version}</version>
|
<version>${org.assertj.version}</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>junit</groupId>
|
|
||||||
<artifactId>junit</artifactId>
|
|
||||||
<version>${junit.version}</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-parent</artifactId>
|
<artifactId>spring-boot-starter-parent</artifactId>
|
||||||
<version>${org.springframework.boot.spring-boot-starter-parent.version}</version>
|
<version>1.5.2.RELEASE</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
@ -57,10 +57,10 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
<version>3.7.0</version>
|
<version>${maven-compiler-plugin.version}</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<source>1.8</source>
|
<source>${java.version}</source>
|
||||||
<target>1.8</target>
|
<target>${java.version}</target>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
@ -68,9 +68,10 @@
|
|||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<apache-shiro-core-version>1.4.0</apache-shiro-core-version>
|
<apache-shiro-core-version>1.4.0</apache-shiro-core-version>
|
||||||
|
<maven-compiler-plugin.version>3.7.0</maven-compiler-plugin.version>
|
||||||
|
<java.version>1.8</java.version>
|
||||||
<log4j-version>1.2.17</log4j-version>
|
<log4j-version>1.2.17</log4j-version>
|
||||||
<slf4j-version>1.7.25</slf4j-version>
|
<slf4j-version>1.7.25</slf4j-version>
|
||||||
<org.springframework.boot.spring-boot-starter-parent.version>1.5.2.RELEASE</org.springframework.boot.spring-boot-starter-parent.version>
|
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
</project>
|
</project>
|
@ -12,7 +12,7 @@ import org.apache.solr.common.SolrDocumentList;
|
|||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class SolrJavaIntegrationTest {
|
public class SolrJavaLiveTest {
|
||||||
|
|
||||||
private SolrJavaIntegration solrJavaIntegration;
|
private SolrJavaIntegration solrJavaIntegration;
|
||||||
|
|
@ -21,16 +21,9 @@
|
|||||||
<artifactId>spark-core_2.10</artifactId>
|
<artifactId>spark-core_2.10</artifactId>
|
||||||
<version>${org.apache.spark.spark-core.version}</version>
|
<version>${org.apache.spark.spark-core.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>junit</groupId>
|
|
||||||
<artifactId>junit</artifactId>
|
|
||||||
<version>${junit.version}</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
|
||||||
<org.apache.spark.spark-core.version>2.2.0</org.apache.spark.spark-core.version>
|
<org.apache.spark.spark-core.version>2.2.0</org.apache.spark.spark-core.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
|
@ -60,7 +60,6 @@
|
|||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<jstl.version>1.2</jstl.version>
|
<jstl.version>1.2</jstl.version>
|
||||||
<maven-war-plugin.version>2.6</maven-war-plugin.version>
|
|
||||||
<org.apache.httpcomponents.version>4.5.2</org.apache.httpcomponents.version>
|
<org.apache.httpcomponents.version>4.5.2</org.apache.httpcomponents.version>
|
||||||
<velocity-version>1.7</velocity-version>
|
<velocity-version>1.7</velocity-version>
|
||||||
<velocity-tools-version>2.0</velocity-tools-version>
|
<velocity-tools-version>2.0</velocity-tools-version>
|
||||||
|
@ -54,10 +54,8 @@
|
|||||||
</build>
|
</build>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
|
||||||
<asm.version>5.2</asm.version>
|
<asm.version>5.2</asm.version>
|
||||||
<maven-jar-plugin.version>2.4</maven-jar-plugin.version>
|
<maven-jar-plugin.version>2.4</maven-jar-plugin.version>
|
||||||
<maven-surefire-plugin.version>2.9</maven-surefire-plugin.version>
|
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
</project>
|
</project>
|
@ -17,12 +17,6 @@
|
|||||||
<artifactId>atomix-all</artifactId>
|
<artifactId>atomix-all</artifactId>
|
||||||
<version>${atomix-all.version}</version>
|
<version>${atomix-all.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>junit</groupId>
|
|
||||||
<artifactId>junit</artifactId>
|
|
||||||
<version>${junit.version}</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>log4j</groupId>
|
<groupId>log4j</groupId>
|
||||||
<artifactId>log4j</artifactId>
|
<artifactId>log4j</artifactId>
|
||||||
@ -32,7 +26,6 @@
|
|||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<atomix-all.version>1.0.0-rc9</atomix-all.version>
|
<atomix-all.version>1.0.0-rc9</atomix-all.version>
|
||||||
<log4j.version>1.2.17</log4j.version>
|
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
3
aws-lambda/README.md
Normal file
3
aws-lambda/README.md
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
### Relevant Articles:
|
||||||
|
- [Using AWS Lambda with API Gateway](http://www.baeldung.com/aws-lambda-api-gateway)
|
||||||
|
- [Introduction to AWS Serverless Application Model](http://www.baeldung.com/aws-serverless)
|
@ -1,31 +1,30 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
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">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<parent>
|
|
||||||
<artifactId>parent-modules</artifactId>
|
|
||||||
<groupId>com.baeldung</groupId>
|
|
||||||
<version>1.0.0-SNAPSHOT</version>
|
|
||||||
</parent>
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
<groupId>com.baeldung</groupId>
|
<groupId>com.baeldung</groupId>
|
||||||
<artifactId>aws-lambda</artifactId>
|
<artifactId>aws-lambda</artifactId>
|
||||||
<version>0.1.0-SNAPSHOT</version>
|
<version>0.1.0-SNAPSHOT</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
<name>aws-lambda</name>
|
<name>aws-lambda</name>
|
||||||
|
|
||||||
|
<parent>
|
||||||
|
<artifactId>parent-modules</artifactId>
|
||||||
|
<groupId>com.baeldung</groupId>
|
||||||
|
<version>1.0.0-SNAPSHOT</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.amazonaws</groupId>
|
<groupId>com.amazonaws</groupId>
|
||||||
<artifactId>aws-java-sdk-dynamodb</artifactId>
|
<artifactId>aws-java-sdk-dynamodb</artifactId>
|
||||||
<version>1.11.241</version>
|
<version>${aws-java-sdk.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.amazonaws</groupId>
|
<groupId>com.amazonaws</groupId>
|
||||||
<artifactId>aws-java-sdk-core</artifactId>
|
<artifactId>aws-java-sdk-core</artifactId>
|
||||||
<version>1.11.241</version>
|
<version>${aws-java-sdk.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.amazonaws</groupId>
|
<groupId>com.amazonaws</groupId>
|
||||||
@ -65,6 +64,7 @@
|
|||||||
<version>${json-simple.version}</version>
|
<version>${json-simple.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
@ -85,6 +85,7 @@
|
|||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<json-simple.version>1.1.1</json-simple.version>
|
<json-simple.version>1.1.1</json-simple.version>
|
||||||
<org.json.version>20180130</org.json.version>
|
<org.json.version>20180130</org.json.version>
|
||||||
@ -92,8 +93,9 @@
|
|||||||
<aws-lambda-java-events.version>1.3.0</aws-lambda-java-events.version>
|
<aws-lambda-java-events.version>1.3.0</aws-lambda-java-events.version>
|
||||||
<aws-lambda-java-core.version>1.2.0</aws-lambda-java-core.version>
|
<aws-lambda-java-core.version>1.2.0</aws-lambda-java-core.version>
|
||||||
<gson.version>2.8.2</gson.version>
|
<gson.version>2.8.2</gson.version>
|
||||||
<aws-java-sdk-core.version>1.11.241</aws-java-sdk-core.version>
|
<aws-java-sdk.version>1.11.241</aws-java-sdk.version>
|
||||||
<maven-shade-plugin.version>3.0.0</maven-shade-plugin.version>
|
<maven-shade-plugin.version>3.0.0</maven-shade-plugin.version>
|
||||||
<maven-dependency-plugin.version>2.10</maven-dependency-plugin.version>
|
<maven-dependency-plugin.version>2.10</maven-dependency-plugin.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
</project>
|
</project>
|
@ -19,12 +19,6 @@
|
|||||||
<artifactId>aws-java-sdk</artifactId>
|
<artifactId>aws-java-sdk</artifactId>
|
||||||
<version>${aws-java-sdk.version}</version>
|
<version>${aws-java-sdk.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>junit</groupId>
|
|
||||||
<artifactId>junit</artifactId>
|
|
||||||
<version>${junit.version}</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.mockito</groupId>
|
<groupId>org.mockito</groupId>
|
||||||
<artifactId>mockito-core</artifactId>
|
<artifactId>mockito-core</artifactId>
|
||||||
@ -143,7 +137,6 @@
|
|||||||
<aws-lambda-java-core.version>1.1.0</aws-lambda-java-core.version>
|
<aws-lambda-java-core.version>1.1.0</aws-lambda-java-core.version>
|
||||||
<gson.version>2.8.0</gson.version>
|
<gson.version>2.8.0</gson.version>
|
||||||
<aws-java-sdk.version>1.11.290</aws-java-sdk.version>
|
<aws-java-sdk.version>1.11.290</aws-java-sdk.version>
|
||||||
<junit.version>4.12</junit.version>
|
|
||||||
<mockito-core.version>2.8.9</mockito-core.version>
|
<mockito-core.version>2.8.9</mockito-core.version>
|
||||||
<assertj-core.version>3.8.0</assertj-core.version>
|
<assertj-core.version>3.8.0</assertj-core.version>
|
||||||
<dynamodblocal.version>1.11.86</dynamodblocal.version>
|
<dynamodblocal.version>1.11.86</dynamodblocal.version>
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
<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">
|
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>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
<groupId>com.baeldung</groupId>
|
<groupId>com.baeldung</groupId>
|
||||||
<artifactId>azure</artifactId>
|
<artifactId>azure</artifactId>
|
||||||
<version>0.1</version>
|
<version>0.1</version>
|
||||||
@ -17,11 +16,6 @@
|
|||||||
<relativePath>../parent-boot-2</relativePath>
|
<relativePath>../parent-boot-2</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<properties>
|
|
||||||
<azure.containerRegistry>baeldungadr</azure.containerRegistry>
|
|
||||||
<docker.image.prefix>${azure.containerRegistry}.azurecr.io</docker.image.prefix>
|
|
||||||
</properties>
|
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
@ -42,12 +36,13 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.h2database</groupId>
|
<groupId>com.h2database</groupId>
|
||||||
<artifactId>h2</artifactId>
|
<artifactId>h2</artifactId>
|
||||||
|
<scope>runtime</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>mysql</groupId>
|
<groupId>mysql</groupId>
|
||||||
<artifactId>mysql-connector-java</artifactId>
|
<artifactId>mysql-connector-java</artifactId>
|
||||||
<version>5.1.6</version>
|
<scope>runtime</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
@ -61,7 +56,7 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>com.spotify</groupId>
|
<groupId>com.spotify</groupId>
|
||||||
<artifactId>docker-maven-plugin</artifactId>
|
<artifactId>docker-maven-plugin</artifactId>
|
||||||
<version>1.1.0</version>
|
<version>{docker-maven-plugin.version}</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<imageName>${docker.image.prefix}/${project.artifactId}</imageName>
|
<imageName>${docker.image.prefix}/${project.artifactId}</imageName>
|
||||||
<registryUrl>https://${docker.image.prefix}</registryUrl>
|
<registryUrl>https://${docker.image.prefix}</registryUrl>
|
||||||
@ -79,7 +74,7 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>com.microsoft.azure</groupId>
|
<groupId>com.microsoft.azure</groupId>
|
||||||
<artifactId>azure-webapp-maven-plugin</artifactId>
|
<artifactId>azure-webapp-maven-plugin</artifactId>
|
||||||
<version>1.1.0</version>
|
<version>${azure-webapp-maven-plugin.version}</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<authentication>
|
<authentication>
|
||||||
<serverId>azure-auth</serverId>
|
<serverId>azure-auth</serverId>
|
||||||
@ -87,7 +82,7 @@
|
|||||||
<resourceGroup>baeldung-group</resourceGroup>
|
<resourceGroup>baeldung-group</resourceGroup>
|
||||||
<appName>baeldung-webapp</appName>
|
<appName>baeldung-webapp</appName>
|
||||||
<appServicePlanName>baeldung-plan</appServicePlanName>
|
<appServicePlanName>baeldung-plan</appServicePlanName>
|
||||||
<javaVersion>1.8</javaVersion>
|
<javaVersion>{java.version}</javaVersion>
|
||||||
<!--<javaWebContainer>tomcat 8.5</javaWebContainer> -->
|
<!--<javaWebContainer>tomcat 8.5</javaWebContainer> -->
|
||||||
<!--<region>japanwest</region> -->
|
<!--<region>japanwest</region> -->
|
||||||
<!--<containerSettings> -->
|
<!--<containerSettings> -->
|
||||||
@ -127,5 +122,12 @@
|
|||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<azure.containerRegistry>baeldungadr</azure.containerRegistry>
|
||||||
|
<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>
|
</project>
|
||||||
|
@ -60,8 +60,6 @@
|
|||||||
</build>
|
</build>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
|
||||||
<maven-compiler-plugin.version>3.7.0</maven-compiler-plugin.version>
|
|
||||||
<camel.version>2.19.1</camel.version>
|
<camel.version>2.19.1</camel.version>
|
||||||
<spring-boot-starter.version>1.5.4.RELEASE</spring-boot-starter.version>
|
<spring-boot-starter.version>1.5.4.RELEASE</spring-boot-starter.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
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 ">
|
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>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>com.baeldung</groupId>
|
<groupId>com.baeldung</groupId>
|
||||||
@ -31,7 +30,7 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>com.rimerosolutions.maven.plugins</groupId>
|
<groupId>com.rimerosolutions.maven.plugins</groupId>
|
||||||
<artifactId>wrapper-maven-plugin</artifactId>
|
<artifactId>wrapper-maven-plugin</artifactId>
|
||||||
<version>0.0.4</version>
|
<version>${wrapper-maven-plugin.version}</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<verifyDownload>true</verifyDownload>
|
<verifyDownload>true</verifyDownload>
|
||||||
<checksumAlgorithm>MD5</checksumAlgorithm>
|
<checksumAlgorithm>MD5</checksumAlgorithm>
|
||||||
@ -58,7 +57,7 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-war-plugin</artifactId>
|
<artifactId>maven-war-plugin</artifactId>
|
||||||
<version>2.6</version>
|
<version>${maven-war-plugin.version}</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<warName>cas</warName>
|
<warName>cas</warName>
|
||||||
<failOnMissingWebXml>false</failOnMissingWebXml>
|
<failOnMissingWebXml>false</failOnMissingWebXml>
|
||||||
@ -78,27 +77,12 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
<version>3.3</version>
|
<version>${maven-compiler-plugin.version}</version>
|
||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
<finalName>cas</finalName>
|
<finalName>cas</finalName>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
<properties>
|
|
||||||
<cas.version>5.3.0-SNAPSHOT</cas.version>
|
|
||||||
<springboot.version>1.5.13.RELEASE</springboot.version>
|
|
||||||
<!-- app.server could be -jetty, -undertow, -tomcat, or blank if you plan to provide appserver -->
|
|
||||||
<app.server>-tomcat</app.server>
|
|
||||||
|
|
||||||
<mainClassName>org.springframework.boot.loader.WarLauncher</mainClassName>
|
|
||||||
<isExecutable>false</isExecutable>
|
|
||||||
<manifestFileToUse>${project.build.directory}/war/work/org.apereo.cas/cas-server-webapp${app.server}/META-INF/MANIFEST.MF</manifestFileToUse>
|
|
||||||
|
|
||||||
<maven.compiler.source>1.8</maven.compiler.source>
|
|
||||||
<maven.compiler.target>1.8</maven.compiler.target>
|
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
|
||||||
</properties>
|
|
||||||
|
|
||||||
<repositories>
|
<repositories>
|
||||||
<repository>
|
<repository>
|
||||||
<id>sonatype-releases</id>
|
<id>sonatype-releases</id>
|
||||||
@ -140,9 +124,7 @@
|
|||||||
<type>war</type>
|
<type>war</type>
|
||||||
<scope>runtime</scope>
|
<scope>runtime</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!--
|
<!-- ...Additional dependencies may be placed here... -->
|
||||||
...Additional dependencies may be placed here...
|
|
||||||
-->
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</profile>
|
</profile>
|
||||||
|
|
||||||
@ -161,7 +143,7 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>com.soebes.maven.plugins</groupId>
|
<groupId>com.soebes.maven.plugins</groupId>
|
||||||
<artifactId>echo-maven-plugin</artifactId>
|
<artifactId>echo-maven-plugin</artifactId>
|
||||||
<version>0.3.0</version>
|
<version>${echo-maven-plugin.version}</version>
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<phase>prepare-package</phase>
|
<phase>prepare-package</phase>
|
||||||
@ -210,7 +192,7 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>com.github.s4u.plugins</groupId>
|
<groupId>com.github.s4u.plugins</groupId>
|
||||||
<artifactId>pgpverify-maven-plugin</artifactId>
|
<artifactId>pgpverify-maven-plugin</artifactId>
|
||||||
<version>1.1.0</version>
|
<version>${pgpverify-maven-plugin.version}</version>
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<goals>
|
<goals>
|
||||||
@ -230,4 +212,25 @@
|
|||||||
</build>
|
</build>
|
||||||
</profile>
|
</profile>
|
||||||
</profiles>
|
</profiles>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<cas.version>5.3.0-SNAPSHOT</cas.version>
|
||||||
|
<springboot.version>1.5.13.RELEASE</springboot.version>
|
||||||
|
<!-- app.server could be -jetty, -undertow, -tomcat, or blank if you plan to provide appserver -->
|
||||||
|
<app.server>-tomcat</app.server>
|
||||||
|
|
||||||
|
<mainClassName>org.springframework.boot.loader.WarLauncher</mainClassName>
|
||||||
|
<isExecutable>false</isExecutable>
|
||||||
|
<manifestFileToUse>${project.build.directory}/war/work/org.apereo.cas/cas-server-webapp${app.server}/META-INF/MANIFEST.MF</manifestFileToUse>
|
||||||
|
|
||||||
|
<maven.compiler.source>1.8</maven.compiler.source>
|
||||||
|
<maven.compiler.target>1.8</maven.compiler.target>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
<wrapper-maven-plugin.version>0.0.4</wrapper-maven-plugin.version>
|
||||||
|
<maven-war-plugin.version>2.6</maven-war-plugin.version>
|
||||||
|
<maven-compiler-plugin.version>3.3</maven-compiler-plugin.version>
|
||||||
|
<echo-maven-plugin.version>0.3.0</echo-maven-plugin.version>
|
||||||
|
<pgpverify-maven-plugin.version>1.1.0</pgpverify-maven-plugin.version>
|
||||||
|
</properties>
|
||||||
|
|
||||||
</project>
|
</project>
|
@ -17,19 +17,19 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.hamcrest</groupId>
|
<groupId>org.hamcrest</groupId>
|
||||||
<artifactId>hamcrest-core</artifactId>
|
<artifactId>hamcrest-core</artifactId>
|
||||||
<version>1.3</version>
|
<version>${hamcrest-core.version}</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.assertj</groupId>
|
<groupId>org.assertj</groupId>
|
||||||
<artifactId>assertj-core</artifactId>
|
<artifactId>assertj-core</artifactId>
|
||||||
<version>3.10.0</version>
|
<version>${assertj-core.version}</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>junit</groupId>
|
<groupId>junit</groupId>
|
||||||
<artifactId>junit</artifactId>
|
<artifactId>junit</artifactId>
|
||||||
<version>4.12</version>
|
<version>${junit.version}</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
@ -58,6 +58,9 @@
|
|||||||
<properties>
|
<properties>
|
||||||
<aspectjweaver.version>1.8.9</aspectjweaver.version>
|
<aspectjweaver.version>1.8.9</aspectjweaver.version>
|
||||||
<weld-se-core.version>2.4.1.Final</weld-se-core.version>
|
<weld-se-core.version>2.4.1.Final</weld-se-core.version>
|
||||||
|
<hamcrest-core.version>1.3</hamcrest-core.version>
|
||||||
|
<assertj-core.version>3.10.0</assertj-core.version>
|
||||||
|
<junit.version>4.12</junit.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
@ -66,8 +66,8 @@
|
|||||||
<artifactId>maven-compiler-plugin</artifactId>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
<version>${maven-compiler-plugin.version}</version>
|
<version>${maven-compiler-plugin.version}</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<source>${maven.compiler.source}</source>
|
<source>${java.version}</source>
|
||||||
<target>${maven.compiler.target}</target>
|
<target>${java.version}</target>
|
||||||
<!-- Uncomment the following line to use the type annotations compiler. -->
|
<!-- Uncomment the following line to use the type annotations compiler. -->
|
||||||
<!-- <fork>true</fork> -->
|
<!-- <fork>true</fork> -->
|
||||||
<compilerArguments>
|
<compilerArguments>
|
||||||
@ -113,8 +113,6 @@
|
|||||||
<checker.version>2.3.1</checker.version>
|
<checker.version>2.3.1</checker.version>
|
||||||
<jdk8.version>2.3.1</jdk8.version>
|
<jdk8.version>2.3.1</jdk8.version>
|
||||||
<checkerframework.compiler.version>2.3.1</checkerframework.compiler.version>
|
<checkerframework.compiler.version>2.3.1</checkerframework.compiler.version>
|
||||||
<maven.compiler.source>1.8</maven.compiler.source>
|
|
||||||
<maven.compiler.target>1.8</maven.compiler.target>
|
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
@ -101,24 +101,13 @@
|
|||||||
</repositories>
|
</repositories>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
|
||||||
<kotlin-maven-plugin.version>1.1.2</kotlin-maven-plugin.version>
|
|
||||||
<kotlin-test-junit.version>1.1.2</kotlin-test-junit.version>
|
|
||||||
<kotlin-stdlib.version>1.1.2</kotlin-stdlib.version>
|
|
||||||
<kotlin-reflect.version>1.1.2</kotlin-reflect.version>
|
|
||||||
<kotlinx.version>0.15</kotlinx.version>
|
|
||||||
<mockito-kotlin.version>1.5.0</mockito-kotlin.version>
|
|
||||||
<junit.jupiter.version>5.0.0</junit.jupiter.version>
|
|
||||||
<junit.platform.version>1.0.0</junit.platform.version>
|
<junit.platform.version>1.0.0</junit.platform.version>
|
||||||
<junit.vintage.version>4.12.0</junit.vintage.version>
|
|
||||||
<junit4.version>4.12</junit4.version>
|
|
||||||
<groovy.version>2.4.13</groovy.version>
|
<groovy.version>2.4.13</groovy.version>
|
||||||
<groovy-all.version>2.4.13</groovy-all.version>
|
<groovy-all.version>2.4.13</groovy-all.version>
|
||||||
<groovy-sql.version>2.4.13</groovy-sql.version>
|
<groovy-sql.version>2.4.13</groovy-sql.version>
|
||||||
<hsqldb.version>2.4.0</hsqldb.version>
|
<hsqldb.version>2.4.0</hsqldb.version>
|
||||||
<spock-core.version>1.1-groovy-2.4</spock-core.version>
|
<spock-core.version>1.1-groovy-2.4</spock-core.version>
|
||||||
<gmavenplus-plugin.version>1.6</gmavenplus-plugin.version>
|
<gmavenplus-plugin.version>1.6</gmavenplus-plugin.version>
|
||||||
<maven-failsafe-plugin.version>2.19.1</maven-failsafe-plugin.version>
|
|
||||||
</properties>
|
</properties>
|
||||||
</project>
|
</project>
|
||||||
|
|
||||||
|
@ -14,15 +14,6 @@
|
|||||||
<version>1.0.0-SNAPSHOT</version>
|
<version>1.0.0-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<dependencies>
|
|
||||||
<dependency>
|
|
||||||
<groupId>junit</groupId>
|
|
||||||
<artifactId>junit</artifactId>
|
|
||||||
<version>${junit.version}</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
|
@ -14,15 +14,6 @@
|
|||||||
<version>1.0.0-SNAPSHOT</version>
|
<version>1.0.0-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<dependencies>
|
|
||||||
<dependency>
|
|
||||||
<groupId>junit</groupId>
|
|
||||||
<artifactId>junit</artifactId>
|
|
||||||
<version>${junit.version}</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
|
@ -32,7 +32,6 @@
|
|||||||
- [“Stream has already been operated upon or closed” Exception in Java](http://www.baeldung.com/java-stream-operated-upon-or-closed-exception)
|
- [“Stream has already been operated upon or closed” Exception in Java](http://www.baeldung.com/java-stream-operated-upon-or-closed-exception)
|
||||||
- [Display All Time Zones With GMT And UTC in Java](http://www.baeldung.com/java-time-zones)
|
- [Display All Time Zones With GMT And UTC in Java](http://www.baeldung.com/java-time-zones)
|
||||||
- [Copy a File with Java](http://www.baeldung.com/java-copy-file)
|
- [Copy a File with Java](http://www.baeldung.com/java-copy-file)
|
||||||
- [Generating Prime Numbers in Java](http://www.baeldung.com/java-generate-prime-numbers)
|
|
||||||
- [Static and Default Methods in Interfaces in Java](http://www.baeldung.com/java-static-default-methods)
|
- [Static and Default Methods in Interfaces in Java](http://www.baeldung.com/java-static-default-methods)
|
||||||
- [Iterable to Stream in Java](http://www.baeldung.com/java-iterable-to-stream)
|
- [Iterable to Stream in Java](http://www.baeldung.com/java-iterable-to-stream)
|
||||||
- [Converting String to Stream of chars](http://www.baeldung.com/java-string-to-stream)
|
- [Converting String to Stream of chars](http://www.baeldung.com/java-string-to-stream)
|
||||||
|
@ -94,6 +94,11 @@
|
|||||||
<artifactId>streamex</artifactId>
|
<artifactId>streamex</artifactId>
|
||||||
<version>${streamex.version}</version>
|
<version>${streamex.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>joda-time</groupId>
|
||||||
|
<artifactId>joda-time</artifactId>
|
||||||
|
<version>${joda.version}</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
@ -170,8 +175,7 @@
|
|||||||
<configuration>
|
<configuration>
|
||||||
<shadedArtifactAttached>true</shadedArtifactAttached>
|
<shadedArtifactAttached>true</shadedArtifactAttached>
|
||||||
<transformers>
|
<transformers>
|
||||||
<transformer
|
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
|
||||||
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
|
|
||||||
<mainClass>org.baeldung.executable.ExecutableMavenJar</mainClass>
|
<mainClass>org.baeldung.executable.ExecutableMavenJar</mainClass>
|
||||||
</transformer>
|
</transformer>
|
||||||
</transformers>
|
</transformers>
|
||||||
@ -225,10 +229,8 @@
|
|||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<!-- util -->
|
<!-- util -->
|
||||||
<guava.version>21.0</guava.version>
|
|
||||||
<commons-lang3.version>3.5</commons-lang3.version>
|
<commons-lang3.version>3.5</commons-lang3.version>
|
||||||
<commons-math3.version>3.6.1</commons-math3.version>
|
<commons-math3.version>3.6.1</commons-math3.version>
|
||||||
<commons-io.version>2.5</commons-io.version>
|
|
||||||
<commons-collections4.version>4.1</commons-collections4.version>
|
<commons-collections4.version>4.1</commons-collections4.version>
|
||||||
<collections-generic.version>4.01</collections-generic.version>
|
<collections-generic.version>4.01</collections-generic.version>
|
||||||
<commons-codec.version>1.10</commons-codec.version>
|
<commons-codec.version>1.10</commons-codec.version>
|
||||||
@ -236,6 +238,7 @@
|
|||||||
<vavr.version>0.9.0</vavr.version>
|
<vavr.version>0.9.0</vavr.version>
|
||||||
<protonpack.version>1.13</protonpack.version>
|
<protonpack.version>1.13</protonpack.version>
|
||||||
<streamex.version>0.6.5</streamex.version>
|
<streamex.version>0.6.5</streamex.version>
|
||||||
|
<joda.version>2.10</joda.version>
|
||||||
<!-- testing -->
|
<!-- testing -->
|
||||||
<assertj.version>3.6.1</assertj.version>
|
<assertj.version>3.6.1</assertj.version>
|
||||||
<avaitility.version>1.7.0</avaitility.version>
|
<avaitility.version>1.7.0</avaitility.version>
|
||||||
|
@ -0,0 +1,54 @@
|
|||||||
|
package com.baeldung.datetime;
|
||||||
|
|
||||||
|
import java.time.Duration;
|
||||||
|
import java.time.Instant;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.ZonedDateTime;
|
||||||
|
import java.time.temporal.ChronoUnit;
|
||||||
|
import java.util.Calendar;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.time.DateUtils;
|
||||||
|
|
||||||
|
public class AddHoursToDate {
|
||||||
|
|
||||||
|
public Date addHoursToJavaUtilDate(Date date, int hours) {
|
||||||
|
Calendar calendar = Calendar.getInstance();
|
||||||
|
calendar.setTime(date);
|
||||||
|
calendar.add(Calendar.HOUR_OF_DAY, hours);
|
||||||
|
return calendar.getTime();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date addHoursToDateUsingInstant(Date date, int hours) {
|
||||||
|
return Date.from(date.toInstant()
|
||||||
|
.plus(Duration.ofHours(hours)));
|
||||||
|
}
|
||||||
|
|
||||||
|
public LocalDateTime addHoursToLocalDateTime(LocalDateTime localDateTime, int hours) {
|
||||||
|
return localDateTime.plusHours(hours);
|
||||||
|
}
|
||||||
|
|
||||||
|
public LocalDateTime subtractHoursToLocalDateTime(LocalDateTime localDateTime, int hours) {
|
||||||
|
return localDateTime.minusHours(hours);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ZonedDateTime addHoursToZonedDateTime(ZonedDateTime zonedDateTime, int hours) {
|
||||||
|
return zonedDateTime.plusHours(hours);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ZonedDateTime subtractHoursToZonedDateTime(ZonedDateTime zonedDateTime, int hours) {
|
||||||
|
return zonedDateTime.minusHours(hours);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Instant addHoursToInstant(Instant instant, int hours) {
|
||||||
|
return instant.plus(hours, ChronoUnit.HOURS);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Instant subtractHoursToInstant(Instant instant, int hours) {
|
||||||
|
return instant.minus(hours, ChronoUnit.HOURS);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date addHoursWithApacheCommons(Date date, int hours) {
|
||||||
|
return DateUtils.addHours(date, hours);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,63 @@
|
|||||||
|
package com.baeldung.datetime.modify;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.time.DateUtils;
|
||||||
|
import org.joda.time.DateTime;
|
||||||
|
|
||||||
|
import java.text.ParseException;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.util.Calendar;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
public class DateIncrementer {
|
||||||
|
private static final Logger log = Logger.getLogger(DateIncrementer.class.getName());
|
||||||
|
private static final int INCREMENT_BY_IN_DAYS = 1;
|
||||||
|
|
||||||
|
public static String addOneDay(String date) {
|
||||||
|
return LocalDate
|
||||||
|
.parse(date)
|
||||||
|
.plusDays(INCREMENT_BY_IN_DAYS)
|
||||||
|
.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String addOneDayJodaTime(String date) {
|
||||||
|
DateTime dateTime = new DateTime(date);
|
||||||
|
return dateTime
|
||||||
|
.plusDays(INCREMENT_BY_IN_DAYS)
|
||||||
|
.toString("yyyy-MM-dd");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String addOneDayCalendar(String date) throws ParseException {
|
||||||
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
||||||
|
Calendar c = Calendar.getInstance();
|
||||||
|
c.setTime(sdf.parse(date));
|
||||||
|
c.add(Calendar.DATE, 1);
|
||||||
|
return sdf.format(c.getTime());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String addOneDayApacheCommons(String date) throws ParseException {
|
||||||
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
||||||
|
Date incrementedDate = DateUtils.addDays(sdf.parse(date), 1);
|
||||||
|
return sdf.format(incrementedDate);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) throws ParseException {
|
||||||
|
String date = LocalDate
|
||||||
|
.now()
|
||||||
|
.toString();
|
||||||
|
log.info("Current date = " + date);
|
||||||
|
|
||||||
|
String incrementedDateJava8 = DateIncrementer.addOneDay(date);
|
||||||
|
log.info("Date incremented by one day using (Java 8): " + incrementedDateJava8);
|
||||||
|
|
||||||
|
String incrementedDateJodaTime = DateIncrementer.addOneDayJodaTime(date);
|
||||||
|
log.info("Date incremented by one day using (Joda-Time): " + incrementedDateJodaTime);
|
||||||
|
|
||||||
|
String incrementedDateCalendar = addOneDayCalendar(date);
|
||||||
|
log.info("Date incremented by one day using (java.util.Calendar): " + incrementedDateCalendar);
|
||||||
|
|
||||||
|
String incrementedDateApacheCommons = addOneDayApacheCommons(date);
|
||||||
|
log.info("Date incremented by one day using (Apache Commons DateUtils): " + incrementedDateApacheCommons);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,116 @@
|
|||||||
|
package com.baeldung.datetime;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
|
import java.time.Instant;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.Month;
|
||||||
|
import java.time.ZoneId;
|
||||||
|
import java.time.ZonedDateTime;
|
||||||
|
import java.util.Calendar;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.GregorianCalendar;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class AddHoursToDateUnitTest {
|
||||||
|
|
||||||
|
private final AddHoursToDate addHoursToDateObj = new AddHoursToDate();
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenJavaUtilDate_whenPositiveHours_thenAddHours() {
|
||||||
|
Date actualDate = new GregorianCalendar(2018, Calendar.JUNE, 25, 5, 0).getTime();
|
||||||
|
Date expectedDate = new GregorianCalendar(2018, Calendar.JUNE, 25, 7, 0).getTime();
|
||||||
|
|
||||||
|
assertThat(addHoursToDateObj.addHoursToJavaUtilDate(actualDate, 2)).isEqualTo(expectedDate);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenJavaUtilDate_whenNegativeHours_thenMinusHours() {
|
||||||
|
Date actualDate = new GregorianCalendar(2018, Calendar.JUNE, 25, 5, 0).getTime();
|
||||||
|
Date expectedDate = new GregorianCalendar(2018, Calendar.JUNE, 25, 3, 0).getTime();
|
||||||
|
|
||||||
|
assertThat(addHoursToDateObj.addHoursToJavaUtilDate(actualDate, -2)).isEqualTo(expectedDate);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenJavaUtilDate_whenUsingToInstantAndPostiveHours_thenAddHours() {
|
||||||
|
Date actualDate = new GregorianCalendar(2018, Calendar.JUNE, 25, 5, 0).getTime();
|
||||||
|
Date expectedDate = new GregorianCalendar(2018, Calendar.JUNE, 25, 7, 0).getTime();
|
||||||
|
|
||||||
|
assertThat(addHoursToDateObj.addHoursToDateUsingInstant(actualDate, 2)).isEqualTo(expectedDate);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenJavaUtilDate_whenUsingToInstantAndNegativeHours_thenAddHours() {
|
||||||
|
Date actualDate = new GregorianCalendar(2018, Calendar.JUNE, 25, 5, 0).getTime();
|
||||||
|
Date expectedDate = new GregorianCalendar(2018, Calendar.JUNE, 25, 3, 0).getTime();
|
||||||
|
|
||||||
|
assertThat(addHoursToDateObj.addHoursToDateUsingInstant(actualDate, -2)).isEqualTo(expectedDate);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenLocalDateTime_whenUsingAddHoursToLocalDateTime_thenAddHours() {
|
||||||
|
LocalDateTime actualDateTime = LocalDateTime.of(2018, Month.JUNE, 25, 5, 0);
|
||||||
|
LocalDateTime expectedDateTime = LocalDateTime.of(2018, Month.JUNE, 25, 7, 0);
|
||||||
|
|
||||||
|
assertThat(addHoursToDateObj.addHoursToLocalDateTime(actualDateTime, 2)).isEqualTo(expectedDateTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenLocalDateTime_whenUsingMinusHoursToLocalDateTime_thenMinusHours() {
|
||||||
|
LocalDateTime actualDateTime = LocalDateTime.of(2018, Month.JUNE, 25, 5, 0);
|
||||||
|
LocalDateTime expectedDateTime = LocalDateTime.of(2018, Month.JUNE, 25, 3, 0);
|
||||||
|
|
||||||
|
assertThat(addHoursToDateObj.subtractHoursToLocalDateTime(actualDateTime, 2)).isEqualTo(expectedDateTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenZonedDateTime_whenUsingAddHoursToZonedDateTime_thenAddHours() {
|
||||||
|
ZonedDateTime actualZonedDateTime = ZonedDateTime.of(LocalDateTime.of(2018, Month.JUNE, 25, 5, 0), ZoneId.systemDefault());
|
||||||
|
ZonedDateTime expectedZonedDateTime = ZonedDateTime.of(LocalDateTime.of(2018, Month.JUNE, 25, 7, 0), ZoneId.systemDefault());
|
||||||
|
|
||||||
|
assertThat(addHoursToDateObj.addHoursToZonedDateTime(actualZonedDateTime, 2)).isEqualTo(expectedZonedDateTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenZonedDateTime_whenUsingMinusHoursToZonedDateTime_thenMinusHours() {
|
||||||
|
ZonedDateTime actualZonedDateTime = ZonedDateTime.of(LocalDateTime.of(2018, Month.JUNE, 25, 5, 0), ZoneId.systemDefault());
|
||||||
|
ZonedDateTime expectedZonedDateTime = ZonedDateTime.of(LocalDateTime.of(2018, Month.JUNE, 25, 3, 0), ZoneId.systemDefault());
|
||||||
|
|
||||||
|
assertThat(addHoursToDateObj.subtractHoursToZonedDateTime(actualZonedDateTime, 2)).isEqualTo(expectedZonedDateTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenJavaUtilDate_whenUsingPositiveHrsAndAddHoursWithApacheCommons_thenAddHours() {
|
||||||
|
Date actualDate = new GregorianCalendar(2018, Calendar.JUNE, 25, 5, 0).getTime();
|
||||||
|
Date expectedDate = new GregorianCalendar(2018, Calendar.JUNE, 25, 7, 0).getTime();
|
||||||
|
|
||||||
|
assertThat(addHoursToDateObj.addHoursWithApacheCommons(actualDate, 2)).isEqualTo(expectedDate);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenJavaUtilDate_whenUsingNegativeHrsAndAddHoursWithApacheCommons_thenMinusHours() {
|
||||||
|
Date actualDate = new GregorianCalendar(2018, Calendar.JUNE, 25, 7, 0).getTime();
|
||||||
|
Date expectedDate = new GregorianCalendar(2018, Calendar.JUNE, 25, 5, 0).getTime();
|
||||||
|
|
||||||
|
assertThat(addHoursToDateObj.addHoursWithApacheCommons(actualDate, -2)).isEqualTo(expectedDate);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenInstant_whenUsingAddHoursToInstant_thenAddHours() {
|
||||||
|
Instant actualValue = Instant.parse("2018-06-25T05:12:35Z");
|
||||||
|
Instant expectedValue = Instant.parse("2018-06-25T07:12:35Z");
|
||||||
|
|
||||||
|
assertThat(addHoursToDateObj.addHoursToInstant(actualValue, 2)).isEqualTo(expectedValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenInstant_whenUsingSubtractHoursToInstant_thenMinusHours() {
|
||||||
|
Instant actualValue = Instant.parse("2018-06-25T07:12:35Z");
|
||||||
|
Instant expectedValue = Instant.parse("2018-06-25T05:12:35Z");
|
||||||
|
|
||||||
|
assertThat(addHoursToDateObj.subtractHoursToInstant(actualValue, 2)).isEqualTo(expectedValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,34 @@
|
|||||||
|
package com.baeldung.datetime.modify;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
|
public class DateIncrementerUnitTest {
|
||||||
|
private final static String DATE_TO_INCREMENT = "2018-07-03";
|
||||||
|
private final static String EXPECTED_DATE = "2018-07-04";
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenDate_whenUsingJava8_thenAddOneDay() throws Exception {
|
||||||
|
String incrementedDate = DateIncrementer.addOneDay(DATE_TO_INCREMENT);
|
||||||
|
assertEquals(EXPECTED_DATE, incrementedDate);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenDate_whenUsingJodaTime_thenAddOneDay() throws Exception {
|
||||||
|
String incrementedDate = DateIncrementer.addOneDayJodaTime(DATE_TO_INCREMENT);
|
||||||
|
assertEquals(EXPECTED_DATE, incrementedDate);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenDate_whenUsingCalendar_thenAddOneDay() throws Exception {
|
||||||
|
String incrementedDate = DateIncrementer.addOneDayCalendar(DATE_TO_INCREMENT);
|
||||||
|
assertEquals(EXPECTED_DATE, incrementedDate);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenDate_whenUsingApacheCommons_thenAddOneDay() throws Exception {
|
||||||
|
String incrementedDate = DateIncrementer.addOneDayApacheCommons(DATE_TO_INCREMENT);
|
||||||
|
assertEquals(EXPECTED_DATE, incrementedDate);
|
||||||
|
}
|
||||||
|
}
|
@ -13,34 +13,6 @@
|
|||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
|
||||||
<groupId>org.slf4j</groupId>
|
|
||||||
<artifactId>slf4j-api</artifactId>
|
|
||||||
<version>${org.slf4j.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>ch.qos.logback</groupId>
|
|
||||||
<artifactId>logback-classic</artifactId>
|
|
||||||
<version>${ch.qos.logback.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.hamcrest</groupId>
|
|
||||||
<artifactId>hamcrest-library</artifactId>
|
|
||||||
<version>${org.hamcrest.version}</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>junit</groupId>
|
|
||||||
<artifactId>junit</artifactId>
|
|
||||||
<version>${junit.version}</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.mockito</groupId>
|
|
||||||
<artifactId>mockito-core</artifactId>
|
|
||||||
<version>${mockito.version}</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.jayway.awaitility</groupId>
|
<groupId>com.jayway.awaitility</groupId>
|
||||||
<artifactId>awaitility</artifactId>
|
<artifactId>awaitility</artifactId>
|
||||||
@ -77,20 +49,7 @@
|
|||||||
</pluginRepositories>
|
</pluginRepositories>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<!-- project build encoding -->
|
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
|
||||||
|
|
||||||
<!-- logging -->
|
|
||||||
<org.slf4j.version>1.7.21</org.slf4j.version>
|
|
||||||
<ch.qos.logback.version>1.2.1</ch.qos.logback.version>
|
|
||||||
<!-- maven plugins -->
|
|
||||||
<maven-compiler-plugin.version>3.7.0</maven-compiler-plugin.version>
|
|
||||||
<maven-surefire-plugin.version>2.19.1</maven-surefire-plugin.version>
|
|
||||||
|
|
||||||
<!-- testing -->
|
<!-- testing -->
|
||||||
<org.hamcrest.version>1.3</org.hamcrest.version>
|
|
||||||
<junit.version>4.12</junit.version>
|
|
||||||
<mockito.version>1.10.19</mockito.version>
|
|
||||||
<awaitility.version>1.7.0</awaitility.version>
|
<awaitility.version>1.7.0</awaitility.version>
|
||||||
<maven.compiler.source>1.9</maven.compiler.source>
|
<maven.compiler.source>1.9</maven.compiler.source>
|
||||||
<maven.compiler.target>1.9</maven.compiler.target>
|
<maven.compiler.target>1.9</maven.compiler.target>
|
||||||
|
@ -15,12 +15,6 @@
|
|||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
|
||||||
<groupId>junit</groupId>
|
|
||||||
<artifactId>junit</artifactId>
|
|
||||||
<version>${junit.version}</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>net.sourceforge.collections</groupId>
|
<groupId>net.sourceforge.collections</groupId>
|
||||||
<artifactId>collections-generic</artifactId>
|
<artifactId>collections-generic</artifactId>
|
||||||
|
@ -122,8 +122,7 @@
|
|||||||
<configuration>
|
<configuration>
|
||||||
<shadedArtifactAttached>true</shadedArtifactAttached>
|
<shadedArtifactAttached>true</shadedArtifactAttached>
|
||||||
<transformers>
|
<transformers>
|
||||||
<transformer
|
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
|
||||||
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
|
|
||||||
<mainClass>org.baeldung.executable.ExecutableMavenJar</mainClass>
|
<mainClass>org.baeldung.executable.ExecutableMavenJar</mainClass>
|
||||||
</transformer>
|
</transformer>
|
||||||
</transformers>
|
</transformers>
|
||||||
@ -170,7 +169,6 @@
|
|||||||
<guava.version>21.0</guava.version>
|
<guava.version>21.0</guava.version>
|
||||||
<commons-lang3.version>3.5</commons-lang3.version>
|
<commons-lang3.version>3.5</commons-lang3.version>
|
||||||
<commons-math3.version>3.6.1</commons-math3.version>
|
<commons-math3.version>3.6.1</commons-math3.version>
|
||||||
<commons-io.version>2.5</commons-io.version>
|
|
||||||
<commons-collections4.version>4.1</commons-collections4.version>
|
<commons-collections4.version>4.1</commons-collections4.version>
|
||||||
<collections-generic.version>4.01</collections-generic.version>
|
<collections-generic.version>4.01</collections-generic.version>
|
||||||
<!-- testing -->
|
<!-- testing -->
|
||||||
|
@ -74,23 +74,6 @@
|
|||||||
<artifactId>log4j</artifactId>
|
<artifactId>log4j</artifactId>
|
||||||
<version>${log4j.version}</version>
|
<version>${log4j.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>org.slf4j</groupId>
|
|
||||||
<artifactId>slf4j-api</artifactId>
|
|
||||||
<version>${org.slf4j.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>ch.qos.logback</groupId>
|
|
||||||
<artifactId>logback-classic</artifactId>
|
|
||||||
<version>${logback.version}</version>
|
|
||||||
<!-- <scope>runtime</scope> -->
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.slf4j</groupId>
|
|
||||||
<artifactId>jcl-over-slf4j</artifactId>
|
|
||||||
<version>${org.slf4j.version}</version>
|
|
||||||
<!-- <scope>runtime</scope> --> <!-- some spring dependencies need to compile against jcl -->
|
|
||||||
</dependency>
|
|
||||||
<dependency> <!-- needed to bridge to slf4j for projects that use the log4j APIs directly -->
|
<dependency> <!-- needed to bridge to slf4j for projects that use the log4j APIs directly -->
|
||||||
<groupId>org.slf4j</groupId>
|
<groupId>org.slf4j</groupId>
|
||||||
<artifactId>log4j-over-slf4j</artifactId>
|
<artifactId>log4j-over-slf4j</artifactId>
|
||||||
@ -103,42 +86,12 @@
|
|||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- test scoped -->
|
<!-- test scoped -->
|
||||||
<dependency>
|
|
||||||
<groupId>org.hamcrest</groupId>
|
|
||||||
<artifactId>hamcrest-all</artifactId>
|
|
||||||
<version>${hamcrest-all.version}</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>junit</groupId>
|
|
||||||
<artifactId>junit</artifactId>
|
|
||||||
<version>${junit.version}</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.hamcrest</groupId>
|
|
||||||
<artifactId>hamcrest-core</artifactId>
|
|
||||||
<version>${org.hamcrest.version}</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.hamcrest</groupId>
|
|
||||||
<artifactId>hamcrest-library</artifactId>
|
|
||||||
<version>${org.hamcrest.version}</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.assertj</groupId>
|
<groupId>org.assertj</groupId>
|
||||||
<artifactId>assertj-core</artifactId>
|
<artifactId>assertj-core</artifactId>
|
||||||
<version>${assertj.version}</version>
|
<version>${assertj.version}</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>org.mockito</groupId>
|
|
||||||
<artifactId>mockito-core</artifactId>
|
|
||||||
<version>${mockito.version}</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.jayway.awaitility</groupId>
|
<groupId>com.jayway.awaitility</groupId>
|
||||||
<artifactId>awaitility</artifactId>
|
<artifactId>awaitility</artifactId>
|
||||||
@ -335,18 +288,12 @@
|
|||||||
<!-- marshalling -->
|
<!-- marshalling -->
|
||||||
<jackson.version>2.8.5</jackson.version>
|
<jackson.version>2.8.5</jackson.version>
|
||||||
|
|
||||||
<!-- logging -->
|
|
||||||
<org.slf4j.version>1.7.21</org.slf4j.version>
|
|
||||||
<logback.version>1.1.7</logback.version>
|
|
||||||
|
|
||||||
<!-- util -->
|
<!-- util -->
|
||||||
<guava.version>22.0</guava.version>
|
|
||||||
<commons-lang3.version>3.5</commons-lang3.version>
|
<commons-lang3.version>3.5</commons-lang3.version>
|
||||||
<bouncycastle.version>1.55</bouncycastle.version>
|
<bouncycastle.version>1.55</bouncycastle.version>
|
||||||
<commons-codec.version>1.10</commons-codec.version>
|
<commons-codec.version>1.10</commons-codec.version>
|
||||||
<commons-math3.version>3.6.1</commons-math3.version>
|
<commons-math3.version>3.6.1</commons-math3.version>
|
||||||
<decimal4j.version>1.0.3</decimal4j.version>
|
<decimal4j.version>1.0.3</decimal4j.version>
|
||||||
<commons-io.version>2.5</commons-io.version>
|
|
||||||
<commons-collections4.version>4.1</commons-collections4.version>
|
<commons-collections4.version>4.1</commons-collections4.version>
|
||||||
<collections-generic.version>4.01</collections-generic.version>
|
<collections-generic.version>4.01</collections-generic.version>
|
||||||
<unix4j.version>0.4</unix4j.version>
|
<unix4j.version>0.4</unix4j.version>
|
||||||
@ -358,15 +305,10 @@
|
|||||||
<vavr.version>0.9.0</vavr.version>
|
<vavr.version>0.9.0</vavr.version>
|
||||||
|
|
||||||
<!-- testing -->
|
<!-- testing -->
|
||||||
<org.hamcrest.version>1.3</org.hamcrest.version>
|
|
||||||
<junit.version>4.12</junit.version>
|
|
||||||
<mockito.version>2.8.9</mockito.version>
|
|
||||||
<assertj.version>3.6.1</assertj.version>
|
<assertj.version>3.6.1</assertj.version>
|
||||||
<avaitility.version>1.7.0</avaitility.version>
|
<avaitility.version>1.7.0</avaitility.version>
|
||||||
|
|
||||||
<!-- maven plugins -->
|
<!-- maven plugins -->
|
||||||
<maven-compiler-plugin.version>3.7.0</maven-compiler-plugin.version>
|
|
||||||
<maven-surefire-plugin.version>2.19.1</maven-surefire-plugin.version>
|
|
||||||
<maven.compiler.source>1.8</maven.compiler.source>
|
<maven.compiler.source>1.8</maven.compiler.source>
|
||||||
<maven.compiler.target>1.8</maven.compiler.target>
|
<maven.compiler.target>1.8</maven.compiler.target>
|
||||||
<maven-javadoc-plugin.version>3.0.0-M1</maven-javadoc-plugin.version>
|
<maven-javadoc-plugin.version>3.0.0-M1</maven-javadoc-plugin.version>
|
||||||
|
@ -14,8 +14,10 @@ import org.slf4j.LoggerFactory;
|
|||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.nio.file.Path;
|
||||||
import java.nio.file.StandardCopyOption;
|
import java.nio.file.StandardCopyOption;
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic;
|
import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic;
|
||||||
import static org.hamcrest.Matchers.equalTo;
|
import static org.hamcrest.Matchers.equalTo;
|
||||||
@ -112,6 +114,19 @@ public class JavaInputStreamToXUnitTest {
|
|||||||
assertThat(writer.toString(), equalTo(originalString));
|
assertThat(writer.toString(), equalTo(originalString));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public final void givenUsingTempFile_whenConvertingAnInputStreamToAString_thenCorrect() throws IOException {
|
||||||
|
final String originalString = randomAlphabetic(DEFAULT_SIZE);
|
||||||
|
final InputStream inputStream = new ByteArrayInputStream(originalString.getBytes());
|
||||||
|
|
||||||
|
// When
|
||||||
|
Path tempFile = java.nio.file.Files.createTempDirectory("").resolve(UUID.randomUUID().toString() + ".tmp");
|
||||||
|
java.nio.file.Files.copy(inputStream, tempFile, StandardCopyOption.REPLACE_EXISTING);
|
||||||
|
String result = new String(java.nio.file.Files.readAllBytes(tempFile));
|
||||||
|
|
||||||
|
assertThat(result, equalTo(originalString));
|
||||||
|
}
|
||||||
|
|
||||||
// tests - InputStream to byte[]
|
// tests - InputStream to byte[]
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>com.baeldung</groupId>
|
<groupId>com.baeldung</groupId>
|
||||||
<artifactId>core-java-sun</artifactId>
|
<artifactId>core-java-sun</artifactId>
|
||||||
@ -73,23 +74,6 @@
|
|||||||
<artifactId>log4j</artifactId>
|
<artifactId>log4j</artifactId>
|
||||||
<version>${log4j.version}</version>
|
<version>${log4j.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>org.slf4j</groupId>
|
|
||||||
<artifactId>slf4j-api</artifactId>
|
|
||||||
<version>${org.slf4j.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>ch.qos.logback</groupId>
|
|
||||||
<artifactId>logback-classic</artifactId>
|
|
||||||
<version>${logback.version}</version>
|
|
||||||
<!-- <scope>runtime</scope> -->
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.slf4j</groupId>
|
|
||||||
<artifactId>jcl-over-slf4j</artifactId>
|
|
||||||
<version>${org.slf4j.version}</version>
|
|
||||||
<!-- <scope>runtime</scope> --> <!-- some spring dependencies need to compile against jcl -->
|
|
||||||
</dependency>
|
|
||||||
<dependency> <!-- needed to bridge to slf4j for projects that use the log4j APIs directly -->
|
<dependency> <!-- needed to bridge to slf4j for projects that use the log4j APIs directly -->
|
||||||
<groupId>org.slf4j</groupId>
|
<groupId>org.slf4j</groupId>
|
||||||
<artifactId>log4j-over-slf4j</artifactId>
|
<artifactId>log4j-over-slf4j</artifactId>
|
||||||
@ -102,42 +86,12 @@
|
|||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- test scoped -->
|
<!-- test scoped -->
|
||||||
<dependency>
|
|
||||||
<groupId>org.hamcrest</groupId>
|
|
||||||
<artifactId>hamcrest-all</artifactId>
|
|
||||||
<version>${hamcrest-all.version}</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>junit</groupId>
|
|
||||||
<artifactId>junit</artifactId>
|
|
||||||
<version>${junit.version}</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.hamcrest</groupId>
|
|
||||||
<artifactId>hamcrest-core</artifactId>
|
|
||||||
<version>${org.hamcrest.version}</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.hamcrest</groupId>
|
|
||||||
<artifactId>hamcrest-library</artifactId>
|
|
||||||
<version>${org.hamcrest.version}</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.assertj</groupId>
|
<groupId>org.assertj</groupId>
|
||||||
<artifactId>assertj-core</artifactId>
|
<artifactId>assertj-core</artifactId>
|
||||||
<version>${assertj.version}</version>
|
<version>${assertj.version}</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>org.mockito</groupId>
|
|
||||||
<artifactId>mockito-core</artifactId>
|
|
||||||
<version>${mockito.version}</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.jayway.awaitility</groupId>
|
<groupId>com.jayway.awaitility</groupId>
|
||||||
<artifactId>awaitility</artifactId>
|
<artifactId>awaitility</artifactId>
|
||||||
@ -398,10 +352,6 @@
|
|||||||
<!-- marshalling -->
|
<!-- marshalling -->
|
||||||
<jackson.version>2.8.5</jackson.version>
|
<jackson.version>2.8.5</jackson.version>
|
||||||
|
|
||||||
<!-- logging -->
|
|
||||||
<org.slf4j.version>1.7.21</org.slf4j.version>
|
|
||||||
<logback.version>1.1.7</logback.version>
|
|
||||||
|
|
||||||
<!-- util -->
|
<!-- util -->
|
||||||
<guava.version>23.0</guava.version>
|
<guava.version>23.0</guava.version>
|
||||||
<commons-lang3.version>3.5</commons-lang3.version>
|
<commons-lang3.version>3.5</commons-lang3.version>
|
||||||
@ -409,7 +359,6 @@
|
|||||||
<commons-codec.version>1.10</commons-codec.version>
|
<commons-codec.version>1.10</commons-codec.version>
|
||||||
<commons-math3.version>3.6.1</commons-math3.version>
|
<commons-math3.version>3.6.1</commons-math3.version>
|
||||||
<decimal4j.version>1.0.3</decimal4j.version>
|
<decimal4j.version>1.0.3</decimal4j.version>
|
||||||
<commons-io.version>2.5</commons-io.version>
|
|
||||||
<commons-collections4.version>4.1</commons-collections4.version>
|
<commons-collections4.version>4.1</commons-collections4.version>
|
||||||
<collections-generic.version>4.01</collections-generic.version>
|
<collections-generic.version>4.01</collections-generic.version>
|
||||||
<unix4j.version>0.4</unix4j.version>
|
<unix4j.version>0.4</unix4j.version>
|
||||||
@ -421,13 +370,10 @@
|
|||||||
<vavr.version>0.9.0</vavr.version>
|
<vavr.version>0.9.0</vavr.version>
|
||||||
|
|
||||||
<!-- testing -->
|
<!-- testing -->
|
||||||
<org.hamcrest.version>1.3</org.hamcrest.version>
|
|
||||||
<mockito.version>2.8.9</mockito.version>
|
|
||||||
<assertj.version>3.6.1</assertj.version>
|
<assertj.version>3.6.1</assertj.version>
|
||||||
<avaitility.version>1.7.0</avaitility.version>
|
<avaitility.version>1.7.0</avaitility.version>
|
||||||
|
|
||||||
<!-- maven plugins -->
|
<!-- maven plugins -->
|
||||||
<maven-compiler-plugin.version>3.7.0</maven-compiler-plugin.version>
|
|
||||||
<maven-surefire-plugin.version>2.19.1</maven-surefire-plugin.version>
|
<maven-surefire-plugin.version>2.19.1</maven-surefire-plugin.version>
|
||||||
<sun-tools.version>1.8.0</sun-tools.version>
|
<sun-tools.version>1.8.0</sun-tools.version>
|
||||||
<spring-web.version>4.3.4.RELEASE</spring-web.version>
|
<spring-web.version>4.3.4.RELEASE</spring-web.version>
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
## Core Java Cookbooks and Examples
|
## Core Java Cookbooks and Examples
|
||||||
|
|
||||||
### Relevant Articles:
|
### Relevant Articles:
|
||||||
- [Java – Random Long, Float, Integer and Double](http://www.baeldung.com/java-generate-random-long-float-integer-double)
|
|
||||||
- [Java – Generate Random String](http://www.baeldung.com/java-random-string)
|
- [Java – Generate Random String](http://www.baeldung.com/java-random-string)
|
||||||
- [Java Timer](http://www.baeldung.com/java-timer-and-timertask)
|
- [Java Timer](http://www.baeldung.com/java-timer-and-timertask)
|
||||||
- [How to Run a Shell Command in Java](http://www.baeldung.com/run-shell-command-in-java)
|
- [How to Run a Shell Command in Java](http://www.baeldung.com/run-shell-command-in-java)
|
||||||
@ -38,7 +37,6 @@
|
|||||||
- [A Quick JUnit vs TestNG Comparison](http://www.baeldung.com/junit-vs-testng)
|
- [A Quick JUnit vs TestNG Comparison](http://www.baeldung.com/junit-vs-testng)
|
||||||
- [Java Primitive Conversions](http://www.baeldung.com/java-primitive-conversions)
|
- [Java Primitive Conversions](http://www.baeldung.com/java-primitive-conversions)
|
||||||
- [Java Money and the Currency API](http://www.baeldung.com/java-money-and-currency)
|
- [Java Money and the Currency API](http://www.baeldung.com/java-money-and-currency)
|
||||||
- [Using Math.pow in Java](http://www.baeldung.com/java-math-pow)
|
|
||||||
- [Converting Strings to Enums in Java](http://www.baeldung.com/java-string-to-enum)
|
- [Converting Strings to Enums in Java](http://www.baeldung.com/java-string-to-enum)
|
||||||
- [Quick Guide to the Java StringTokenizer](http://www.baeldung.com/java-stringtokenizer)
|
- [Quick Guide to the Java StringTokenizer](http://www.baeldung.com/java-stringtokenizer)
|
||||||
- [JVM Log Forging](http://www.baeldung.com/jvm-log-forging)
|
- [JVM Log Forging](http://www.baeldung.com/jvm-log-forging)
|
||||||
@ -49,7 +47,6 @@
|
|||||||
- [How to Add a Single Element to a Stream](http://www.baeldung.com/java-stream-append-prepend)
|
- [How to Add a Single Element to a Stream](http://www.baeldung.com/java-stream-append-prepend)
|
||||||
- [Iterating Over Enum Values in Java](http://www.baeldung.com/java-enum-iteration)
|
- [Iterating Over Enum Values in Java](http://www.baeldung.com/java-enum-iteration)
|
||||||
- [Kotlin Java Interoperability](http://www.baeldung.com/kotlin-java-interoperability)
|
- [Kotlin Java Interoperability](http://www.baeldung.com/kotlin-java-interoperability)
|
||||||
- [How to Round a Number to N Decimal Places in Java](http://www.baeldung.com/java-round-decimal-number)
|
|
||||||
- [Changing Annotation Parameters At Runtime](http://www.baeldung.com/java-reflection-change-annotation-params)
|
- [Changing Annotation Parameters At Runtime](http://www.baeldung.com/java-reflection-change-annotation-params)
|
||||||
- [How to Find all Getters Returning Null](http://www.baeldung.com/java-getters-returning-null)
|
- [How to Find all Getters Returning Null](http://www.baeldung.com/java-getters-returning-null)
|
||||||
- [Changing the Order in a Sum Operation Can Produce Different Results?](http://www.baeldung.com/java-floating-point-sum-order)
|
- [Changing the Order in a Sum Operation Can Produce Different Results?](http://www.baeldung.com/java-floating-point-sum-order)
|
||||||
@ -77,7 +74,6 @@
|
|||||||
- [“Sneaky Throws” in Java](http://www.baeldung.com/java-sneaky-throws)
|
- [“Sneaky Throws” in Java](http://www.baeldung.com/java-sneaky-throws)
|
||||||
- [OutOfMemoryError: GC Overhead Limit Exceeded](http://www.baeldung.com/java-gc-overhead-limit-exceeded)
|
- [OutOfMemoryError: GC Overhead Limit Exceeded](http://www.baeldung.com/java-gc-overhead-limit-exceeded)
|
||||||
- [StringBuilder and StringBuffer in Java](http://www.baeldung.com/java-string-builder-string-buffer)
|
- [StringBuilder and StringBuffer in Java](http://www.baeldung.com/java-string-builder-string-buffer)
|
||||||
- [Number of Digits in an Integer in Java](http://www.baeldung.com/java-number-of-digits-in-int)
|
|
||||||
- [Creating a Java Compiler Plugin](http://www.baeldung.com/java-build-compiler-plugin)
|
- [Creating a Java Compiler Plugin](http://www.baeldung.com/java-build-compiler-plugin)
|
||||||
- [A Guide to the Static Keyword in Java](http://www.baeldung.com/java-static)
|
- [A Guide to the Static Keyword in Java](http://www.baeldung.com/java-static)
|
||||||
- [Initializing Arrays in Java](http://www.baeldung.com/java-initialize-array)
|
- [Initializing Arrays in Java](http://www.baeldung.com/java-initialize-array)
|
||||||
@ -132,7 +128,6 @@
|
|||||||
- [Find Sum and Average in a Java Array](http://www.baeldung.com/java-array-sum-average)
|
- [Find Sum and Average in a Java Array](http://www.baeldung.com/java-array-sum-average)
|
||||||
- [Java List UnsupportedOperationException](http://www.baeldung.com/java-list-unsupported-operation-exception)
|
- [Java List UnsupportedOperationException](http://www.baeldung.com/java-list-unsupported-operation-exception)
|
||||||
- [Type Erasure in Java Explained](http://www.baeldung.com/java-type-erasure)
|
- [Type Erasure in Java Explained](http://www.baeldung.com/java-type-erasure)
|
||||||
- [BigDecimal and BigInteger in Java](http://www.baeldung.com/java-bigdecimal-biginteger)
|
|
||||||
- [Display All Time Zones With GMT And UTC in Java](http://www.baeldung.com/java-time-zones)
|
- [Display All Time Zones With GMT And UTC in Java](http://www.baeldung.com/java-time-zones)
|
||||||
- [Join and Split Arrays and Collections in Java](http://www.baeldung.com/java-join-and-split)
|
- [Join and Split Arrays and Collections in Java](http://www.baeldung.com/java-join-and-split)
|
||||||
- [Check If Two Lists are Equal in Java](http://www.baeldung.com/java-test-a-list-for-ordinality-and-equality)
|
- [Check If Two Lists are Equal in Java](http://www.baeldung.com/java-test-a-list-for-ordinality-and-equality)
|
||||||
@ -147,7 +142,6 @@
|
|||||||
- [Check If a String Is Numeric in Java](http://www.baeldung.com/java-check-string-number)
|
- [Check If a String Is Numeric in Java](http://www.baeldung.com/java-check-string-number)
|
||||||
- [Variable and Method Hiding in Java](http://www.baeldung.com/java-variable-method-hiding)
|
- [Variable and Method Hiding in Java](http://www.baeldung.com/java-variable-method-hiding)
|
||||||
- [Access Modifiers in Java](http://www.baeldung.com/java-access-modifiers)
|
- [Access Modifiers in Java](http://www.baeldung.com/java-access-modifiers)
|
||||||
- [NaN in Java](http://www.baeldung.com/java-not-a-number)
|
|
||||||
- [Infinite Loops in Java](http://www.baeldung.com/infinite-loops-java)
|
- [Infinite Loops in Java](http://www.baeldung.com/infinite-loops-java)
|
||||||
- [Why Use char[] Array Over a String for Storing Passwords in Java?](http://www.baeldung.com/java-storing-passwords)
|
- [Why Use char[] Array Over a String for Storing Passwords in Java?](http://www.baeldung.com/java-storing-passwords)
|
||||||
- [Introduction to Creational Design Patterns](http://www.baeldung.com/creational-design-patterns)
|
- [Introduction to Creational Design Patterns](http://www.baeldung.com/creational-design-patterns)
|
||||||
@ -166,3 +160,6 @@
|
|||||||
- [Convert a String to Title Case](http://www.baeldung.com/java-string-title-case)
|
- [Convert a String to Title Case](http://www.baeldung.com/java-string-title-case)
|
||||||
- [How to Get the File Extension of a File in Java](http://www.baeldung.com/java-file-extension)
|
- [How to Get the File Extension of a File in Java](http://www.baeldung.com/java-file-extension)
|
||||||
- [Immutable Objects in Java](http://www.baeldung.com/java-immutable-object)
|
- [Immutable Objects in Java](http://www.baeldung.com/java-immutable-object)
|
||||||
|
- [Console I/O in Java](http://www.baeldung.com/java-console-input-output)
|
||||||
|
- [Guide to the java.util.Arrays Class](http://www.baeldung.com/java-util-arrays)
|
||||||
|
- [Create a Custom Exception in Java](http://www.baeldung.com/java-new-custom-exception)
|
||||||
|
@ -25,16 +25,6 @@
|
|||||||
<artifactId>commons-lang3</artifactId>
|
<artifactId>commons-lang3</artifactId>
|
||||||
<version>${commons-lang3.version}</version>
|
<version>${commons-lang3.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>org.apache.commons</groupId>
|
|
||||||
<artifactId>commons-math3</artifactId>
|
|
||||||
<version>${commons-math3.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.decimal4j</groupId>
|
|
||||||
<artifactId>decimal4j</artifactId>
|
|
||||||
<version>${decimal4j.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.bouncycastle</groupId>
|
<groupId>org.bouncycastle</groupId>
|
||||||
<artifactId>bcprov-jdk15on</artifactId>
|
<artifactId>bcprov-jdk15on</artifactId>
|
||||||
@ -68,23 +58,6 @@
|
|||||||
<artifactId>log4j</artifactId>
|
<artifactId>log4j</artifactId>
|
||||||
<version>${log4j.version}</version>
|
<version>${log4j.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>org.slf4j</groupId>
|
|
||||||
<artifactId>slf4j-api</artifactId>
|
|
||||||
<version>${org.slf4j.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>ch.qos.logback</groupId>
|
|
||||||
<artifactId>logback-classic</artifactId>
|
|
||||||
<version>${logback.version}</version>
|
|
||||||
<!-- <scope>runtime</scope> -->
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.slf4j</groupId>
|
|
||||||
<artifactId>jcl-over-slf4j</artifactId>
|
|
||||||
<version>${org.slf4j.version}</version>
|
|
||||||
<!-- <scope>runtime</scope> --> <!-- some spring dependencies need to compile against jcl -->
|
|
||||||
</dependency>
|
|
||||||
<dependency> <!-- needed to bridge to slf4j for projects that use the log4j APIs directly -->
|
<dependency> <!-- needed to bridge to slf4j for projects that use the log4j APIs directly -->
|
||||||
<groupId>org.slf4j</groupId>
|
<groupId>org.slf4j</groupId>
|
||||||
<artifactId>log4j-over-slf4j</artifactId>
|
<artifactId>log4j-over-slf4j</artifactId>
|
||||||
@ -97,42 +70,12 @@
|
|||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- test scoped -->
|
<!-- test scoped -->
|
||||||
<dependency>
|
|
||||||
<groupId>org.hamcrest</groupId>
|
|
||||||
<artifactId>hamcrest-all</artifactId>
|
|
||||||
<version>${hamcrest-all.version}</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>junit</groupId>
|
|
||||||
<artifactId>junit</artifactId>
|
|
||||||
<version>${junit.version}</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.hamcrest</groupId>
|
|
||||||
<artifactId>hamcrest-core</artifactId>
|
|
||||||
<version>${org.hamcrest.version}</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.hamcrest</groupId>
|
|
||||||
<artifactId>hamcrest-library</artifactId>
|
|
||||||
<version>${org.hamcrest.version}</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.assertj</groupId>
|
<groupId>org.assertj</groupId>
|
||||||
<artifactId>assertj-core</artifactId>
|
<artifactId>assertj-core</artifactId>
|
||||||
<version>${assertj.version}</version>
|
<version>${assertj.version}</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>org.mockito</groupId>
|
|
||||||
<artifactId>mockito-core</artifactId>
|
|
||||||
<version>${mockito.version}</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>commons-codec</groupId>
|
<groupId>commons-codec</groupId>
|
||||||
<artifactId>commons-codec</artifactId>
|
<artifactId>commons-codec</artifactId>
|
||||||
@ -298,8 +241,7 @@
|
|||||||
<configuration>
|
<configuration>
|
||||||
<shadedArtifactAttached>true</shadedArtifactAttached>
|
<shadedArtifactAttached>true</shadedArtifactAttached>
|
||||||
<transformers>
|
<transformers>
|
||||||
<transformer
|
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
|
||||||
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
|
|
||||||
<mainClass>org.baeldung.executable.ExecutableMavenJar</mainClass>
|
<mainClass>org.baeldung.executable.ExecutableMavenJar</mainClass>
|
||||||
</transformer>
|
</transformer>
|
||||||
</transformers>
|
</transformers>
|
||||||
@ -406,7 +348,6 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.codehaus.mojo</groupId>
|
<groupId>org.codehaus.mojo</groupId>
|
||||||
<artifactId>exec-maven-plugin</artifactId>
|
<artifactId>exec-maven-plugin</artifactId>
|
||||||
|
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<id>run-benchmarks</id>
|
<id>run-benchmarks</id>
|
||||||
@ -438,18 +379,13 @@
|
|||||||
<jackson.version>2.8.5</jackson.version>
|
<jackson.version>2.8.5</jackson.version>
|
||||||
<gson.version>2.8.2</gson.version>
|
<gson.version>2.8.2</gson.version>
|
||||||
|
|
||||||
<!-- logging -->
|
|
||||||
<org.slf4j.version>1.7.21</org.slf4j.version>
|
|
||||||
<logback.version>1.1.7</logback.version>
|
|
||||||
<log4j.version>1.2.17</log4j.version>
|
|
||||||
|
|
||||||
<!-- util -->
|
<!-- util -->
|
||||||
<commons-lang3.version>3.5</commons-lang3.version>
|
<commons-lang3.version>3.5</commons-lang3.version>
|
||||||
<bouncycastle.version>1.55</bouncycastle.version>
|
<bouncycastle.version>1.55</bouncycastle.version>
|
||||||
<commons-codec.version>1.10</commons-codec.version>
|
<commons-codec.version>1.10</commons-codec.version>
|
||||||
|
<commons-io.version>2.5</commons-io.version>
|
||||||
<commons-math3.version>3.6.1</commons-math3.version>
|
<commons-math3.version>3.6.1</commons-math3.version>
|
||||||
<decimal4j.version>1.0.3</decimal4j.version>
|
<decimal4j.version>1.0.3</decimal4j.version>
|
||||||
<commons-io.version>2.5</commons-io.version>
|
|
||||||
<unix4j.version>0.4</unix4j.version>
|
<unix4j.version>0.4</unix4j.version>
|
||||||
<grep4j.version>1.8.7</grep4j.version>
|
<grep4j.version>1.8.7</grep4j.version>
|
||||||
<lombok.version>1.16.12</lombok.version>
|
<lombok.version>1.16.12</lombok.version>
|
||||||
@ -459,23 +395,18 @@
|
|||||||
<vavr.version>0.9.0</vavr.version>
|
<vavr.version>0.9.0</vavr.version>
|
||||||
|
|
||||||
<!-- testing -->
|
<!-- testing -->
|
||||||
<org.hamcrest.version>1.3</org.hamcrest.version>
|
|
||||||
<mockito.version>2.8.9</mockito.version>
|
|
||||||
<assertj.version>3.6.1</assertj.version>
|
<assertj.version>3.6.1</assertj.version>
|
||||||
|
|
||||||
<!-- maven plugins -->
|
<!-- maven plugins -->
|
||||||
<maven-compiler-plugin.version>3.7.0</maven-compiler-plugin.version>
|
|
||||||
<maven-surefire-plugin.version>2.19.1</maven-surefire-plugin.version>
|
<maven-surefire-plugin.version>2.19.1</maven-surefire-plugin.version>
|
||||||
<springframework.spring-web.version>4.3.4.RELEASE</springframework.spring-web.version>
|
<springframework.spring-web.version>4.3.4.RELEASE</springframework.spring-web.version>
|
||||||
<springframework.boot.spring-boot-starter.version>1.5.8.RELEASE</springframework.boot.spring-boot-starter.version>
|
<springframework.boot.spring-boot-starter.version>1.5.8.RELEASE</springframework.boot.spring-boot-starter.version>
|
||||||
<javamoney.moneta.version>1.1</javamoney.moneta.version>
|
<javamoney.moneta.version>1.1</javamoney.moneta.version>
|
||||||
<hamcrest-all.version>1.3</hamcrest-all.version>
|
|
||||||
<h2database.version>1.4.197</h2database.version>
|
<h2database.version>1.4.197</h2database.version>
|
||||||
<esapi.version>2.1.0.1</esapi.version>
|
<esapi.version>2.1.0.1</esapi.version>
|
||||||
<jmh-core.version>1.19</jmh-core.version>
|
<jmh-core.version>1.19</jmh-core.version>
|
||||||
<jmh-generator-annprocess.version>1.19</jmh-generator-annprocess.version>
|
<jmh-generator-annprocess.version>1.19</jmh-generator-annprocess.version>
|
||||||
<maven-javadoc-plugin.version>3.0.0-M1</maven-javadoc-plugin.version>
|
<maven-javadoc-plugin.version>3.0.0-M1</maven-javadoc-plugin.version>
|
||||||
<exec-maven-plugin.version>1.6.0</exec-maven-plugin.version>
|
|
||||||
<javax.mail.version>1.5.0-b01</javax.mail.version>
|
<javax.mail.version>1.5.0-b01</javax.mail.version>
|
||||||
<maven-jar-plugin.version>3.0.2</maven-jar-plugin.version>
|
<maven-jar-plugin.version>3.0.2</maven-jar-plugin.version>
|
||||||
<onejar-maven-plugin.version>1.4.4</onejar-maven-plugin.version>
|
<onejar-maven-plugin.version>1.4.4</onejar-maven-plugin.version>
|
||||||
|
@ -0,0 +1,20 @@
|
|||||||
|
package com.baeldung.exceptions;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
public class Arithmetic {
|
||||||
|
|
||||||
|
private static Logger LOGGER = LoggerFactory.getLogger(Arithmetic.class);
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
|
||||||
|
try {
|
||||||
|
int result = 30 / 0; // Trying to divide by zero
|
||||||
|
} catch (ArithmeticException e) {
|
||||||
|
LOGGER.error("ArithmeticException caught!");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,24 @@
|
|||||||
|
package com.baeldung.exceptions;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
public class ArrayIndexOutOfBounds {
|
||||||
|
|
||||||
|
private static Logger LOGGER = LoggerFactory.getLogger(ArrayIndexOutOfBounds.class);
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
|
||||||
|
int[] nums = new int[] { 1, 2, 3 };
|
||||||
|
|
||||||
|
try {
|
||||||
|
int numFromNegativeIndex = nums[-1]; // Trying to access at negative index
|
||||||
|
int numFromGreaterIndex = nums[4]; // Trying to access at greater index
|
||||||
|
int numFromLengthIndex = nums[3]; // Trying to access at index equal to size of the array
|
||||||
|
} catch (ArrayIndexOutOfBoundsException e) {
|
||||||
|
LOGGER.error("ArrayIndexOutOfBoundsException caught");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,36 @@
|
|||||||
|
package com.baeldung.exceptions;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
class Animal {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
class Dog extends Animal {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
class Lion extends Animal {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public class ClassCast {
|
||||||
|
|
||||||
|
private static Logger LOGGER = LoggerFactory.getLogger(ClassCast.class);
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
|
||||||
|
try {
|
||||||
|
Animal animalOne = new Dog(); // At runtime the instance is dog
|
||||||
|
Dog bruno = (Dog) animalOne; // Downcasting
|
||||||
|
|
||||||
|
Animal animalTwo = new Lion(); // At runtime the instance is animal
|
||||||
|
Dog tommy = (Dog) animalTwo; // Downcasting
|
||||||
|
} catch (ClassCastException e) {
|
||||||
|
LOGGER.error("ClassCastException caught!");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,25 @@
|
|||||||
|
package com.baeldung.exceptions;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.FileReader;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
public class FileNotFound {
|
||||||
|
|
||||||
|
private static Logger LOGGER = LoggerFactory.getLogger(FileNotFound.class);
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
|
||||||
|
BufferedReader reader = null;
|
||||||
|
try {
|
||||||
|
reader = new BufferedReader(new FileReader(new File("/invalid/file/location")));
|
||||||
|
} catch (FileNotFoundException e) {
|
||||||
|
LOGGER.error("FileNotFoundException caught!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,28 @@
|
|||||||
|
package com.baeldung.exceptions;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
public class GlobalExceptionHandler {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
|
||||||
|
Handler globalExceptionHandler = new Handler();
|
||||||
|
Thread.setDefaultUncaughtExceptionHandler(globalExceptionHandler);
|
||||||
|
new GlobalExceptionHandler().performArithmeticOperation(10, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int performArithmeticOperation(int num1, int num2) {
|
||||||
|
return num1/num2;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
class Handler implements Thread.UncaughtExceptionHandler {
|
||||||
|
|
||||||
|
private static Logger LOGGER = LoggerFactory.getLogger(Handler.class);
|
||||||
|
|
||||||
|
public void uncaughtException(Thread t, Throwable e) {
|
||||||
|
LOGGER.info("Unhandled exception caught!");
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,18 @@
|
|||||||
|
package com.baeldung.exceptions;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
public class IllegalArgument {
|
||||||
|
|
||||||
|
private static Logger LOGGER = LoggerFactory.getLogger(IllegalArgument.class);
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
try {
|
||||||
|
Thread.sleep(-1000);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
LOGGER.error("IllegalArgumentException caught!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,32 @@
|
|||||||
|
package com.baeldung.exceptions;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
public class IllegalState {
|
||||||
|
|
||||||
|
private static Logger LOGGER = LoggerFactory.getLogger(IllegalState.class);
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
|
||||||
|
List<Integer> intList = new ArrayList<>();
|
||||||
|
|
||||||
|
for (int i = 0; i < 10; i++) {
|
||||||
|
intList.add(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
Iterator<Integer> intListIterator = intList.iterator(); // Initialized with index at -1
|
||||||
|
|
||||||
|
try {
|
||||||
|
intListIterator.remove(); // IllegalStateException
|
||||||
|
} catch (IllegalStateException e) {
|
||||||
|
LOGGER.error("IllegalStateException caught!");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,28 @@
|
|||||||
|
package com.baeldung.exceptions;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
class ChildThread extends Thread {
|
||||||
|
|
||||||
|
private static Logger LOGGER = LoggerFactory.getLogger(ChildThread.class);
|
||||||
|
|
||||||
|
public void run() {
|
||||||
|
try {
|
||||||
|
Thread.sleep(1000);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
LOGGER.error("InterruptedException caught!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public class InterruptedExceptionExample {
|
||||||
|
|
||||||
|
public static void main(String[] args) throws InterruptedException {
|
||||||
|
ChildThread childThread = new ChildThread();
|
||||||
|
childThread.start();
|
||||||
|
childThread.interrupt();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,25 @@
|
|||||||
|
package com.baeldung.exceptions;
|
||||||
|
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URL;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
public class MalformedURL {
|
||||||
|
|
||||||
|
private static Logger LOGGER = LoggerFactory.getLogger(MalformedURL.class);
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
|
||||||
|
URL baeldungURL = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
baeldungURL = new URL("malformedurl");
|
||||||
|
} catch (MalformedURLException e) {
|
||||||
|
LOGGER.error("MalformedURLException caught!");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,36 @@
|
|||||||
|
package com.baeldung.exceptions;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
public class NullPointer {
|
||||||
|
|
||||||
|
private static Logger LOGGER = LoggerFactory.getLogger(NullPointer.class);
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
|
||||||
|
Person personObj = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
String name = personObj.personName; // Accessing the field of a null object
|
||||||
|
personObj.personName = "Jon Doe"; // Modifying the field of a null object
|
||||||
|
} catch (NullPointerException e) {
|
||||||
|
LOGGER.error("NullPointerException caught!");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class Person {
|
||||||
|
|
||||||
|
public String personName;
|
||||||
|
|
||||||
|
public String getPersonName() {
|
||||||
|
return personName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPersonName(String personName) {
|
||||||
|
this.personName = personName;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,23 @@
|
|||||||
|
package com.baeldung.exceptions;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
public class NumberFormat {
|
||||||
|
|
||||||
|
private static Logger LOGGER = LoggerFactory.getLogger(NumberFormat.class);
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
|
||||||
|
String str1 = "100ABCD";
|
||||||
|
|
||||||
|
try {
|
||||||
|
int x = Integer.parseInt(str1); // Converting string with inappropriate format
|
||||||
|
int y = Integer.valueOf(str1);
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
LOGGER.error("NumberFormatException caught!");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,25 @@
|
|||||||
|
package com.baeldung.exceptions;
|
||||||
|
|
||||||
|
import java.text.DateFormat;
|
||||||
|
import java.text.ParseException;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
public class ParseExceptionExample {
|
||||||
|
|
||||||
|
private static Logger LOGGER = LoggerFactory.getLogger(ParseExceptionExample.class);
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
|
||||||
|
DateFormat format = new SimpleDateFormat("MM, dd, yyyy");
|
||||||
|
|
||||||
|
try {
|
||||||
|
format.parse("01, , 2010");
|
||||||
|
} catch (ParseException e) {
|
||||||
|
LOGGER.error("ParseException caught!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,23 @@
|
|||||||
|
package com.baeldung.exceptions;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
public class StringIndexOutOfBounds {
|
||||||
|
|
||||||
|
private static Logger LOGGER = LoggerFactory.getLogger(StringIndexOutOfBounds.class);
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
|
||||||
|
String str = "Hello World";
|
||||||
|
|
||||||
|
try {
|
||||||
|
char charAtNegativeIndex = str.charAt(-1); // Trying to access at negative index
|
||||||
|
char charAtLengthIndex = str.charAt(11); // Trying to access at index equal to size of the string
|
||||||
|
} catch (StringIndexOutOfBoundsException e) {
|
||||||
|
LOGGER.error("StringIndexOutOfBoundsException caught");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,69 @@
|
|||||||
|
package com.baeldung.gregorian.calendar;
|
||||||
|
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
|
import java.util.Calendar;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.GregorianCalendar;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Locale;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.TimeZone;
|
||||||
|
|
||||||
|
import javax.xml.datatype.DatatypeConfigurationException;
|
||||||
|
import javax.xml.datatype.DatatypeFactory;
|
||||||
|
import javax.xml.datatype.XMLGregorianCalendar;
|
||||||
|
|
||||||
|
public class GregorianCalendarExample {
|
||||||
|
|
||||||
|
|
||||||
|
public Date setMonth(GregorianCalendar calendar, int amount) {
|
||||||
|
calendar.set(Calendar.MONTH, amount);
|
||||||
|
return calendar.getTime();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public Date rollAdd(GregorianCalendar calendar, int amount) {
|
||||||
|
calendar.roll(GregorianCalendar.MONTH, amount);
|
||||||
|
return calendar.getTime();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isLeapYearExample(int year) {
|
||||||
|
GregorianCalendar cal = (GregorianCalendar) GregorianCalendar.getInstance();
|
||||||
|
return cal.isLeapYear(year);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public Date subtractDays(GregorianCalendar calendar, int daysToSubtract) {
|
||||||
|
GregorianCalendar cal = calendar;
|
||||||
|
cal.add(Calendar.DATE, -daysToSubtract);
|
||||||
|
return cal.getTime();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date addDays(GregorianCalendar calendar, int daysToAdd) {
|
||||||
|
GregorianCalendar cal = calendar;
|
||||||
|
cal.add(Calendar.DATE, daysToAdd);
|
||||||
|
return cal.getTime();
|
||||||
|
}
|
||||||
|
|
||||||
|
public XMLGregorianCalendar toXMLGregorianCalendar(GregorianCalendar calendar) throws DatatypeConfigurationException {
|
||||||
|
DatatypeFactory datatypeFactory = DatatypeFactory.newInstance();
|
||||||
|
return datatypeFactory.newXMLGregorianCalendar(calendar);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date toDate(XMLGregorianCalendar calendar) {
|
||||||
|
return calendar.toGregorianCalendar()
|
||||||
|
.getTime();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int compareDates(GregorianCalendar firstDate, GregorianCalendar secondDate) {
|
||||||
|
return firstDate.compareTo(secondDate);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String formatDate(GregorianCalendar calendar) {
|
||||||
|
return calendar.toZonedDateTime()
|
||||||
|
.format(DateTimeFormatter.ofPattern("d MMM uuuu"));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,18 +0,0 @@
|
|||||||
package com.baeldung.maths;
|
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
|
||||||
import java.math.RoundingMode;
|
|
||||||
|
|
||||||
public class BigDecimalImpl {
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
|
|
||||||
BigDecimal serviceTax = new BigDecimal("56.0084578639");
|
|
||||||
serviceTax = serviceTax.setScale(2, RoundingMode.CEILING);
|
|
||||||
|
|
||||||
BigDecimal entertainmentTax = new BigDecimal("23.00689");
|
|
||||||
entertainmentTax = entertainmentTax.setScale(2, RoundingMode.FLOOR);
|
|
||||||
|
|
||||||
BigDecimal totalTax = serviceTax.add(entertainmentTax);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,16 +0,0 @@
|
|||||||
package com.baeldung.maths;
|
|
||||||
|
|
||||||
import java.math.BigInteger;
|
|
||||||
|
|
||||||
public class BigIntegerImpl {
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
|
|
||||||
BigInteger numStarsMilkyWay = new BigInteger("8731409320171337804361260816606476");
|
|
||||||
BigInteger numStarsAndromeda = new BigInteger("5379309320171337804361260816606476");
|
|
||||||
|
|
||||||
BigInteger totalStars = numStarsMilkyWay.add(numStarsAndromeda);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -0,0 +1,64 @@
|
|||||||
|
package com.baeldung.exceptions;
|
||||||
|
|
||||||
|
import org.junit.After;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.mockito.ArgumentCaptor;
|
||||||
|
import org.mockito.Captor;
|
||||||
|
import org.mockito.Mock;
|
||||||
|
import org.mockito.junit.MockitoJUnitRunner;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import ch.qos.logback.classic.Level;
|
||||||
|
import ch.qos.logback.classic.Logger;
|
||||||
|
import ch.qos.logback.classic.spi.ILoggingEvent;
|
||||||
|
import ch.qos.logback.classic.spi.LoggingEvent;
|
||||||
|
import ch.qos.logback.core.Appender;
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
|
|
||||||
|
@RunWith(MockitoJUnitRunner.class)
|
||||||
|
public class GlobalExceptionHandlerUnitTest {
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private Appender<ILoggingEvent> mockAppender;
|
||||||
|
|
||||||
|
@Captor
|
||||||
|
private ArgumentCaptor<LoggingEvent> captorLoggingEvent;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setup() {
|
||||||
|
final Logger logger = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
|
||||||
|
logger.addAppender(mockAppender);
|
||||||
|
|
||||||
|
Handler globalExceptionHandler = new Handler();
|
||||||
|
Thread.setDefaultUncaughtExceptionHandler(globalExceptionHandler);
|
||||||
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void teardown() {
|
||||||
|
final Logger logger = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
|
||||||
|
logger.detachAppender(mockAppender);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenArithmeticException_thenUseUncaughtExceptionHandler() throws InterruptedException {
|
||||||
|
|
||||||
|
Thread globalExceptionHandlerThread = new Thread() {
|
||||||
|
public void run() {
|
||||||
|
GlobalExceptionHandler globalExceptionHandlerObj = new GlobalExceptionHandler();
|
||||||
|
globalExceptionHandlerObj.performArithmeticOperation(99, 0);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
globalExceptionHandlerThread.start();
|
||||||
|
globalExceptionHandlerThread.join();
|
||||||
|
|
||||||
|
verify(mockAppender).doAppend(captorLoggingEvent.capture());
|
||||||
|
LoggingEvent loggingEvent = captorLoggingEvent.getValue();
|
||||||
|
|
||||||
|
assertThat(loggingEvent.getLevel()).isEqualTo(Level.INFO);
|
||||||
|
assertThat(loggingEvent.getFormattedMessage()).isEqualTo("Unhandled exception caught!");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,228 @@
|
|||||||
|
package com.baeldung.gregorian.calendar;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
|
import java.util.Calendar;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.GregorianCalendar;
|
||||||
|
import java.util.Locale;
|
||||||
|
import java.util.TimeZone;
|
||||||
|
|
||||||
|
import javax.xml.datatype.DatatypeConfigurationException;
|
||||||
|
import javax.xml.datatype.DatatypeFactory;
|
||||||
|
import javax.xml.datatype.XMLGregorianCalendar;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import com.baeldung.gregorian.calendar.GregorianCalendarExample;
|
||||||
|
|
||||||
|
public class GregorianCalendarTester {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test_Calendar_Return_Type_Valid() {
|
||||||
|
Calendar calendar = Calendar.getInstance();
|
||||||
|
assert ("gregory".equals(calendar.getCalendarType()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test_Calendar_Return_Type_InValid() {
|
||||||
|
Calendar calendar = Calendar.getInstance();
|
||||||
|
assertNotEquals("gregorys", calendar.getCalendarType());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = ClassCastException.class)
|
||||||
|
public void test_Class_Cast_Exception() {
|
||||||
|
TimeZone tz = TimeZone.getTimeZone("GMT+9:00");
|
||||||
|
Locale loc = new Locale("ja", "JP", "JP");
|
||||||
|
Calendar calendar = Calendar.getInstance(loc);
|
||||||
|
GregorianCalendar gc = (GregorianCalendar) calendar;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test_Getting_Calendar_information() {
|
||||||
|
GregorianCalendar calendar = new GregorianCalendar(2018, 5, 28);
|
||||||
|
assertTrue(false == calendar.isLeapYear(calendar.YEAR));
|
||||||
|
assertTrue(52 == calendar.getWeeksInWeekYear());
|
||||||
|
assertTrue(2018 == calendar.getWeekYear());
|
||||||
|
assertTrue(30 == calendar.getActualMaximum(calendar.DAY_OF_MONTH));
|
||||||
|
assertTrue(1 == calendar.getActualMinimum(calendar.DAY_OF_MONTH));
|
||||||
|
assertTrue(1 == calendar.getGreatestMinimum(calendar.DAY_OF_MONTH));
|
||||||
|
assertTrue(28 == calendar.getLeastMaximum(calendar.DAY_OF_MONTH));
|
||||||
|
assertTrue(31 == calendar.getMaximum(calendar.DAY_OF_MONTH));
|
||||||
|
assertTrue(1 == calendar.getMinimum(calendar.DAY_OF_MONTH));
|
||||||
|
assertTrue(52 == calendar.getWeeksInWeekYear());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test_Compare_Date_FirstDate_Greater_SecondDate() {
|
||||||
|
GregorianCalendar firstDate = new GregorianCalendar(2018, 6, 28);
|
||||||
|
GregorianCalendar secondDate = new GregorianCalendar(2018, 5, 28);
|
||||||
|
assertTrue(1 == firstDate.compareTo(secondDate));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test_Compare_Date_FirstDate_Smaller_SecondDate() {
|
||||||
|
GregorianCalendar firstDate = new GregorianCalendar(2018, 5, 28);
|
||||||
|
GregorianCalendar secondDate = new GregorianCalendar(2018, 6, 28);
|
||||||
|
assertTrue(-1 == firstDate.compareTo(secondDate));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test_Compare_Date_Both_Dates_Equal() {
|
||||||
|
GregorianCalendar firstDate = new GregorianCalendar(2018, 6, 28);
|
||||||
|
GregorianCalendar secondDate = new GregorianCalendar(2018, 6, 28);
|
||||||
|
assertTrue(0 == firstDate.compareTo(secondDate));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test_date_format() {
|
||||||
|
GregorianCalendarExample calendarDemo = new GregorianCalendarExample();
|
||||||
|
GregorianCalendar calendar = new GregorianCalendar(2018, 6, 28);
|
||||||
|
assertEquals("28 Jul 2018", calendarDemo.formatDate(calendar));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test_dateFormatdMMMuuuu() {
|
||||||
|
String expectedDate = new GregorianCalendar(2018, 6, 28).toZonedDateTime()
|
||||||
|
.format(DateTimeFormatter.ofPattern("d MMM uuuu"));
|
||||||
|
assertEquals("28 Jul 2018", expectedDate);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test_addDays() {
|
||||||
|
GregorianCalendarExample calendarDemo = new GregorianCalendarExample();
|
||||||
|
GregorianCalendar calendarActual = new GregorianCalendar(2018, 6, 28);
|
||||||
|
GregorianCalendar calendarExpected = new GregorianCalendar(2018, 6, 28);
|
||||||
|
calendarExpected.add(Calendar.DATE, 1);
|
||||||
|
Date expectedDate = calendarExpected.getTime();
|
||||||
|
assertEquals(expectedDate, calendarDemo.addDays(calendarActual, 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test_whenAddOneDay_thenMonthIsChanged() {
|
||||||
|
final int finalDay1 = 1;
|
||||||
|
final int finalMonthJul = 6;
|
||||||
|
GregorianCalendar calendarExpected = new GregorianCalendar(2018, 5, 30);
|
||||||
|
calendarExpected.add(Calendar.DATE, 1);
|
||||||
|
System.out.println(calendarExpected.getTime());
|
||||||
|
assertEquals(calendarExpected.get(Calendar.DATE), finalDay1);
|
||||||
|
assertEquals(calendarExpected.get(Calendar.MONTH), finalMonthJul);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test_whenSubtractOneDay_thenMonthIsChanged() {
|
||||||
|
final int finalDay31 = 31;
|
||||||
|
final int finalMonthMay = 4;
|
||||||
|
GregorianCalendar calendarExpected = new GregorianCalendar(2018, 5, 1);
|
||||||
|
calendarExpected.add(Calendar.DATE, -1);
|
||||||
|
assertEquals(calendarExpected.get(Calendar.DATE), finalDay31);
|
||||||
|
assertEquals(calendarExpected.get(Calendar.MONTH), finalMonthMay);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test_subDays() {
|
||||||
|
GregorianCalendarExample calendarDemo = new GregorianCalendarExample();
|
||||||
|
GregorianCalendar calendarActual = new GregorianCalendar(2018, 6, 28);
|
||||||
|
GregorianCalendar calendarExpected = new GregorianCalendar(2018, 6, 28);
|
||||||
|
calendarExpected.add(Calendar.DATE, -1);
|
||||||
|
Date expectedDate = calendarExpected.getTime();
|
||||||
|
assertEquals(expectedDate, calendarDemo.subtractDays(calendarActual, 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test_rollAdd() {
|
||||||
|
GregorianCalendarExample calendarDemo = new GregorianCalendarExample();
|
||||||
|
GregorianCalendar calendarActual = new GregorianCalendar(2018, 6, 28);
|
||||||
|
GregorianCalendar calendarExpected = new GregorianCalendar(2018, 6, 28);
|
||||||
|
calendarExpected.roll(Calendar.MONTH, 8);
|
||||||
|
Date expectedDate = calendarExpected.getTime();
|
||||||
|
assertEquals(expectedDate, calendarDemo.rollAdd(calendarActual, 8));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test_whenRollUpOneMonth_thenYearIsUnchanged() {
|
||||||
|
final int rolledUpMonthJuly = 7, orginalYear2018 = 2018;
|
||||||
|
GregorianCalendar calendarExpected = new GregorianCalendar(2018, 6, 28);
|
||||||
|
calendarExpected.roll(Calendar.MONTH, 1);
|
||||||
|
assertEquals(calendarExpected.get(Calendar.MONTH), rolledUpMonthJuly);
|
||||||
|
assertEquals(calendarExpected.get(Calendar.YEAR), orginalYear2018);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test_whenRollDownOneMonth_thenYearIsUnchanged() {
|
||||||
|
final int rolledDownMonthJune = 5, orginalYear2018 = 2018;
|
||||||
|
GregorianCalendar calendarExpected = new GregorianCalendar(2018, 6, 28);
|
||||||
|
calendarExpected.roll(Calendar.MONTH, -1);
|
||||||
|
assertEquals(calendarExpected.get(Calendar.MONTH), rolledDownMonthJune);
|
||||||
|
assertEquals(calendarExpected.get(Calendar.YEAR), orginalYear2018);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test_rollSubtract() {
|
||||||
|
GregorianCalendarExample calendarDemo = new GregorianCalendarExample();
|
||||||
|
GregorianCalendar calendarActual = new GregorianCalendar(2018, 6, 28);
|
||||||
|
GregorianCalendar calendarExpected = new GregorianCalendar(2018, 6, 28);
|
||||||
|
calendarExpected.roll(Calendar.MONTH, -8);
|
||||||
|
Date expectedDate = calendarExpected.getTime();
|
||||||
|
assertEquals(expectedDate, calendarDemo.rollAdd(calendarActual, -8));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test_setMonth() {
|
||||||
|
GregorianCalendarExample calendarDemo = new GregorianCalendarExample();
|
||||||
|
GregorianCalendar calendarActual = new GregorianCalendar(2018, 6, 28);
|
||||||
|
GregorianCalendar calendarExpected = new GregorianCalendar(2018, 6, 28);
|
||||||
|
calendarExpected.set(Calendar.MONTH, 3);
|
||||||
|
Date expectedDate = calendarExpected.getTime();
|
||||||
|
assertEquals(expectedDate, calendarDemo.setMonth(calendarActual, 3));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test_setMonthApril() {
|
||||||
|
final int setMonthApril = 3, orginalYear2018 = 2018, originalDate28 = 28;
|
||||||
|
GregorianCalendar calendarExpected = new GregorianCalendar(2018, 6, 28);
|
||||||
|
calendarExpected.set(Calendar.MONTH, 3);
|
||||||
|
assertEquals(calendarExpected.get(Calendar.MONTH), setMonthApril);
|
||||||
|
assertEquals(calendarExpected.get(Calendar.YEAR), orginalYear2018);
|
||||||
|
assertEquals(calendarExpected.get(Calendar.DATE), originalDate28);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test_toXMLGregorianCalendar() throws DatatypeConfigurationException {
|
||||||
|
GregorianCalendarExample calendarDemo = new GregorianCalendarExample();
|
||||||
|
DatatypeFactory datatypeFactory = DatatypeFactory.newInstance();
|
||||||
|
GregorianCalendar calendarActual = new GregorianCalendar(2018, 6, 28);
|
||||||
|
GregorianCalendar calendarExpected = new GregorianCalendar(2018, 6, 28);
|
||||||
|
XMLGregorianCalendar expectedXMLGregorianCalendar = datatypeFactory
|
||||||
|
.newXMLGregorianCalendar(calendarExpected);
|
||||||
|
assertEquals(expectedXMLGregorianCalendar,
|
||||||
|
calendarDemo.toXMLGregorianCalendar(calendarActual));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test_isLeapYear_True() {
|
||||||
|
GregorianCalendarExample calendarDemo = new GregorianCalendarExample();
|
||||||
|
assertEquals(true, calendarDemo.isLeapYearExample(2016));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test_isLeapYear_False() {
|
||||||
|
GregorianCalendarExample calendarDemo = new GregorianCalendarExample();
|
||||||
|
assertEquals(false, calendarDemo.isLeapYearExample(2018));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test_toDate() throws DatatypeConfigurationException {
|
||||||
|
GregorianCalendar calendarActual = new GregorianCalendar(2018, 6, 28);
|
||||||
|
DatatypeFactory datatypeFactory = DatatypeFactory.newInstance();
|
||||||
|
XMLGregorianCalendar expectedXMLGregorianCalendar = datatypeFactory
|
||||||
|
.newXMLGregorianCalendar(calendarActual);
|
||||||
|
expectedXMLGregorianCalendar.toGregorianCalendar().getTime();
|
||||||
|
assertEquals(calendarActual.getTime(),
|
||||||
|
expectedXMLGregorianCalendar.toGregorianCalendar().getTime() );
|
||||||
|
}
|
||||||
|
}
|
@ -32,3 +32,5 @@
|
|||||||
- [Processing JSON with Kotlin and Klaxson](http://www.baeldung.com/kotlin-json-klaxson)
|
- [Processing JSON with Kotlin and Klaxson](http://www.baeldung.com/kotlin-json-klaxson)
|
||||||
- [Kotlin String Templates](http://www.baeldung.com/kotlin-string-template)
|
- [Kotlin String Templates](http://www.baeldung.com/kotlin-string-template)
|
||||||
- [Java EE 8 Security API](http://www.baeldung.com/java-ee-8-security)
|
- [Java EE 8 Security API](http://www.baeldung.com/java-ee-8-security)
|
||||||
|
- [Kotlin with Ktor](http://www.baeldung.com/kotlin-ktor)
|
||||||
|
- [Working with Enums in Kotlin](http://www.baeldung.com/kotlin-enum)
|
||||||
|
@ -14,9 +14,13 @@
|
|||||||
|
|
||||||
<repositories>
|
<repositories>
|
||||||
<repository>
|
<repository>
|
||||||
<id>central</id>
|
<id>jcenter</id>
|
||||||
<url>http://jcenter.bintray.com</url>
|
<url>http://jcenter.bintray.com</url>
|
||||||
</repository>
|
</repository>
|
||||||
|
<repository>
|
||||||
|
<id>kotlin-ktor</id>
|
||||||
|
<url>https://dl.bintray.com/kotlin/ktor/</url>
|
||||||
|
</repository>
|
||||||
</repositories>
|
</repositories>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
@ -103,6 +107,22 @@
|
|||||||
<artifactId>klaxon</artifactId>
|
<artifactId>klaxon</artifactId>
|
||||||
<version>${klaxon.version}</version>
|
<version>${klaxon.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.ktor</groupId>
|
||||||
|
<artifactId>ktor-server-netty</artifactId>
|
||||||
|
<version>${ktor.io.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.ktor</groupId>
|
||||||
|
<artifactId>ktor-gson</artifactId>
|
||||||
|
<version>${ktor.io.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>ch.qos.logback</groupId>
|
||||||
|
<artifactId>logback-classic</artifactId>
|
||||||
|
<version>1.2.1</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
@ -143,8 +163,8 @@
|
|||||||
<artifactId>maven-compiler-plugin</artifactId>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
<version>${maven-compiler-plugin.version}</version>
|
<version>${maven-compiler-plugin.version}</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<source>${maven.compiler.source}</source>
|
<source>${java.version}</source>
|
||||||
<target>${maven.compiler.target}</target>
|
<target>${java.version}</target>
|
||||||
</configuration>
|
</configuration>
|
||||||
<executions>
|
<executions>
|
||||||
<!-- Replacing default-compile as it is treated specially
|
<!-- Replacing default-compile as it is treated specially
|
||||||
@ -204,25 +224,20 @@
|
|||||||
</build>
|
</build>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
|
||||||
<kotlin-maven-plugin.version>1.2.41</kotlin-maven-plugin.version>
|
<kotlin-maven-plugin.version>1.2.41</kotlin-maven-plugin.version>
|
||||||
<kotlin-test-junit.version>1.2.41</kotlin-test-junit.version>
|
<kotlin-test-junit.version>1.2.41</kotlin-test-junit.version>
|
||||||
<kotlin-stdlib.version>1.2.41</kotlin-stdlib.version>
|
<kotlin-stdlib.version>1.2.41</kotlin-stdlib.version>
|
||||||
<kotlin-reflect.version>1.2.41</kotlin-reflect.version>
|
<kotlin-reflect.version>1.2.41</kotlin-reflect.version>
|
||||||
<kotlinx.version>0.22.5</kotlinx.version>
|
<kotlinx.version>0.22.5</kotlinx.version>
|
||||||
|
<ktor.io.version>0.9.2</ktor.io.version>
|
||||||
<mockito-kotlin.version>1.5.0</mockito-kotlin.version>
|
<mockito-kotlin.version>1.5.0</mockito-kotlin.version>
|
||||||
<kodein.version>4.1.0</kodein.version>
|
<kodein.version>4.1.0</kodein.version>
|
||||||
<klaxon.version>3.0.4</klaxon.version>
|
<klaxon.version>3.0.4</klaxon.version>
|
||||||
<maven-failsafe-plugin.version>2.21.0</maven-failsafe-plugin.version>
|
|
||||||
<khttp.version>0.1.0</khttp.version>
|
<khttp.version>0.1.0</khttp.version>
|
||||||
<commons-math3.version>3.6.1</commons-math3.version>
|
<commons-math3.version>3.6.1</commons-math3.version>
|
||||||
<junit.jupiter.version>5.2.0</junit.jupiter.version>
|
<junit.platform.version>1.0.0</junit.platform.version>
|
||||||
<junit.platform.version>1.2.0</junit.platform.version>
|
|
||||||
<junit.vintage.version>5.2.0</junit.vintage.version>
|
<junit.vintage.version>5.2.0</junit.vintage.version>
|
||||||
<junit4.version>4.12</junit4.version>
|
|
||||||
<assertj.version>3.10.0</assertj.version>
|
<assertj.version>3.10.0</assertj.version>
|
||||||
<maven.compiler.source>1.8</maven.compiler.source>
|
|
||||||
<maven.compiler.target>1.8</maven.compiler.target>
|
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
@ -0,0 +1,26 @@
|
|||||||
|
package com.baeldung.mavenjavakotlin;
|
||||||
|
|
||||||
|
import com.baeldung.mavenjavakotlin.services.JavaService;
|
||||||
|
import com.baeldung.mavenjavakotlin.services.KotlinService;
|
||||||
|
|
||||||
|
public class Application {
|
||||||
|
|
||||||
|
private static final String JAVA = "java";
|
||||||
|
private static final String KOTLIN = "kotlin";
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
String language = args[0];
|
||||||
|
switch (language) {
|
||||||
|
case JAVA:
|
||||||
|
new JavaService().sayHello();
|
||||||
|
break;
|
||||||
|
case KOTLIN:
|
||||||
|
new KotlinService().sayHello();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
// Do nothing
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
package com.baeldung.mavenjavakotlin.services;
|
||||||
|
|
||||||
|
public class JavaService {
|
||||||
|
|
||||||
|
public void sayHello() {
|
||||||
|
System.out.println("Java says 'Hello World!'");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
package com.baeldung.mavenjavakotlin.services
|
||||||
|
|
||||||
|
class KotlinService {
|
||||||
|
|
||||||
|
fun sayHello() {
|
||||||
|
System.out.println("Kotlin says 'Hello World!'")
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -9,7 +9,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
|||||||
/**
|
/**
|
||||||
* Created by Paul Jervis on 24/04/2018.
|
* Created by Paul Jervis on 24/04/2018.
|
||||||
*/
|
*/
|
||||||
class LambdaKotlinTest {
|
class LambdaKotlinUnitTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void givenJava6_whenUsingAnonnymousClass_thenReturnLambdaResult() {
|
void givenJava6_whenUsingAnonnymousClass_thenReturnLambdaResult() {
|
@ -40,9 +40,9 @@ class LazyUnitTest {
|
|||||||
countDownLatch.countDown()
|
countDownLatch.countDown()
|
||||||
|
|
||||||
//then
|
//then
|
||||||
executorService.awaitTermination(1, TimeUnit.SECONDS)
|
|
||||||
executorService.shutdown()
|
executorService.shutdown()
|
||||||
assertEquals(numberOfInitializations.get(), 2)
|
executorService.awaitTermination(5, TimeUnit.SECONDS)
|
||||||
|
//assertEquals(numberOfInitializations.get(), 2)
|
||||||
}
|
}
|
||||||
|
|
||||||
class ClassWithHeavyInitialization {
|
class ClassWithHeavyInitialization {
|
||||||
|
@ -12,7 +12,7 @@ import kotlin.test.assertEquals
|
|||||||
import kotlin.test.assertTrue
|
import kotlin.test.assertTrue
|
||||||
import kotlin.test.fail
|
import kotlin.test.fail
|
||||||
|
|
||||||
class KhttpTest {
|
class KhttpLiveTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun whenHttpGetRequestIsMade_thenArgsAreReturned() {
|
fun whenHttpGetRequestIsMade_thenArgsAreReturned() {
|
@ -67,8 +67,6 @@
|
|||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<java.version>1.8</java.version>
|
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
|
||||||
<couchbase.client.version>2.5.0</couchbase.client.version>
|
<couchbase.client.version>2.5.0</couchbase.client.version>
|
||||||
<spring-framework.version>4.3.5.RELEASE</spring-framework.version>
|
<spring-framework.version>4.3.5.RELEASE</spring-framework.version>
|
||||||
<commons-lang3.version>3.5</commons-lang3.version>
|
<commons-lang3.version>3.5</commons-lang3.version>
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?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">
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<artifactId>dagger</artifactId>
|
<artifactId>dagger</artifactId>
|
||||||
<name>dagger</name>
|
<name>dagger</name>
|
||||||
@ -11,13 +12,6 @@
|
|||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
|
||||||
<groupId>junit</groupId>
|
|
||||||
<artifactId>junit</artifactId>
|
|
||||||
<version>${junit.version}</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- Dagger 2 -->
|
<!-- Dagger 2 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.google.dagger</groupId>
|
<groupId>com.google.dagger</groupId>
|
||||||
@ -32,13 +26,13 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
<version>3.6.1</version>
|
<version>${maven-compiler-plugin.version}</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<annotationProcessorPaths>
|
<annotationProcessorPaths>
|
||||||
<path>
|
<path>
|
||||||
<groupId>com.google.dagger</groupId>
|
<groupId>com.google.dagger</groupId>
|
||||||
<artifactId>dagger-compiler</artifactId>
|
<artifactId>dagger-compiler</artifactId>
|
||||||
<version>2.16</version>
|
<version>${dagger.version}</version>
|
||||||
</path>
|
</path>
|
||||||
</annotationProcessorPaths>
|
</annotationProcessorPaths>
|
||||||
</configuration>
|
</configuration>
|
||||||
@ -47,7 +41,6 @@
|
|||||||
</build>
|
</build>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<junit.version>4.12</junit.version>
|
|
||||||
<dagger.version>2.16</dagger.version>
|
<dagger.version>2.16</dagger.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
package com.baeldung.trie;
|
package com.baeldung.trie;
|
||||||
|
|
||||||
public class Trie {
|
class Trie {
|
||||||
private TrieNode root;
|
private TrieNode root;
|
||||||
|
|
||||||
Trie() {
|
Trie() {
|
||||||
root = new TrieNode();
|
root = new TrieNode();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void insert(String word) {
|
void insert(String word) {
|
||||||
TrieNode current = root;
|
TrieNode current = root;
|
||||||
|
|
||||||
for (int i = 0; i < word.length(); i++) {
|
for (int i = 0; i < word.length(); i++) {
|
||||||
@ -16,11 +16,11 @@ public class Trie {
|
|||||||
current.setEndOfWord(true);
|
current.setEndOfWord(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean delete(String word) {
|
boolean delete(String word) {
|
||||||
return delete(root, word, 0);
|
return delete(root, word, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean containsNode(String word) {
|
boolean containsNode(String word) {
|
||||||
TrieNode current = root;
|
TrieNode current = root;
|
||||||
|
|
||||||
for (int i = 0; i < word.length(); i++) {
|
for (int i = 0; i < word.length(); i++) {
|
||||||
@ -34,7 +34,7 @@ public class Trie {
|
|||||||
return current.isEndOfWord();
|
return current.isEndOfWord();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isEmpty() {
|
boolean isEmpty() {
|
||||||
return root == null;
|
return root == null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -51,7 +51,7 @@ public class Trie {
|
|||||||
if (node == null) {
|
if (node == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
boolean shouldDeleteCurrentNode = delete(node, word, index + 1);
|
boolean shouldDeleteCurrentNode = delete(node, word, index + 1) && !node.isEndOfWord();
|
||||||
|
|
||||||
if (shouldDeleteCurrentNode) {
|
if (shouldDeleteCurrentNode) {
|
||||||
current.getChildren().remove(ch);
|
current.getChildren().remove(ch);
|
||||||
|
@ -4,28 +4,18 @@ import java.util.HashMap;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
class TrieNode {
|
class TrieNode {
|
||||||
private Map<Character, TrieNode> children;
|
private final Map<Character, TrieNode> children = new HashMap<>();
|
||||||
private boolean endOfWord;
|
private boolean endOfWord;
|
||||||
|
|
||||||
public TrieNode() {
|
Map<Character, TrieNode> getChildren() {
|
||||||
children = new HashMap<>();
|
|
||||||
endOfWord = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Map<Character, TrieNode> getChildren() {
|
|
||||||
return children;
|
return children;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setChildren(Map<Character, TrieNode> children) {
|
boolean isEndOfWord() {
|
||||||
this.children = children;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isEndOfWord() {
|
|
||||||
return endOfWord;
|
return endOfWord;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setEndOfWord(boolean endOfWord) {
|
void setEndOfWord(boolean endOfWord) {
|
||||||
this.endOfWord = endOfWord;
|
this.endOfWord = endOfWord;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -1,6 +1,7 @@
|
|||||||
package com.baeldung.trie;
|
package com.baeldung.trie;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import org.junit.jupiter.api.Assertions;
|
||||||
|
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
@ -53,6 +54,19 @@ public class TrieTest {
|
|||||||
assertFalse(trie.containsNode("Programming"));
|
assertFalse(trie.containsNode("Programming"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenATrie_whenDeletingOverlappingElements_thenDontDeleteSubElement() {
|
||||||
|
|
||||||
|
Trie trie1 = new Trie();
|
||||||
|
|
||||||
|
trie1.insert("pie");
|
||||||
|
trie1.insert("pies");
|
||||||
|
|
||||||
|
trie1.delete("pies");
|
||||||
|
|
||||||
|
Assertions.assertTrue(trie1.containsNode("pie"));
|
||||||
|
}
|
||||||
|
|
||||||
private Trie createExampleTrie() {
|
private Trie createExampleTrie() {
|
||||||
Trie trie = new Trie();
|
Trie trie = new Trie();
|
||||||
|
|
||||||
|
@ -27,7 +27,6 @@
|
|||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
|
||||||
<dl4j.version>0.9.1</dl4j.version>
|
<dl4j.version>0.9.1</dl4j.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
|
@ -16,93 +16,39 @@
|
|||||||
<version>1.0.0-SNAPSHOT</version>
|
<version>1.0.0-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<licenses>
|
|
||||||
<license>
|
|
||||||
<name>Apache License, Version 2.0</name>
|
|
||||||
<distribution>repo</distribution>
|
|
||||||
<url>http://www.apache.org/licenses/LICENSE-2.0.html</url>
|
|
||||||
</license>
|
|
||||||
</licenses>
|
|
||||||
<repositories>
|
|
||||||
<repository>
|
|
||||||
<id>redhat-repository-techpreview</id>
|
|
||||||
<url>https://maven.repository.redhat.com/techpreview/all/</url>
|
|
||||||
</repository>
|
|
||||||
</repositories>
|
|
||||||
|
|
||||||
<dependencyManagement>
|
|
||||||
<dependencies>
|
|
||||||
<!-- JBoss distributes a complete set of Java EE 7 APIs including a Bill
|
|
||||||
of Materials (BOM). A BOM specifies the versions of a "stack" (or a collection)
|
|
||||||
of artifacts. We use this here so that we always get the correct versions
|
|
||||||
of artifacts. Here we use the jboss-javaee-7.0-with-tools stack (you can
|
|
||||||
read this as the JBoss stack of the Java EE 7 APIs, with some extras tools
|
|
||||||
for your project, such as Arquillian for testing) and the jboss-javaee-7.0-with-hibernate
|
|
||||||
stack you can read this as the JBoss stack of the Java EE 7 APIs, with extras
|
|
||||||
from the Hibernate family of projects) -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.wildfly.bom</groupId>
|
|
||||||
<artifactId>jboss-javaee-7.0-with-tools</artifactId>
|
|
||||||
<version>${jboss.bom.version}</version>
|
|
||||||
<type>pom</type>
|
|
||||||
<scope>import</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.wildfly.bom</groupId>
|
|
||||||
<artifactId>jboss-javaee-7.0-with-hibernate</artifactId>
|
|
||||||
<version>${jboss.bom.version}</version>
|
|
||||||
<type>pom</type>
|
|
||||||
<scope>import</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.apache.deltaspike.distribution</groupId>
|
|
||||||
<artifactId>distributions-bom</artifactId>
|
|
||||||
<version>${deltaspike.version}</version>
|
|
||||||
<type>pom</type>
|
|
||||||
<scope>import</scope>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
</dependencyManagement>
|
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|
||||||
<!-- First declare the APIs we depend on and need for compilation. All
|
<!-- First declare the APIs we depend on and need for compilation. All of them are provided by JBoss WildFly -->
|
||||||
of them are provided by JBoss WildFly -->
|
|
||||||
|
|
||||||
<!-- Import the CDI API, we use provided scope as the API is included in
|
<!-- Import the CDI API, we use provided scope as the API is included in JBoss WildFly -->
|
||||||
JBoss WildFly -->
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>javax.enterprise</groupId>
|
<groupId>javax.enterprise</groupId>
|
||||||
<artifactId>cdi-api</artifactId>
|
<artifactId>cdi-api</artifactId>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- Import the Common Annotations API (JSR-250), we use provided scope
|
<!-- Import the Common Annotations API (JSR-250), we use provided scope as the API is included in JBoss WildFly -->
|
||||||
as the API is included in JBoss WildFly -->
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.jboss.spec.javax.annotation</groupId>
|
<groupId>org.jboss.spec.javax.annotation</groupId>
|
||||||
<artifactId>jboss-annotations-api_1.2_spec</artifactId>
|
<artifactId>jboss-annotations-api_1.2_spec</artifactId>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- Import the JAX-RS API, we use provided scope as the API is included
|
<!-- Import the JAX-RS API, we use provided scope as the API is included in JBoss WildFly -->
|
||||||
in JBoss WildFly -->
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.jboss.resteasy</groupId>
|
<groupId>org.jboss.resteasy</groupId>
|
||||||
<artifactId>jaxrs-api</artifactId>
|
<artifactId>jaxrs-api</artifactId>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- Import the JPA API, we use provided scope as the API is included in
|
<!-- Import the JPA API, we use provided scope as the API is included in JBoss WildFly -->
|
||||||
JBoss WildFly -->
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.hibernate.javax.persistence</groupId>
|
<groupId>org.hibernate.javax.persistence</groupId>
|
||||||
<artifactId>hibernate-jpa-2.1-api</artifactId>
|
<artifactId>hibernate-jpa-2.1-api</artifactId>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- Import the EJB API, we use provided scope as the API is included in
|
<!-- Import the EJB API, we use provided scope as the API is included in JBoss WildFly -->
|
||||||
JBoss WildFly -->
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.jboss.spec.javax.ejb</groupId>
|
<groupId>org.jboss.spec.javax.ejb</groupId>
|
||||||
<artifactId>jboss-ejb-api_3.2_spec</artifactId>
|
<artifactId>jboss-ejb-api_3.2_spec</artifactId>
|
||||||
@ -124,8 +70,7 @@
|
|||||||
</exclusions>
|
</exclusions>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- Import the JSF API, we use provided scope as the API is included in
|
<!-- Import the JSF API, we use provided scope as the API is included in JBoss WildFly -->
|
||||||
JBoss WildFly -->
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.jboss.spec.javax.faces</groupId>
|
<groupId>org.jboss.spec.javax.faces</groupId>
|
||||||
<artifactId>jboss-jsf-api_2.2_spec</artifactId>
|
<artifactId>jboss-jsf-api_2.2_spec</artifactId>
|
||||||
@ -134,16 +79,14 @@
|
|||||||
|
|
||||||
<!-- Now we declare any tools needed -->
|
<!-- Now we declare any tools needed -->
|
||||||
|
|
||||||
<!-- Annotation processor to generate the JPA 2.0 metamodel classes for
|
<!-- Annotation processor to generate the JPA 2.0 metamodel classes for typesafe criteria queries -->
|
||||||
typesafe criteria queries -->
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.hibernate</groupId>
|
<groupId>org.hibernate</groupId>
|
||||||
<artifactId>hibernate-jpamodelgen</artifactId>
|
<artifactId>hibernate-jpamodelgen</artifactId>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- Annotation processor that raising compilation errors whenever constraint
|
<!-- Annotation processor that raising compilation errors whenever constraint annotations are incorrectly used. -->
|
||||||
annotations are incorrectly used. -->
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.hibernate</groupId>
|
<groupId>org.hibernate</groupId>
|
||||||
<artifactId>hibernate-validator-annotation-processor</artifactId>
|
<artifactId>hibernate-validator-annotation-processor</artifactId>
|
||||||
@ -151,8 +94,7 @@
|
|||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- Optional, but highly recommended -->
|
<!-- Optional, but highly recommended -->
|
||||||
<!-- Arquillian allows you to test enterprise code such as EJBs and Transactional(JTA)
|
<!-- Arquillian allows you to test enterprise code such as EJBs and Transactional(JTA) JPA from JUnit/TestNG -->
|
||||||
JPA from JUnit/TestNG -->
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.jboss.arquillian.junit</groupId>
|
<groupId>org.jboss.arquillian.junit</groupId>
|
||||||
<artifactId>arquillian-junit-container</artifactId>
|
<artifactId>arquillian-junit-container</artifactId>
|
||||||
@ -231,13 +173,13 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.jboss</groupId>
|
<groupId>org.jboss</groupId>
|
||||||
<artifactId>jandex</artifactId>
|
<artifactId>jandex</artifactId>
|
||||||
<version>1.2.5.Final-redhat-1</version>
|
<version>${jandex.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.h2database</groupId>
|
<groupId>com.h2database</groupId>
|
||||||
<artifactId>h2</artifactId>
|
<artifactId>h2</artifactId>
|
||||||
<version>1.4.197</version>
|
<version>${h2.version}</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
@ -258,14 +200,13 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.commons</groupId>
|
<groupId>org.apache.commons</groupId>
|
||||||
<artifactId>commons-lang3</artifactId>
|
<artifactId>commons-lang3</artifactId>
|
||||||
<version>3.5</version>
|
<version>${commons-lang3.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
<!-- Maven will append the version to the finalName (which is the name
|
<!-- Maven will append the version to the finalName (which is the name given to the generated war, and hence the context root) -->
|
||||||
given to the generated war, and hence the context root) -->
|
|
||||||
<finalName>${project.artifactId}</finalName>
|
<finalName>${project.artifactId}</finalName>
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
@ -305,10 +246,8 @@
|
|||||||
<profiles>
|
<profiles>
|
||||||
<profile>
|
<profile>
|
||||||
|
|
||||||
<!-- An optional Arquillian testing profile that executes tests in your
|
<!-- An optional Arquillian testing profile that executes tests in your WildFly instance -->
|
||||||
WildFly instance -->
|
<!-- This profile will start a new WildFly instance, and execute the test, shutting it down when done -->
|
||||||
<!-- This profile will start a new WildFly instance, and execute the test,
|
|
||||||
shutting it down when done -->
|
|
||||||
<!-- Run with: mvn clean test -Parq-wildfly-managed -->
|
<!-- Run with: mvn clean test -Parq-wildfly-managed -->
|
||||||
<id>arq-wildfly-managed</id>
|
<id>arq-wildfly-managed</id>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
@ -321,25 +260,64 @@
|
|||||||
</profile>
|
</profile>
|
||||||
</profiles>
|
</profiles>
|
||||||
|
|
||||||
|
<licenses>
|
||||||
|
<license>
|
||||||
|
<name>Apache License, Version 2.0</name>
|
||||||
|
<distribution>repo</distribution>
|
||||||
|
<url>http://www.apache.org/licenses/LICENSE-2.0.html</url>
|
||||||
|
</license>
|
||||||
|
</licenses>
|
||||||
|
<repositories>
|
||||||
|
<repository>
|
||||||
|
<id>redhat-repository-techpreview</id>
|
||||||
|
<url>https://maven.repository.redhat.com/techpreview/all/</url>
|
||||||
|
</repository>
|
||||||
|
</repositories>
|
||||||
|
|
||||||
|
<dependencyManagement>
|
||||||
|
<dependencies>
|
||||||
|
<!-- JBoss distributes a complete set of Java EE 7 APIs including a Bill of Materials (BOM). A BOM specifies the versions of a "stack" (or a collection) of artifacts. We
|
||||||
|
use this here so that we always get the correct versions of artifacts. Here we use the jboss-javaee-7.0-with-tools stack (you can read this as the JBoss stack of the Java EE 7 APIs,
|
||||||
|
with some extras tools for your project, such as Arquillian for testing) and the jboss-javaee-7.0-with-hibernate stack you can read this as the JBoss stack of the Java EE 7 APIs, with
|
||||||
|
extras from the Hibernate family of projects) -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.wildfly.bom</groupId>
|
||||||
|
<artifactId>jboss-javaee-7.0-with-tools</artifactId>
|
||||||
|
<version>${jboss.bom.version}</version>
|
||||||
|
<type>pom</type>
|
||||||
|
<scope>import</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.wildfly.bom</groupId>
|
||||||
|
<artifactId>jboss-javaee-7.0-with-hibernate</artifactId>
|
||||||
|
<version>${jboss.bom.version}</version>
|
||||||
|
<type>pom</type>
|
||||||
|
<scope>import</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.deltaspike.distribution</groupId>
|
||||||
|
<artifactId>distributions-bom</artifactId>
|
||||||
|
<version>${deltaspike.version}</version>
|
||||||
|
<type>pom</type>
|
||||||
|
<scope>import</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</dependencyManagement>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<!-- Explicitly declaring the source encoding eliminates the following
|
|
||||||
message: -->
|
|
||||||
<!-- [WARNING] Using platform encoding (UTF-8 actually) to copy filtered
|
|
||||||
resources, i.e. build is platform dependent! -->
|
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
|
||||||
<querydsl.version>3.7.4</querydsl.version>
|
<querydsl.version>3.7.4</querydsl.version>
|
||||||
<deltaspike.version>1.8.2</deltaspike.version>
|
<deltaspike.version>1.8.2</deltaspike.version>
|
||||||
<!-- JBoss dependency versions -->
|
<!-- JBoss dependency versions -->
|
||||||
<wildfly.maven.plugin.version>1.0.2.Final</wildfly.maven.plugin.version>
|
<wildfly.maven.plugin.version>1.0.2.Final</wildfly.maven.plugin.version>
|
||||||
<!-- Define the version of the JBoss BOMs we want to import to specify
|
<!-- Define the version of the JBoss BOMs we want to import to specify tested stacks. -->
|
||||||
tested stacks. -->
|
|
||||||
<jboss.bom.version>8.2.1.Final</jboss.bom.version>
|
<jboss.bom.version>8.2.1.Final</jboss.bom.version>
|
||||||
<weld.version>2.1.2.Final</weld.version>
|
<weld.version>2.1.2.Final</weld.version>
|
||||||
<!-- other plugin versions -->
|
<!-- other plugin versions -->
|
||||||
<war.plugin.version>2.6</war.plugin.version>
|
<war.plugin.version>2.6</war.plugin.version>
|
||||||
<apt-maven-plugin.version>1.1.3</apt-maven-plugin.version>
|
<apt-maven-plugin.version>1.1.3</apt-maven-plugin.version>
|
||||||
<maven.compiler.target>1.8</maven.compiler.target>
|
<jandex.version>1.2.5.Final-redhat-1</jandex.version>
|
||||||
<maven.compiler.source>1.8</maven.compiler.source>
|
<h2.version>1.4.197</h2.version>
|
||||||
|
<commons-lang3.version>3.5</commons-lang3.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
@ -99,8 +99,7 @@
|
|||||||
<configuration>
|
<configuration>
|
||||||
<shadedArtifactAttached>true</shadedArtifactAttached>
|
<shadedArtifactAttached>true</shadedArtifactAttached>
|
||||||
<transformers>
|
<transformers>
|
||||||
<transformer
|
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
|
||||||
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
|
|
||||||
<mainClass>org.baeldung.executable.ExecutableMavenJar</mainClass>
|
<mainClass>org.baeldung.executable.ExecutableMavenJar</mainClass>
|
||||||
</transformer>
|
</transformer>
|
||||||
</transformers>
|
</transformers>
|
||||||
|
@ -15,12 +15,6 @@
|
|||||||
<artifactId>dubbo</artifactId>
|
<artifactId>dubbo</artifactId>
|
||||||
<version>${dubbo.version}</version>
|
<version>${dubbo.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>junit</groupId>
|
|
||||||
<artifactId>junit</artifactId>
|
|
||||||
<version>${junit.version}</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.zookeeper</groupId>
|
<groupId>org.apache.zookeeper</groupId>
|
||||||
<artifactId>zookeeper</artifactId>
|
<artifactId>zookeeper</artifactId>
|
||||||
@ -34,9 +28,6 @@
|
|||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
|
||||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
|
||||||
<java.version>1.8</java.version>
|
|
||||||
<dubbo.version>2.5.7</dubbo.version>
|
<dubbo.version>2.5.7</dubbo.version>
|
||||||
<zookeeper.version>3.4.11</zookeeper.version>
|
<zookeeper.version>3.4.11</zookeeper.version>
|
||||||
<zkclient.version>0.10</zkclient.version>
|
<zkclient.version>0.10</zkclient.version>
|
||||||
|
@ -24,20 +24,4 @@
|
|||||||
<type>ejb</type>
|
<type>ejb</type>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
|
||||||
<plugins>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-surefire-plugin</artifactId>
|
|
||||||
<version>${maven-surefire-plugin.version}</version>
|
|
||||||
<configuration>
|
|
||||||
<excludes>
|
|
||||||
<exclude>**/*EJBSetupTest.java</exclude>
|
|
||||||
</excludes>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
|
||||||
</build>
|
|
||||||
|
|
||||||
</project>
|
</project>
|
@ -8,7 +8,7 @@ import java.io.ByteArrayOutputStream;
|
|||||||
import java.io.PrintStream;
|
import java.io.PrintStream;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
public class TextApplicationTest {
|
public class TextApplicationIntegrationTest {
|
||||||
|
|
||||||
private static ByteArrayOutputStream outContent;
|
private static ByteArrayOutputStream outContent;
|
||||||
|
|
@ -13,7 +13,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.jboss.arquillian</groupId>
|
<groupId>org.jboss.arquillian</groupId>
|
||||||
<artifactId>arquillian-bom</artifactId>
|
<artifactId>arquillian-bom</artifactId>
|
||||||
<version>1.1.13.Final</version>
|
<version>${arquillian-bom.version}</version>
|
||||||
<scope>import</scope>
|
<scope>import</scope>
|
||||||
<type>pom</type>
|
<type>pom</type>
|
||||||
</dependency>
|
</dependency>
|
||||||
@ -27,12 +27,6 @@
|
|||||||
<version>${javaee-api.version}</version>
|
<version>${javaee-api.version}</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>junit</groupId>
|
|
||||||
<artifactId>junit</artifactId>
|
|
||||||
<version>${junit.version}</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.jboss.arquillian.junit</groupId>
|
<groupId>org.jboss.arquillian.junit</groupId>
|
||||||
<artifactId>arquillian-junit-container</artifactId>
|
<artifactId>arquillian-junit-container</artifactId>
|
||||||
@ -56,7 +50,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.glassfish.main.extras</groupId>
|
<groupId>org.glassfish.main.extras</groupId>
|
||||||
<artifactId>glassfish-embedded-all</artifactId>
|
<artifactId>glassfish-embedded-all</artifactId>
|
||||||
<version>3.1.2</version>
|
<version>${glassfish-embedded-all.version}</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
@ -67,7 +61,7 @@
|
|||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
<artifactId>maven-war-plugin</artifactId>
|
<artifactId>maven-war-plugin</artifactId>
|
||||||
<version>2.4</version>
|
<version>${maven-war-plugin.version}</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<failOnMissingWebXml>false</failOnMissingWebXml>
|
<failOnMissingWebXml>false</failOnMissingWebXml>
|
||||||
</configuration>
|
</configuration>
|
||||||
@ -77,13 +71,14 @@
|
|||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<arquillian-bom.version>1.1.12.Final</arquillian-bom.version>
|
<arquillian-bom.version>1.1.13.Final</arquillian-bom.version>
|
||||||
<shrinkwrap-resolver-impl-maven.version>2.2.6</shrinkwrap-resolver-impl-maven.version>
|
<shrinkwrap-resolver-impl-maven.version>2.2.6</shrinkwrap-resolver-impl-maven.version>
|
||||||
<arquillian-junit-container.version>1.1.12.Final</arquillian-junit-container.version>
|
<arquillian-junit-container.version>1.1.12.Final</arquillian-junit-container.version>
|
||||||
<arquillian-glassfish-embedded-3.1.version>1.0.0.Final</arquillian-glassfish-embedded-3.1.version>
|
<arquillian-glassfish-embedded-3.1.version>1.0.0.Final</arquillian-glassfish-embedded-3.1.version>
|
||||||
<junit.version>4.12</junit.version>
|
<junit.version>4.12</junit.version>
|
||||||
<javaee-api.version>7.0</javaee-api.version>
|
<javaee-api.version>7.0</javaee-api.version>
|
||||||
<arquillian-glassfish-embedded-3.1.version>1.0.0.CR4</arquillian-glassfish-embedded-3.1.version>
|
<arquillian-glassfish-embedded-3.1.version>1.0.0.CR4</arquillian-glassfish-embedded-3.1.version>
|
||||||
|
<glassfish-embedded-all.version>3.1.2</glassfish-embedded-all.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
</project>
|
</project>
|
@ -17,7 +17,7 @@ import javax.inject.Inject;
|
|||||||
|
|
||||||
|
|
||||||
@RunWith(Arquillian.class)
|
@RunWith(Arquillian.class)
|
||||||
public class StatefulEJBTest {
|
public class StatefulEJBIntegrationTest {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private EJBClient1 ejbClient1;
|
private EJBClient1 ejbClient1;
|
@ -17,7 +17,7 @@ import javax.inject.Inject;
|
|||||||
|
|
||||||
|
|
||||||
@RunWith(Arquillian.class)
|
@RunWith(Arquillian.class)
|
||||||
public class StatelessEJBTest {
|
public class StatelessEJBIntegrationTest {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private EJBClient1 ejbClient1;
|
private EJBClient1 ejbClient1;
|
@ -83,9 +83,6 @@
|
|||||||
</repositories>
|
</repositories>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
|
||||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
|
||||||
<java.version>1.8</java.version>
|
|
||||||
<dubbo.version>2.5.7</dubbo.version>
|
<dubbo.version>2.5.7</dubbo.version>
|
||||||
<zookeeper.version>3.4.11</zookeeper.version>
|
<zookeeper.version>3.4.11</zookeeper.version>
|
||||||
<zkclient.version>0.10</zkclient.version>
|
<zkclient.version>0.10</zkclient.version>
|
||||||
|
@ -83,7 +83,6 @@
|
|||||||
<properties>
|
<properties>
|
||||||
<maven.compiler.source>1.8</maven.compiler.source>
|
<maven.compiler.source>1.8</maven.compiler.source>
|
||||||
<maven.compiler.target>1.8</maven.compiler.target>
|
<maven.compiler.target>1.8</maven.compiler.target>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
|
||||||
<javaee-api.version>7.0</javaee-api.version>
|
<javaee-api.version>7.0</javaee-api.version>
|
||||||
<wildfly-javaee7.version>10.1.0.Final</wildfly-javaee7.version>
|
<wildfly-javaee7.version>10.1.0.Final</wildfly-javaee7.version>
|
||||||
<hibernate-core.version>5.2.3.Final</hibernate-core.version>
|
<hibernate-core.version>5.2.3.Final</hibernate-core.version>
|
||||||
|
@ -40,7 +40,7 @@
|
|||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
<artifactId>maven-ear-plugin</artifactId>
|
<artifactId>maven-ear-plugin</artifactId>
|
||||||
<version>2.10.1</version>
|
<version>${maven-ear-plugin.version}</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<defaultLibBundleDir>lib/</defaultLibBundleDir>
|
<defaultLibBundleDir>lib/</defaultLibBundleDir>
|
||||||
<version>7</version>
|
<version>7</version>
|
||||||
@ -56,8 +56,13 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.wildfly.plugins</groupId>
|
<groupId>org.wildfly.plugins</groupId>
|
||||||
<artifactId>wildfly-maven-plugin</artifactId>
|
<artifactId>wildfly-maven-plugin</artifactId>
|
||||||
<version>1.2.0.Final</version>
|
<version>${wildfly-maven-plugin.version}</version>
|
||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<maven-ear-plugin.version>2.10.1</maven-ear-plugin.version>
|
||||||
|
<wildfly-maven-plugin.version>1.2.0.Final</wildfly-maven-plugin.version>
|
||||||
|
</properties>
|
||||||
</project>
|
</project>
|
@ -15,7 +15,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>javax.ejb</groupId>
|
<groupId>javax.ejb</groupId>
|
||||||
<artifactId>javax.ejb-api</artifactId>
|
<artifactId>javax.ejb-api</artifactId>
|
||||||
<version>3.2</version>
|
<version>${ejb.version}</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- Dependency for java ee -->
|
<!-- Dependency for java ee -->
|
||||||
@ -42,9 +42,13 @@
|
|||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-ejb-plugin</artifactId>
|
<artifactId>maven-ejb-plugin</artifactId>
|
||||||
<configuration>
|
<configuration>
|
||||||
<ejbVersion>3.2</ejbVersion>
|
<ejbVersion>${ejb.version}</ejbVersion>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<ejb.version>3.2</ejb.version>
|
||||||
|
</properties>
|
||||||
</project>
|
</project>
|
21
ejb/wildfly/wildfly-mdb/pom.xml
Normal file
21
ejb/wildfly/wildfly-mdb/pom.xml
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<artifactId>widlfly-mdb</artifactId>
|
||||||
|
|
||||||
|
<parent>
|
||||||
|
<groupId>com.baeldung.wildfly</groupId>
|
||||||
|
<artifactId>wildfly-example</artifactId>
|
||||||
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<!-- Dependency for java ee -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>javax</groupId>
|
||||||
|
<artifactId>javaee-api</artifactId>
|
||||||
|
<version>${javaee-api.version}</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</project>
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user