Merge branch 'masterEugen' into tutorials/mvnMultipleSrc

This commit is contained in:
Marcos Lopez Gonzalez 2018-08-10 19:53:23 +02:00
commit af7250ec21
96 changed files with 1346 additions and 892 deletions

View File

@ -0,0 +1,26 @@
package com.baeldung.collection;
import java.util.List;
import java.util.ArrayList;
import java.util.Collections;
import org.junit.Assert;
import org.junit.Test;
public class CollectionsEmpty {
@Test
public void givenArrayList_whenAddingElement_addsNewElement() {
ArrayList<String> mutableList = new ArrayList<>();
mutableList.add("test");
Assert.assertEquals(mutableList.size(), 1);
Assert.assertEquals(mutableList.get(0), "test");
}
@Test(expected = UnsupportedOperationException.class)
public void givenCollectionsEmptyList_whenAddingElement_throwsUnsupportedOperationException() {
List<String> immutableList = Collections.emptyList();
immutableList.add("test");
}
}

View File

@ -303,7 +303,7 @@
<avaitility.version>1.7.0</avaitility.version>
<!-- maven plugins -->
<maven-surefire-plugin.version>2.19.1</maven-surefire-plugin.version>
<maven-surefire-plugin.version>2.21.0</maven-surefire-plugin.version>
<sun-tools.version>1.8.0</sun-tools.version>
<maven-jar-plugin.version>3.0.2</maven-jar-plugin.version>
</properties>

View File

@ -530,7 +530,7 @@
<assertj-core.version>3.10.0</assertj-core.version>
<!-- maven plugins -->
<maven-surefire-plugin.version>2.19.1</maven-surefire-plugin.version>
<maven-surefire-plugin.version>2.21.0</maven-surefire-plugin.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>

View File

@ -0,0 +1,24 @@
package com.baeldung.fileparser;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
public class BufferedReaderExample {
protected static ArrayList<String> generateArrayListFromFile(String filename) throws IOException {
ArrayList<String> result = new ArrayList<>();
try (BufferedReader br = new BufferedReader(new FileReader(filename))) {
while (br.ready()) {
result.add(br.readLine());
}
return result;
}
}
}

View File

@ -0,0 +1,31 @@
package com.baeldung.fileparser;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
public class FileReaderExample {
protected static ArrayList<String> generateArrayListFromFile(String filename) throws IOException {
ArrayList<String> result = new ArrayList<>();
try (FileReader f = new FileReader(filename)) {
StringBuffer sb = new StringBuffer();
while (f.ready()) {
char c = (char) f.read();
if (c == '\n') {
result.add(sb.toString());
sb = new StringBuffer();
} else {
sb.append(c);
}
}
if (sb.length() > 0) {
result.add(sb.toString());
}
}
return result;
}
}

View File

@ -0,0 +1,18 @@
package com.baeldung.fileparser;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
public class FilesReadLinesExample {
protected static ArrayList<String> generateArrayListFromFile(String filename) throws IOException {
List<String> result = Files.readAllLines(Paths.get(filename));
return (ArrayList<String>) result;
}
}

View File

@ -0,0 +1,24 @@
package com.baeldung.fileparser;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Scanner;
public class ScannerIntExample {
protected static ArrayList<Integer> generateArrayListFromFile(String filename) throws IOException {
ArrayList<Integer> result = new ArrayList<>();
try (Scanner s = new Scanner(new FileReader(filename))) {
while (s.hasNext()) {
result.add(s.nextInt());
}
return result;
}
}
}

View File

@ -0,0 +1,24 @@
package com.baeldung.fileparser;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Scanner;
public class ScannerStringExample {
protected static ArrayList<String> generateArrayListFromFile(String filename) throws IOException {
ArrayList<String> result = new ArrayList<>();
try (Scanner s = new Scanner(new FileReader(filename))) {
while (s.hasNext()) {
result.add(s.nextLine());
}
return result;
}
}
}

View File

@ -0,0 +1,19 @@
package com.baeldung.fileparser;
import static org.junit.Assert.assertTrue;
import java.io.IOException;
import java.util.List;
import org.junit.Test;
public class BufferedReaderUnitTest {
protected static final String TEXT_FILENAME = "src/test/resources/sampleTextFile.txt";
@Test
public void whenParsingExistingTextFile_thenGetArrayList() throws IOException {
List<String> lines = BufferedReaderExample.generateArrayListFromFile(TEXT_FILENAME);
assertTrue("File does not has 2 lines", lines.size() == 2);
}
}

View File

@ -0,0 +1,19 @@
package com.baeldung.fileparser;
import static org.junit.Assert.assertTrue;
import java.io.IOException;
import java.util.List;
import org.junit.Test;
public class FileReaderUnitTest {
protected static final String TEXT_FILENAME = "src/test/resources/sampleTextFile.txt";
@Test
public void whenParsingExistingTextFile_thenGetArrayList() throws IOException {
List<String> lines = FileReaderExample.generateArrayListFromFile(TEXT_FILENAME);
assertTrue("File does not has 2 lines", lines.size() == 2);
}
}

View File

@ -0,0 +1,19 @@
package com.baeldung.fileparser;
import static org.junit.Assert.assertTrue;
import java.io.IOException;
import java.util.List;
import org.junit.Test;
public class FilesReadAllLinesUnitTest {
protected static final String TEXT_FILENAME = "src/test/resources/sampleTextFile.txt";
@Test
public void whenParsingExistingTextFile_thenGetArrayList() throws IOException {
List<String> lines = FilesReadLinesExample.generateArrayListFromFile(TEXT_FILENAME);
assertTrue("File does not has 2 lines", lines.size() == 2);
}
}

View File

@ -0,0 +1,19 @@
package com.baeldung.fileparser;
import static org.junit.Assert.assertTrue;
import java.io.IOException;
import java.util.List;
import org.junit.Test;
public class ScannerIntUnitTest {
protected static final String NUMBER_FILENAME = "src/test/resources/sampleNumberFile.txt";
@Test
public void whenParsingExistingTextFile_thenGetIntArrayList() throws IOException {
List<Integer> numbers = ScannerIntExample.generateArrayListFromFile(NUMBER_FILENAME);
assertTrue("File does not has 2 lines", numbers.size() == 2);
}
}

View File

@ -0,0 +1,19 @@
package com.baeldung.fileparser;
import static org.junit.Assert.assertTrue;
import java.io.IOException;
import java.util.List;
import org.junit.Test;
public class ScannerStringUnitTest {
protected static final String TEXT_FILENAME = "src/test/resources/sampleTextFile.txt";
@Test
public void whenParsingExistingTextFile_thenGetArrayList() throws IOException {
List<String> lines = ScannerStringExample.generateArrayListFromFile(TEXT_FILENAME);
assertTrue("File does not has 2 lines", lines.size() == 2);
}
}

View File

@ -0,0 +1,2 @@
111
222

View File

@ -0,0 +1,2 @@
Hello
World

View File

@ -13,16 +13,12 @@
</parent>
<dependencies>
<dependency>
<groupId>com.hazelcast</groupId>
<artifactId>hazelcast</artifactId>
<version>${hazelcast.version}</version>
</dependency>
<dependency>
<groupId>com.hazelcast</groupId>
<artifactId>hazelcast-client</artifactId>
<version>${hazelcast.version}</version>
</dependency>
<!-- Hazelcast Jet -->
<dependency>
<groupId>com.hazelcast.jet</groupId>
<artifactId>hazelcast-jet</artifactId>
<version>${hazelcast.jet.version}</version>
</dependency>
</dependencies>
<build>
@ -36,8 +32,8 @@
</build>
<properties>
<!-- hazelcast -->
<hazelcast.version>3.8.4</hazelcast.version>
<!-- hazelcast jet-->
<hazelcast.jet.version>0.6</hazelcast.jet.version>
</properties>
</project>

View File

@ -0,0 +1,51 @@
package com.baeldung.hazelcast.jet;
import java.util.List;
import java.util.Map;
import static com.hazelcast.jet.Traversers.traverseArray;
import static com.hazelcast.jet.aggregate.AggregateOperations.counting;
import static com.hazelcast.jet.function.DistributedFunctions.wholeItem;
import com.hazelcast.jet.Jet;
import com.hazelcast.jet.JetInstance;
import com.hazelcast.jet.pipeline.Pipeline;
import com.hazelcast.jet.pipeline.Sinks;
import com.hazelcast.jet.pipeline.Sources;
public class WordCounter {
private static final String LIST_NAME = "textList";
private static final String MAP_NAME = "countMap";
private Pipeline createPipeLine() {
Pipeline p = Pipeline.create();
p.drawFrom(Sources.<String> list(LIST_NAME))
.flatMap(word -> traverseArray(word.toLowerCase()
.split("\\W+")))
.filter(word -> !word.isEmpty())
.groupingKey(wholeItem())
.aggregate(counting())
.drainTo(Sinks.map(MAP_NAME));
return p;
}
public Long countWord(List<String> sentences, String word) {
long count = 0;
JetInstance jet = Jet.newJetInstance();
try {
List<String> textList = jet.getList(LIST_NAME);
textList.addAll(sentences);
Pipeline p = createPipeLine();
jet.newJob(p)
.join();
Map<String, Long> counts = jet.getMap(MAP_NAME);
count = counts.get(word);
} finally {
Jet.shutdownAll();
}
return count;
}
}

View File

@ -0,0 +1,21 @@
package com.baeldung.hazelcast.jet;
import static org.junit.Assert.assertTrue;
import java.util.ArrayList;
import java.util.List;
import org.junit.Test;
public class WordCounterUnitTest {
@Test
public void whenGivenSentencesAndWord_ThenReturnCountOfWord() {
List<String> sentences = new ArrayList<>();
sentences.add("The first second was alright, but the second second was tough.");
WordCounter wordCounter = new WordCounter();
long countSecond = wordCounter.countWord(sentences, "second");
assertTrue(countSecond == 3);
}
}

View File

@ -156,7 +156,7 @@
<jmh-core.version>1.19</jmh-core.version>
<jmh-generator-annprocess.version>1.19</jmh-generator-annprocess.version>
<maven-surefire-plugin.version>2.19.1</maven-surefire-plugin.version>
<maven-surefire-plugin.version>2.21.0</maven-surefire-plugin.version>
<maven-javadoc-plugin.version>3.0.0-M1</maven-javadoc-plugin.version>
<maven-jar-plugin.version>3.0.2</maven-jar-plugin.version>
</properties>

View File

@ -418,7 +418,7 @@
<arquillian-glassfish.version>1.0.0.Final</arquillian-glassfish.version>
<maven-war-plugin.version>2.6</maven-war-plugin.version>
<org.springframework.security.version>4.2.3.RELEASE</org.springframework.security.version>
<maven-surefire-plugin.version>2.17</maven-surefire-plugin.version>
<maven-surefire-plugin.version>2.21.0</maven-surefire-plugin.version>
<taglibs.standard.version>1.1.2</taglibs.standard.version>
<commons-io.version>2.4</commons-io.version>
<com.sun.faces.jsf.version>2.2.14</com.sun.faces.jsf.version>

View File

@ -153,7 +153,7 @@
<!-- 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.21.0</maven-surefire-plugin.version>
<datafactory.version>0.8</datafactory.version>
<webjars.bootstrap.version>3.3.7</webjars.bootstrap.version>
<java.version>1.8</java.version>

View File

@ -8,18 +8,27 @@
<description>Parent for all Spring Boot 2 modules</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.1.RELEASE</version>
<relativePath />
<groupId>com.baeldung</groupId>
<artifactId>parent-modules</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>2.0.1.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<version>${rest-assured.version}</version>
</dependency>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
@ -27,79 +36,16 @@
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
<configuration>
<forkCount>3</forkCount>
<reuseForks>true</reuseForks>
<excludes>
<exclude>**/*IntegrationTest.java</exclude>
<exclude>**/*IntTest.java</exclude>
<exclude>**/*LongRunningUnitTest.java</exclude>
<exclude>**/*ManualTest.java</exclude>
<exclude>**/*LiveTest.java</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
</configuration>
</plugin>
</plugins>
</build>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.0.1.RELEASE</version>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>integration</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<executions>
<execution>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<excludes>
<exclude>**/*ManualTest.java</exclude>
<exclude>**/*LiveTest.java</exclude>
<exclude>**/AutoconfigurationTest.java</exclude>
<exclude>**/*UnitTest.java</exclude>
</excludes>
<includes>
<include>**/*IntegrationTest.java</include>
<include>**/*IntTest.java</include>
<include>*/EthControllerTestOne.java</include>
<include>**/*EntryPointsTest.java</include>
</includes>
</configuration>
</execution>
</executions>
<configuration>
<systemPropertyVariables>
<test.mime>json</test.mime>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>thin-jar</id>
<build>
@ -122,13 +68,8 @@
</profiles>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<rest-assured.version>3.1.0</rest-assured.version>
<!-- plugins -->
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<thin.version>1.0.11.RELEASE</thin.version>
</properties>

View File

@ -177,46 +177,12 @@
</build>
<repositories>
<repository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>https://repo.spring.io/snapshot</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>dynamodb-local</id>
<name>DynamoDB Local Release Repository</name>
<url>${dynamodblocal.repository.url}</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>https://repo.spring.io/snapshot</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
<pluginRepository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
<properties>
<!-- The main class to start by executing java -jar -->

49
pom.xml
View File

@ -43,9 +43,15 @@
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit.jupiter.version}</version>
<version>${junit-jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit-jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
@ -70,6 +76,14 @@
<version>${mockito.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-logger-api</artifactId>
<version>${maven-surefire-plugin.version}</version>
<!-- to get around bug https://github.com/junit-team/junit5/issues/801 -->
<scope>test</scope>
<optional>true</optional>
</dependency>
</dependencies>
<build>
@ -98,6 +112,23 @@
<exclude>**/*LiveTest.java</exclude>
</excludes>
</configuration>
<dependencies>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-surefire-provider</artifactId>
<version>${junit-platform.version}</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit-jupiter.version}</version>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>${junit-jupiter.version}</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
@ -187,6 +218,10 @@
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>${maven-war-plugin.version}</version>
</plugin>
</plugins>
<extensions>
<extension>
@ -406,6 +441,7 @@
<module>spring-4</module>
<module>spring-5</module>
<module>spring-5-reactive</module>
<module>spring-5-reactive-client</module>
<module>spring-5-mvc</module>
<module>spring-5-security</module>
<module>spring-activiti</module>
@ -551,7 +587,6 @@
<module>apache-meecrowave</module>
<module>spring-reactive-kotlin</module>
<module>jnosql</module>
<module>testing-modules/junit-abstract</module>
<module>sse-jaxrs</module>
<module>spring-boot-angular-ecommerce</module>
</modules>
@ -664,6 +699,7 @@
<module>spring-4</module>
<module>spring-5</module>
<module>spring-5-reactive</module>
<module>spring-5-reactive-client</module>
<module>spring-5-mvc</module>
<module>spring-5-security</module>
<module>spring-activiti</module>
@ -673,7 +709,6 @@
<module>spring-amqp-simple</module>
<module>spring-apache-camel</module>
<module>spring-batch</module>
<module>testing-modules/junit-abstract</module>
<module>jmh</module>
<!-- group 2 - Pass, 11-16 min, 42 test failures, 4,020 KB -->
@ -905,6 +940,7 @@
<module>json</module>
<module>jsoup</module>
<module>testing-modules/junit-5</module>
<module>testing-modules/junit5-migration</module>
<module>jws</module>
<module>libraries-data</module>
<module>linkrest</module>
@ -943,6 +979,7 @@
<module>spark-java</module>
<module>spring-4</module>
<module>spring-5-reactive</module>
<module>spring-5-reactive-client</module>
<module>spring-5-mvc</module>
<module>spring-5-security</module>
<module>spring-activiti</module>
@ -1079,7 +1116,6 @@
<module>antlr</module>
<module>maven-archetype</module>
<module>apache-meecrowave</module>
<module>testing-modules/junit-abstract</module>
<module>spring-hibernate4</module>
<module>xml</module>
@ -1222,7 +1258,7 @@
<maven-failsafe-plugin.version>2.19.1</maven-failsafe-plugin.version>
<commons-io.version>2.5</commons-io.version>
<commons-cli.version>1.4</commons-cli.version>
<maven-war-plugin.version>2.6</maven-war-plugin.version>
<maven-war-plugin.version>3.0.0</maven-war-plugin.version>
<javax.servlet-api.version>3.1.0</javax.servlet-api.version>
<jstl-api.version>1.2</jstl-api.version>
<javax.servlet.jsp-api.version>2.3.1</javax.servlet.jsp-api.version>
@ -1230,7 +1266,8 @@
<jstl.version>1.2</jstl.version>
<jackson-databind.version>2.5.0</jackson-databind.version>
<commons-fileupload.version>1.3</commons-fileupload.version>
<junit.jupiter.version>5.0.2</junit.jupiter.version>
<junit-platform.version>1.2.0</junit-platform.version>
<junit-jupiter.version>5.2.0</junit-jupiter.version>
<directory-maven-plugin.version>0.3.1</directory-maven-plugin.version>
<maven-install-plugin.version>2.5.1</maven-install-plugin.version>
<custom-pmd.version>0.0.1</custom-pmd.version>

View File

@ -82,11 +82,6 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.jayway.restassured</groupId>
<artifactId>rest-assured</artifactId>
@ -137,46 +132,11 @@
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<failIfNoTests>false</failIfNoTests>
<excludes>
<exclude>**/*IntegrationTest.java</exclude>
<exclude>**/*IntTest.java</exclude>
<exclude>**/*LiveTest.java</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
<properties>
<jayway-rest-assured.version>2.9.0</jayway-rest-assured.version>
<kotlin.version>1.1.2</kotlin.version>
</properties>
</project>

View File

@ -11,8 +11,8 @@
<description>spring 5 sample project about new features</description>
<parent>
<artifactId>parent-boot-2</artifactId>
<groupId>com.baeldung</groupId>
<artifactId>parent-boot-2</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../parent-boot-2</relativePath>
</parent>
@ -43,20 +43,6 @@
<groupId>javax.json.bind</groupId>
<artifactId>javax.json.bind-api</artifactId>
</dependency>
<!-- Dependencies for Yasson -->
<!-- <dependency> -->
<!-- <groupId>org.eclipse</groupId> -->
<!-- <artifactId>yasson</artifactId> -->
<!-- <version>1.0</version> -->
<!-- </dependency> -->
<!-- <dependency> -->
<!-- <groupId>org.glassfish</groupId> -->
<!-- <artifactId>javax.json</artifactId> -->
<!-- <version>1.1.2</version> -->
<!-- </dependency> -->
<!-- Dependencies for Johnzon -->
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-json_1.1_spec</artifactId>
@ -102,28 +88,6 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-surefire-provider</artifactId>
<version>${junit.platform.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-runner</artifactId>
<version>${junit.platform.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
@ -145,54 +109,10 @@
<layout>JAR</layout>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<forkCount>3</forkCount>
<reuseForks>true</reuseForks>
<parallel>methods</parallel>
<useUnlimitedThreads>true</useUnlimitedThreads>
<excludes>
<exclude>**/*IntegrationTest.java</exclude>
<exclude>**/*IntTest.java</exclude>
<exclude>**/*LiveTest.java</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<junit.platform.version>1.0.0</junit.platform.version>
<junit.jupiter.version>5.0.0</junit.jupiter.version>
<maven-surefire-plugin.version>2.20</maven-surefire-plugin.version>
<spring.version>5.0.2.RELEASE</spring.version>
<reactor-spring.version>1.0.1.RELEASE</reactor-spring.version>
<johnzon.version>1.1.3</johnzon.version>
<jsonb-api.version>1.0</jsonb-api.version>

View File

@ -43,20 +43,6 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<!-- Dependencies for Yasson -->
<!-- <dependency> -->
<!-- <groupId>org.eclipse</groupId> -->
<!-- <artifactId>yasson</artifactId> -->
<!-- <version>1.0</version> -->
<!-- </dependency> -->
<!-- <dependency> -->
<!-- <groupId>org.glassfish</groupId> -->
<!-- <artifactId>javax.json</artifactId> -->
<!-- <version>1.1.2</version> -->
<!-- </dependency> -->
<!-- Dependencies for Johnzon -->
<!-- lombok -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
@ -100,28 +86,6 @@
<version>${commons-collections4.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-surefire-provider</artifactId>
<version>${junit.platform.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-runner</artifactId>
<version>${junit.platform.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
@ -159,29 +123,10 @@
<layout>JAR</layout>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<forkCount>3</forkCount>
<reuseForks>true</reuseForks>
<parallel>methods</parallel>
<useUnlimitedThreads>true</useUnlimitedThreads>
<excludes>
<exclude>**/*IntegrationTest.java</exclude>
<exclude>**/*IntTest.java</exclude>
<exclude>**/*LiveTest.java</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<junit.platform.version>1.0.0</junit.platform.version>
<junit.jupiter.version>5.0.2</junit.jupiter.version>
<maven-surefire-plugin.version>2.20</maven-surefire-plugin.version>
<reactor-spring.version>1.0.1.RELEASE</reactor-spring.version>
<rxjava-version>2.1.12</rxjava-version>
<johnzon.version>1.1.3</johnzon.version>

View File

@ -76,44 +76,7 @@
<layout>JAR</layout>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<forkCount>3</forkCount>
<reuseForks>true</reuseForks>
<parallel>methods</parallel>
<useUnlimitedThreads>true</useUnlimitedThreads>
<excludes>
<exclude>**/*IntegrationTest.java</exclude>
<exclude>**/*IntTest.java</exclude>
<exclude>**/*LiveTest.java</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</project>

View File

@ -14,7 +14,7 @@ import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = InMemoryAuthApplication.class, webEnvironment = WebEnvironment.RANDOM_PORT)
public class InMemoryAuthControllerTest {
public class InMemoryAuthControllerIntegrationTest {
@Autowired
private TestRestTemplate template;

View File

@ -41,18 +41,6 @@
<groupId>javax.json.bind</groupId>
<artifactId>javax.json.bind-api</artifactId>
</dependency>
<!-- Dependencies for Yasson -->
<!-- <dependency> -->
<!-- <groupId>org.eclipse</groupId> -->
<!-- <artifactId>yasson</artifactId> -->
<!-- <version>1.0</version> -->
<!-- </dependency> -->
<!-- <dependency> -->
<!-- <groupId>org.glassfish</groupId> -->
<!-- <artifactId>javax.json</artifactId> -->
<!-- <version>1.1.2</version> -->
<!-- </dependency> -->
<!-- Dependencies for Johnzon -->
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-json_1.1_spec</artifactId>
@ -85,45 +73,21 @@
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-collections4</artifactId>
<version>${commons-collections4.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-surefire-provider</artifactId>
<version>${junit.platform.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-runner</artifactId>
<version>${junit.platform.version}</version>
<scope>test</scope>
</dependency>
<!-- restdocs -->
<dependency>
<groupId>org.springframework.restdocs</groupId>
@ -147,22 +111,6 @@
<layout>JAR</layout>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<forkCount>3</forkCount>
<reuseForks>true</reuseForks>
<parallel>methods</parallel>
<useUnlimitedThreads>true</useUnlimitedThreads>
<excludes>
<exclude>**/*IntegrationTest.java</exclude>
<exclude>**/*IntTest.java</exclude>
<exclude>**/*LiveTest.java</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>org.asciidoctor</groupId>
<artifactId>asciidoctor-maven-plugin</artifactId>
@ -190,9 +138,6 @@
</build>
<properties>
<junit.platform.version>1.0.0</junit.platform.version>
<spring.version>5.0.2.RELEASE</spring.version>
<reactor-spring.version>1.0.1.RELEASE</reactor-spring.version>
<geronimo-json_1.1_spec.version>1.0</geronimo-json_1.1_spec.version>
<asciidoctor-plugin.version>1.5.6</asciidoctor-plugin.version>
<commons-collections4.version>4.1</commons-collections4.version>

View File

@ -1,16 +0,0 @@
package com.baeldung.springbootmvc;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest
public class SpringBootMvcApplicationTests {
@Test
public void contextLoads() {
}
}

View File

@ -16,7 +16,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
@RunWith(SpringRunner.class)
@SpringBootTest
@AutoConfigureMockMvc
public class SpringBootMvcApplicationTests {
public class SpringBootMvcApplicationUnitTest {
@Autowired
private MockMvc mockMvc;

View File

@ -149,6 +149,12 @@
<artifactId>rome</artifactId>
<version>${rome.version}</version>
</dependency>
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>chaos-monkey-spring-boot</artifactId>
<version>${chaos.monkey.version}</version>
</dependency>
</dependencies>
<build>
@ -219,9 +225,11 @@
<tomee-servlet-api.version>8.5.11</tomee-servlet-api.version>
<togglz.version>2.4.1.Final</togglz.version>
<rome.version>1.9.0</rome.version>
<chaos.monkey.version>2.0.0</chaos.monkey.version>
<graphql-spring-boot-starter.version>3.6.0</graphql-spring-boot-starter.version>
<graphql-java-tools.version>3.2.0</graphql-java-tools.version>
<guava.version>18.0</guava.version>
<junit-platform.version>1.2.0</junit-platform.version>
</properties>
</project>

View File

@ -0,0 +1,15 @@
package com.baeldung.chaosmonkey;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
/**
* Created by adi on 8/2/18.
*/
@SpringBootApplication(scanBasePackages = { "com.baeldung.chaosmonkey" })
public class SpringBootChaosMonkeyApp {
public static void main(String[] args) {
SpringApplication.run(SpringBootChaosMonkeyApp.class, args);
}
}

View File

@ -0,0 +1,25 @@
package com.baeldung.chaosmonkey.controller;
import com.baeldung.chaosmonkey.service.PermissionsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
/**
* Created by adi on 8/2/18.
*/
@RestController
@RequestMapping("/permissions")
public class PermissionsController {
@Autowired private PermissionsService permissionsService;
@GetMapping
public List<String> getAllPermissions() {
return permissionsService.getAllPermissions();
}
}

View File

@ -0,0 +1,17 @@
package com.baeldung.chaosmonkey.service;
import org.springframework.stereotype.Service;
import java.util.Arrays;
import java.util.List;
/**
* Created by adi on 8/2/18.
*/
@Service
public class PermissionsService {
public List<String> getAllPermissions() {
return Arrays.asList("CREATE", "READ", "UPDATE", "DELETE");
}
}

View File

@ -43,3 +43,34 @@ servlet.mapping=/dispatcherExampleURL
#spring.banner.image.invert= //TODO
contactInfoType=email
#chaos monkey for spring boot props
management.endpoint.chaosmonkey.enabled=true
management.endpoint.chaosmonkeyjmx.enabled=true
spring.profiles.active=chaos-monkey
#Determine whether should execute or not
chaos.monkey.enabled=true
#How many requests are to be attacked. 1: attack each request; 5: each 5th request is attacked
chaos.monkey.assaults.level=1
#Minimum latency in ms added to the request
chaos.monkey.assaults.latencyRangeStart=3000
#Maximum latency in ms added to the request
chaos.monkey.assaults.latencyRangeEnd=15000
#Latency assault active
chaos.monkey.assaults.latencyActive=true
#Exception assault active
chaos.monkey.assaults.exceptionsActive=false
#AppKiller assault active
chaos.monkey.assaults.killApplicationActive=false
#Controller watcher active
chaos.monkey.watcher.controller=false
#RestController watcher active
chaos.monkey.watcher.restController=false
#Service watcher active
chaos.monkey.watcher.service=true
#Repository watcher active
chaos.monkey.watcher.repository=false
#Component watcher active
chaos.monkey.watcher.component=false

View File

@ -79,7 +79,7 @@
<properties>
<spring-cloud-dependencies.version>Brixton.SR7</spring-cloud-dependencies.version>
<maven-surefire-plugin.version>2.19.1</maven-surefire-plugin.version>
<maven-surefire-plugin.version>2.21.0</maven-surefire-plugin.version>
<postgresql.version>9.4-1201-jdbc4</postgresql.version>
</properties>

View File

@ -28,7 +28,7 @@
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-gateway</artifactId>
<artifactId>spring-cloud-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
@ -54,27 +54,8 @@
</dependency>
</dependencies>
<repositories>
<repository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>https://repo.spring.io/snapshot</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<properties>
<cloud.version>2.0.0.RC2</cloud.version>
<cloud.version>2.0.1.RELEASE</cloud.version>
<hibernate-validator.version>6.0.2.Final</hibernate-validator.version>
</properties>

View File

@ -38,25 +38,6 @@
</dependencies>
</dependencyManagement>
<repositories>
<repository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>https://repo.spring.io/snapshot</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<properties>
<spring-cloud-dependencies.version>Brixton.SR7</spring-cloud-dependencies.version>
</properties>

View File

@ -19,9 +19,6 @@
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<kotlin.version>1.2.41</kotlin.version>
</properties>

View File

@ -85,7 +85,6 @@
</build>
<properties>
<maven-surefire-plugin.version>2.19.1</maven-surefire-plugin.version>
<jackson.library>2.9.2</jackson.library>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>

View File

@ -51,27 +51,6 @@
</dependency>
</dependencies>
<repositories>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
<properties>
<spring-security-oauth2.version>2.2.1.RELEASE</spring-security-oauth2.version>
<spring-security-jwt.version>1.0.9.RELEASE</spring-security-jwt.version>

View File

@ -1,5 +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">
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>spring-thymeleaf</artifactId>
@ -8,8 +8,9 @@
<parent>
<groupId>com.baeldung</groupId>
<artifactId>parent-modules</artifactId>
<version>1.0.0-SNAPSHOT</version>
<artifactId>parent-spring-5</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../parent-spring-5</relativePath>
</parent>
<dependencies>
@ -17,7 +18,7 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${org.springframework-version}</version>
<version>${spring.version}</version>
<exclusions>
<!-- Exclude Commons Logging in favor of SLF4j -->
<exclusion>
@ -29,19 +30,38 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${org.springframework-version}</version>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-commons</artifactId>
<version>${spring-data.version}</version>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>${javax.validation-version}</version>
</dependency>
<dependency>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator</artifactId>
<version>${hibernate-validator.version}</version>
</dependency>
<!-- Spring Security -->
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
<version>${springframework-security.version}</version>
<version>${spring-security.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
<version>${springframework-security.version}</version>
<version>${spring-security.version}</version>
</dependency>
<!-- Thymeleaf -->
<dependency>
<groupId>org.thymeleaf</groupId>
@ -50,10 +70,9 @@
</dependency>
<dependency>
<groupId>org.thymeleaf</groupId>
<artifactId>thymeleaf-spring4</artifactId>
<artifactId>thymeleaf-spring5</artifactId>
<version>${org.thymeleaf-version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/nz.net.ultraq.thymeleaf/thymeleaf-layout-dialect -->
<dependency>
<groupId>nz.net.ultraq.thymeleaf</groupId>
<artifactId>thymeleaf-layout-dialect</artifactId>
@ -64,60 +83,29 @@
<artifactId>thymeleaf-extras-java8time</artifactId>
<version>${org.thymeleaf.extras-version}</version>
</dependency>
<!-- Servlet -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>${javax.servlet-version}</version>
<version>${javax.servlet-api.version}</version>
<scope>provided</scope>
</dependency>
<!-- Validation -->
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>${javax.validation-version}</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>${hibernate-validator.version}</version>
</dependency>
<!-- test scoped -->
<!-- test scoped -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${org.springframework-version}</version>
<version>${spring.version}</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.security/spring-security-test -->
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<version>${springframework-security.version}</version>
<version>${spring-security.version}</version>
<scope>test</scope>
</dependency>
<!-- <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
<version>2.0.1.RELEASE</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency> -->
<!-- Spring data -->
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-commons</artifactId>
<version>${springFramework-data.version}</version>
</dependency>
</dependencies>
@ -131,7 +119,7 @@
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
@ -151,7 +139,7 @@
</configuration>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
@ -176,22 +164,14 @@
</build>
<properties>
<!-- spring -->
<org.springframework-version>4.3.4.RELEASE</org.springframework-version>
<springframework-security.version>4.2.0.RELEASE</springframework-security.version>
<springFramework-data.version>2.0.7.RELEASE</springFramework-data.version>
<javax.servlet-version>3.1.0</javax.servlet-version>
<!-- thymeleaf -->
<spring-data.version>2.0.9.RELEASE</spring-data.version>
<org.thymeleaf-version>3.0.9.RELEASE</org.thymeleaf-version>
<org.thymeleaf.extras-version>3.0.0.RELEASE</org.thymeleaf.extras-version>
<thymeleaf-layout-dialect.version>2.1.2</thymeleaf-layout-dialect.version>
<!-- validation -->
<javax.validation-version>1.1.0.Final</javax.validation-version>
<hibernate-validator.version>5.3.3.Final</hibernate-validator.version>
<org.hibernate-version>5.2.5.Final</org.hibernate-version>
<org.thymeleaf.extras-version>3.0.1.RELEASE</org.thymeleaf.extras-version>
<thymeleaf-layout-dialect.version>2.3.0</thymeleaf-layout-dialect.version>
<javax.validation-version>2.0.1.Final</javax.validation-version>
<hibernate-validator.version>6.0.11.Final</hibernate-validator.version>
<!-- Maven plugins -->
<maven-war-plugin.version>2.6</maven-war-plugin.version>
<cargo-maven2-plugin.version>1.6.1</cargo-maven2-plugin.version>
<tomcat7-maven-plugin.version>2.2</tomcat7-maven-plugin.version>
</properties>

View File

@ -2,6 +2,9 @@ package com.baeldung.thymeleaf.config;
import java.util.Locale;
import nz.net.ultraq.thymeleaf.LayoutDialect;
import nz.net.ultraq.thymeleaf.decorators.strategies.GroupingStrategy;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.annotation.Bean;
@ -15,23 +18,20 @@ import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.i18n.LocaleChangeInterceptor;
import org.springframework.web.servlet.i18n.SessionLocaleResolver;
import org.thymeleaf.TemplateEngine;
import org.thymeleaf.extras.java8time.dialect.Java8TimeDialect;
import org.thymeleaf.spring4.SpringTemplateEngine;
import org.thymeleaf.spring4.templateresolver.SpringResourceTemplateResolver;
import org.thymeleaf.spring4.view.ThymeleafViewResolver;
import org.thymeleaf.spring5.ISpringTemplateEngine;
import org.thymeleaf.spring5.SpringTemplateEngine;
import org.thymeleaf.spring5.templateresolver.SpringResourceTemplateResolver;
import org.thymeleaf.spring5.view.ThymeleafViewResolver;
import org.thymeleaf.templatemode.TemplateMode;
import org.thymeleaf.templateresolver.ITemplateResolver;
import com.baeldung.thymeleaf.formatter.NameFormatter;
import com.baeldung.thymeleaf.utils.ArrayUtil;
import nz.net.ultraq.thymeleaf.LayoutDialect;
import nz.net.ultraq.thymeleaf.decorators.strategies.GroupingStrategy;
@Configuration
@EnableWebMvc
@ComponentScan({ "com.baeldung.thymeleaf" })
@ -39,10 +39,11 @@ import nz.net.ultraq.thymeleaf.decorators.strategies.GroupingStrategy;
* Java configuration file that is used for Spring MVC and Thymeleaf
* configurations
*/
public class WebMVCConfig extends WebMvcConfigurerAdapter implements ApplicationContextAware {
public class WebMVCConfig implements WebMvcConfigurer, ApplicationContextAware {
private ApplicationContext applicationContext;
@Override
public void setApplicationContext(ApplicationContext applicationContext) {
this.applicationContext = applicationContext;
}
@ -77,7 +78,7 @@ public class WebMVCConfig extends WebMvcConfigurerAdapter implements Application
return resolver;
}
private TemplateEngine templateEngine(ITemplateResolver templateResolver) {
private ISpringTemplateEngine templateEngine(ITemplateResolver templateResolver) {
SpringTemplateEngine engine = new SpringTemplateEngine();
engine.addDialect(new LayoutDialect(new GroupingStrategy()));
engine.addDialect(new Java8TimeDialect());

View File

@ -27,7 +27,7 @@ public class WebMVCSecurity extends WebSecurityConfigurerAdapter {
@Override
protected void configure(final AuthenticationManagerBuilder auth) throws Exception {
auth.inMemoryAuthentication().withUser("user1").password("user1Pass").authorities("ROLE_USER");
auth.inMemoryAuthentication().withUser("user1").password("{noop}user1Pass").authorities("ROLE_USER");
}
@Override

View File

@ -1,10 +1,22 @@
package com.baeldung.thymeleaf.controller;
import static org.hamcrest.Matchers.containsString;
import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.user;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import javax.servlet.Filter;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mock.web.MockHttpSession;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.request.RequestPostProcessor;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
@ -15,21 +27,6 @@ import com.baeldung.thymeleaf.config.WebApp;
import com.baeldung.thymeleaf.config.WebMVCConfig;
import com.baeldung.thymeleaf.config.WebMVCSecurity;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.user;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import javax.servlet.Filter;
import static org.hamcrest.Matchers.containsString;
@RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration
@ContextConfiguration(classes = { WebApp.class, WebMVCConfig.class, WebMVCSecurity.class, InitSecurity.class })

View File

@ -33,6 +33,12 @@
<version>${junit.vintage.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-migrationsupport</artifactId>
<version>${junit.vintage.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
@ -54,6 +60,24 @@
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>${powermock.version}</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito2</artifactId>
<version>${powermock.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
@ -94,13 +118,14 @@
</build>
<properties>
<junit.jupiter.version>5.1.0</junit.jupiter.version>
<junit.platform.version>1.1.0</junit.platform.version>
<junit.jupiter.version>5.2.0</junit.jupiter.version>
<junit.platform.version>1.2.0</junit.platform.version>
<junit.vintage.version>5.2.0</junit.vintage.version>
<log4j2.version>2.8.2</log4j2.version>
<h2.version>1.4.196</h2.version>
<mockito.version>2.11.0</mockito.version>
<maven-surefire-plugin.version>2.19.1</maven-surefire-plugin.version>
<mockito.version>2.8.9</mockito.version>
<powermock.version>1.7.4</powermock.version>
<maven-surefire-plugin.version>2.21.0</maven-surefire-plugin.version>
<exec-maven-plugin.version>1.6.0</exec-maven-plugin.version>
<spring.version>5.0.1.RELEASE</spring.version>
</properties>

View File

@ -1,7 +1,7 @@
/**
*
*/
package org.baeldung.testing.abstractclass.abstractmethod;
package com.baeldung.abstractclass.abstractmethod;
/**
* When method calls abstract method.

View File

@ -1,4 +1,4 @@
package org.baeldung.testing.abstractclass.indepedentmethod;
package com.baeldung.abstractclass.indepedentmethod;
/**
* Test Independent Method

View File

@ -1,4 +1,4 @@
package org.baeldung.testing.abstractclass.indepedentmethod;
package com.baeldung.abstractclass.indepedentmethod;
public class ConcreteImpl extends AbstractIndependent {

View File

@ -1,4 +1,4 @@
package org.baeldung.testing.abstractclass.instancefields;
package com.baeldung.abstractclass.instancefields;
/**
* Test Independent Method

View File

@ -1,4 +1,4 @@
package org.baeldung.testing.abstractclass.privatemethod;
package com.baeldung.abstractclass.privatemethod;
import java.time.LocalDateTime;

View File

@ -11,14 +11,17 @@ import java.util.Optional;
import java.util.function.BooleanSupplier;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
/**
* Unit test that demonstrate the different assertions available within JUnit 4
*/
@DisplayName("Test case for assertions")
public class AssertionUnitTest {
@Test
@DisplayName("Arrays should be equals")
public void whenAssertingArraysEquality_thenEqual() {
char[] expected = {'J', 'u', 'p', 'i', 't', 'e', 'r'};
char[] actual = "Jupiter".toCharArray();
@ -27,6 +30,7 @@ public class AssertionUnitTest {
}
@Test
@DisplayName("The area of two polygons should be equal")
public void whenAssertingEquality_thenEqual() {
float square = 2 * 2;
float rectangle = 2 * 2;

View File

@ -10,13 +10,13 @@ import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
public class NestedUnitTest {
Stack<Object> stack;
boolean isRun = false;
@Test
@DisplayName("is instantiated with new Stack()")
void isInstantiatedWithNew() {
new Stack<Object>();
new Stack<>();
}
@Nested
@ -25,7 +25,7 @@ public class NestedUnitTest {
@BeforeEach
void init() {
stack = new Stack<Object>();
stack = new Stack<>();
}
@Test

View File

@ -1,4 +1,4 @@
package org.baeldung.testing.abstractclass.abstractmethod;
package com.baeldung.abstractclass.abstractmethod;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;

View File

@ -1,7 +1,7 @@
/**
*
*/
package org.baeldung.testing.abstractclass.indepedentmethod;
package com.baeldung.abstractclass.indepedentmethod;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

View File

@ -1,4 +1,4 @@
package org.baeldung.testing.abstractclass.instancefields;
package com.baeldung.abstractclass.instancefields;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

View File

@ -1,9 +1,7 @@
/**
*
*/
package org.baeldung.testing.abstractclass.privatemethod;
import java.time.LocalDateTime;
package com.baeldung.abstractclass.privatemethod;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
@ -12,6 +10,8 @@ import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import java.time.LocalDateTime;
/**
* Providing custom values for private methods using powermock
*

View File

@ -1,4 +1,4 @@
package com.baeldung;
package com.baeldung.migration.junit5;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assumptions.assumeFalse;
@ -10,19 +10,19 @@ import org.junit.jupiter.api.Test;
public class AssumptionUnitTest {
@Test
void trueAssumption() {
assumeTrue(5 > 1);
public void trueAssumption() {
assumeTrue(5 > 1, () -> "5 is greater the 1");
assertEquals(5 + 2, 7);
}
@Test
void falseAssumption() {
assumeFalse(5 < 1);
public void falseAssumption() {
assumeFalse(5 < 1, () -> "5 is less then 1");
assertEquals(5 + 2, 7);
}
@Test
void assumptionThat() {
public void assumptionThat() {
String someString = "Just a string";
assumingThat(someString.equals("Just a string"), () -> assertEquals(2 + 2, 4));
}

View File

@ -0,0 +1,24 @@
package com.baeldung.runfromjava;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertTrue;
class FirstUnitTest {
@Test
void whenThis_thenThat() {
assertTrue(true);
}
@Test
void whenSomething_thenSomething() {
assertTrue(true);
}
@Test
void whenSomethingElse_thenSomethingElse() {
assertTrue(true);
}
}

View File

@ -1,4 +1,4 @@
package com.baeldung.junit5.runfromjava;
package com.baeldung.runfromjava;
import org.junit.platform.launcher.Launcher;
import org.junit.platform.launcher.LauncherDiscoveryRequest;
@ -14,7 +14,7 @@ import static org.junit.platform.engine.discovery.ClassNameFilter.includeClassNa
import static org.junit.platform.engine.discovery.DiscoverySelectors.selectClass;
import static org.junit.platform.engine.discovery.DiscoverySelectors.selectPackage;
public class RunJUnit5Tests {
public class RunJUnit5TestsFromJava {
SummaryGeneratingListener listener = new SummaryGeneratingListener();
public void runOne() {
@ -32,7 +32,7 @@ public class RunJUnit5Tests {
public void runAll() {
LauncherDiscoveryRequest request = LauncherDiscoveryRequestBuilder
.request()
.selectors(selectPackage("com.baeldung.junit5.runfromjava"))
.selectors(selectPackage("com.baeldung.runfromjava"))
.filters(includeClassNamePatterns(".*Test"))
.build();
Launcher launcher = LauncherFactory.create();
@ -45,7 +45,7 @@ public class RunJUnit5Tests {
}
public static void main(String[] args) {
RunJUnit5Tests runner = new RunJUnit5Tests();
RunJUnit5TestsFromJava runner = new RunJUnit5TestsFromJava();
runner.runAll();
TestExecutionSummary summary = runner.listener.getSummary();

View File

@ -0,0 +1,18 @@
package com.baeldung.runfromjava;
import org.junit.jupiter.api.RepeatedTest;
import static org.junit.jupiter.api.Assertions.assertTrue;
class SecondUnitTest {
@RepeatedTest(10)
void whenSomething_thenSomething() {
assertTrue(true);
}
@RepeatedTest(5)
void whenSomethingElse_thenSomethingElse() {
assertTrue(true);
}
}

View File

@ -1,62 +0,0 @@
<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>junit-abstract</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>abstractclasses</name>
<url>http://maven.apache.org</url>
<parent>
<groupId>com.baeldung</groupId>
<artifactId>parent-modules</artifactId>
<version>1.0.0-SNAPSHOT</version>
<relativePath>../../</relativePath>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<powermock.version>1.7.4</powermock.version>
<java.version>1.8</java.version>
<junit.jupiter.version>5.1.0</junit.jupiter.version>
<junit.platform.version>1.1.0</junit.platform.version>
<junit.vintage.version>5.2.0</junit.vintage.version>
</properties>
<dependencies>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>${powermock.version}</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito2</artifactId>
<version>${powermock.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.0</version>
</plugin>
</plugins>
<finalName>junit-abstract</finalName>
</build>
</project>

View File

@ -1,13 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
</pattern>
</encoder>
</appender>
<root level="INFO">
<appender-ref ref="STDOUT" />
</root>
</configuration>

View File

@ -0,0 +1,3 @@
### Relevant Articles:
- [JUnit4 -> JUnit5 migration guide](http://www.baeldung.com/junit4-junit5-migration-guide)

View File

@ -0,0 +1,90 @@
<?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">
<modelVersion>4.0.0</modelVersion>
<artifactId>junit5-migration</artifactId>
<version>1.0-SNAPSHOT</version>
<name>junit5-migration</name>
<description>JUnit 4 -> JUnit 5 migration</description>
<parent>
<groupId>com.baeldung</groupId>
<artifactId>parent-modules</artifactId>
<version>1.0.0-SNAPSHOT</version>
<relativePath>../../</relativePath>
</parent>
<dependencies>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-engine</artifactId>
<version>${junit.platform.version}</version>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-runner</artifactId>
<version>${junit.platform.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>${junit.vintage.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-migrationsupport</artifactId>
<version>${junit.vintage.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<directory>src/test/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
<dependencies>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-surefire-provider</artifactId>
<version>${junit.platform.version}</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>${exec-maven-plugin.version}</version>
<executions>
<execution>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>com.baeldung.TestLauncher</mainClass>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<junit.jupiter.version>5.2.0</junit.jupiter.version>
<junit.platform.version>1.2.0</junit.platform.version>
<junit.vintage.version>5.2.0</junit.vintage.version>
<maven-surefire-plugin.version>2.21.0</maven-surefire-plugin.version>
<exec-maven-plugin.version>1.6.0</exec-maven-plugin.version>
</properties>
</project>

View File

@ -0,0 +1,22 @@
package com.baeldung.junit4;
import com.baeldung.junit4.categories.Annotations;
import com.baeldung.junit4.categories.JUnit4UnitTest;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;
@Category(value = { Annotations.class, JUnit4UnitTest.class })
public class AnnotationTestExampleUnitTest {
@Test(expected = Exception.class)
public void shouldRaiseAnException() throws Exception {
throw new Exception("This is my expected exception");
}
@Test(timeout = 1)
@Ignore
public void shouldFailBecauseTimeout() throws InterruptedException {
Thread.sleep(10);
}
}

View File

@ -0,0 +1,36 @@
package com.baeldung.junit4;
import org.junit.Assert;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import java.util.Arrays;
import static org.hamcrest.CoreMatchers.hasItems;
import static org.junit.Assert.*;
import static org.junit.Assert.assertArrayEquals;
@DisplayName("Test case for assertions")
public class AssertionUnitTest {
@Test
@DisplayName("Arrays should be equals")
public void whenAssertingArraysEquality_thenEqual() {
char[] expected = {'J', 'u', 'p', 'i', 't', 'e', 'r'};
char[] actual = "Jupiter".toCharArray();
assertArrayEquals("Arrays should be equal", expected, actual);
}
@Test
public void givenMultipleAssertion_whenAssertingAll_thenOK() {
assertEquals("4 is 2 times 2", 4, 2 * 2);
assertEquals("java", "JAVA".toLowerCase());
assertEquals("null is equal to null", null, null);
}
@Test
public void testAssertThatHasItems() {
assertThat(Arrays.asList("Java", "Kotlin", "Scala"), hasItems("Java", "Kotlin"));
}
}

View File

@ -0,0 +1,23 @@
package com.baeldung.junit4;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assume.assumeFalse;
import static org.junit.Assume.assumeTrue;
public class AssumeUnitTest {
@Test
public void trueAssumption() {
assumeTrue("5 is greater the 1", 5 > 1);
assertEquals(5 + 2, 7);
}
@Test
public void falseAssumption() {
assumeFalse("5 is less then 1", 5 < 1);
assertEquals(5 + 2, 7);
}
}

View File

@ -0,0 +1,24 @@
package com.baeldung.junit4;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
public class ExceptionAssertionUnitTest {
@Rule
public ExpectedException exceptionRule = ExpectedException.none();
@Test(expected = NullPointerException.class)
public void whenExceptionThrown_thenExpectationSatisfied() {
String test = null;
test.length();
}
@Test
public void whenExceptionThrown_thenRuleIsApplied() {
exceptionRule.expect(NumberFormatException.class);
exceptionRule.expectMessage("For input string");
Integer.parseInt("1a");
}
}

View File

@ -0,0 +1,16 @@
package com.baeldung.junit4;
import org.junit.Rule;
import org.junit.Test;
public class RuleExampleUnitTest {
@Rule
public final TraceUnitTestRule traceRuleTests = new TraceUnitTestRule();
@Test
public void whenTracingTests() {
System.out.println("This is my test");
/*...*/
}
}

View File

@ -0,0 +1,34 @@
package com.baeldung.junit4;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import java.util.logging.Logger;
public class TestAnnotationsUnitTest {
private static final Logger log = Logger.getLogger(TestAnnotationsUnitTest.class.getName());
@BeforeClass
static void setup() {
log.info("@BeforeAll - executes once before all test methods in this class");
}
@Before
void init() {
log.info("@BeforeEach - executes before each test method in this class");
}
@After
void tearDown() {
log.info("@AfterEach - executed after each test method.");
}
@AfterClass
static void done() {
log.info("@AfterAll - executed after all test methods.");
}
}

View File

@ -0,0 +1,35 @@
package com.baeldung.junit4;
import org.junit.rules.TestRule;
import org.junit.runner.Description;
import org.junit.runners.model.MultipleFailureException;
import org.junit.runners.model.Statement;
import java.util.ArrayList;
import java.util.List;
public class TraceUnitTestRule implements TestRule {
@Override
public Statement apply(Statement base, Description description) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
List<Throwable> errors = new ArrayList<Throwable>();
System.out.println("Starting test ... " + description.getMethodName());
try {
base.evaluate();
} catch (Throwable e) {
errors.add(e);
} finally {
System.out.println("... test finished. " + description.getMethodName());
}
MultipleFailureException.assertEmpty(errors);
}
};
}
}

View File

@ -0,0 +1,5 @@
package com.baeldung.junit4.categories;
public interface Annotations {
}

View File

@ -0,0 +1,5 @@
package com.baeldung.junit4.categories;
public interface JUnit4UnitTest {
}

View File

@ -0,0 +1,28 @@
package com.baeldung.junit5;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.platform.runner.JUnitPlatform;
import org.junit.runner.RunWith;
import java.time.Duration;
@Tag("annotations")
@Tag("junit5")
@RunWith(JUnitPlatform.class)
public class AnnotationTestExampleUnitTest {
@Test
public void shouldRaiseAnException() throws Exception {
Assertions.assertThrows(Exception.class, () -> {
throw new Exception("This is my expected exception");
});
}
@Test
@Disabled
public void shouldFailBecauseTimeout() throws InterruptedException {
Assertions.assertTimeout(Duration.ofMillis(1), () -> Thread.sleep(10));
}
}

View File

@ -0,0 +1,40 @@
package com.baeldung.junit5;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertAll;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
@DisplayName("Test case for assertions")
public class AssertionUnitTest {
@Test
@DisplayName("Arrays should be equals")
public void whenAssertingArraysEquality_thenEqual() {
char[] expected = {'J', 'u', 'p', 'i', 't', 'e', 'r'};
char[] actual = "Jupiter".toCharArray();
assertArrayEquals(expected, actual, "Arrays should be equal");
}
@Test
@DisplayName("The area of two polygons should be equal")
public void whenAssertingEquality_thenEqual() {
float square = 2 * 2;
float rectangle = 2 * 2;
assertEquals(square, rectangle);
}
@Test
public void givenMultipleAssertion_whenAssertingAll_thenOK() {
assertAll(
"heading",
() -> assertEquals(4, 2 * 2, "4 is 2 times 2"),
() -> assertEquals("java", "JAVA".toLowerCase()),
() -> assertEquals(null, null, "null is equal to null")
);
}
}

View File

@ -0,0 +1,27 @@
package com.baeldung.junit5;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assumptions.*;
public class AssumptionUnitTest {
@Test
public void trueAssumption() {
assumeTrue(5 > 1, () -> "5 is greater the 1");
assertEquals(5 + 2, 7);
}
@Test
public void falseAssumption() {
assumeFalse(5 < 1, () -> "5 is less then 1");
assertEquals(5 + 2, 7);
}
@Test
public void assumptionThat() {
String someString = "Just a string";
assumingThat(someString.equals("Just a string"), () -> assertEquals(2 + 2, 4));
}
}

View File

@ -0,0 +1,69 @@
package com.baeldung.junit5;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.*;
import static org.junit.jupiter.api.Assertions.*;
public class ConditionalExecutionUnitTest {
@Test
@EnabledOnOs({OS.MAC})
void whenOperatingSystemIsMac_thenTestIsEnabled() {
assertEquals(5 + 2, 7);
}
@Test
@DisabledOnOs({OS.WINDOWS})
void whenOperatingSystemIsWindows_thenTestIsDisabled() {
assertEquals(5 + 2, 7);
}
@Test
@EnabledOnJre({JRE.JAVA_8})
void whenRunningTestsOnJRE8_thenTestIsEnabled() {
assertTrue(5 > 4, "5 is greater the 4");
assertTrue(null == null, "null is equal to null");
}
@Test
@DisabledOnJre({JRE.JAVA_10})
void whenRunningTestsOnJRE10_thenTestIsDisabled() {
assertTrue(5 > 4, "5 is greater the 4");
assertTrue(null == null, "null is equal to null");
}
@Test
@EnabledIfSystemProperty(named = "os.arch", matches = ".*64.*")
public void whenRunningTestsOn64BitArchitectures_thenTestIsDisabled() {
Integer value = 5; // result of an algorithm
assertNotEquals(0, value, "The result cannot be 0");
}
@Test
@DisabledIfSystemProperty(named = "ci-server", matches = "true")
public void whenRunningTestsOnCIServer_thenTestIsDisabled() {
Integer value = 5; // result of an algorithm
assertNotEquals(0, value, "The result cannot be 0");
}
@Test
@EnabledIfEnvironmentVariable(named = "ENV", matches = "staging-server")
public void whenRunningTestsStagingServer_thenTestIsEnabled() {
char[] expected = {'J', 'u', 'p', 'i', 't', 'e', 'r'};
char[] actual = "Jupiter".toCharArray();
assertArrayEquals(expected, actual, "Arrays should be equal");
}
@Test
@DisabledIfEnvironmentVariable(named = "ENV", matches = ".*development.*")
public void whenRunningTestsDevelopmentEnvironment_thenTestIsDisabled() {
char[] expected = {'J', 'u', 'p', 'i', 't', 'e', 'r'};
char[] actual = "Jupiter".toCharArray();
assertArrayEquals(expected, actual, "Arrays should be equal");
}
}

View File

@ -0,0 +1,77 @@
package com.baeldung.junit5;
import org.junit.jupiter.api.*;
import java.util.EmptyStackException;
import java.util.Stack;
public class NestedUnitTest {
Stack<Object> stack;
@Test
@DisplayName("is instantiated with new Stack()")
void isInstantiatedWithNew() {
new Stack<>();
}
@Nested
@DisplayName("when new")
class WhenNew {
@BeforeEach
void init() {
stack = new Stack<>();
}
@Test
@DisplayName("is empty")
void isEmpty() {
Assertions.assertTrue(stack.isEmpty());
}
@Test
@DisplayName("throws EmptyStackException when popped")
void throwsExceptionWhenPopped() {
Assertions.assertThrows(EmptyStackException.class, () -> stack.pop());
}
@Test
@DisplayName("throws EmptyStackException when peeked")
void throwsExceptionWhenPeeked() {
Assertions.assertThrows(EmptyStackException.class, () -> stack.peek());
}
@Nested
@DisplayName("after pushing an element")
class AfterPushing {
String anElement = "an element";
@BeforeEach
void init() {
stack.push(anElement);
}
@Test
@DisplayName("it is no longer empty")
void isEmpty() {
Assertions.assertFalse(stack.isEmpty());
}
@Test
@DisplayName("returns the element when popped and is empty")
void returnElementWhenPopped() {
Assertions.assertEquals(anElement, stack.pop());
Assertions.assertTrue(stack.isEmpty());
}
@Test
@DisplayName("returns the element when peeked but remains not empty")
void returnElementWhenPeeked() {
Assertions.assertEquals(anElement, stack.peek());
Assertions.assertFalse(stack.isEmpty());
}
}
}
}

View File

@ -0,0 +1,17 @@
package com.baeldung.junit5;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.platform.runner.JUnitPlatform;
import org.junit.runner.RunWith;
@RunWith(JUnitPlatform.class)
@ExtendWith(TraceUnitExtension.class)
public class RuleExampleUnitTest {
@Test
public void whenTracingTests() {
System.out.println("This is my test");
/*...*/
}
}

View File

@ -0,0 +1,27 @@
package com.baeldung.junit5;
import org.junit.Rule;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.migrationsupport.rules.EnableRuleMigrationSupport;
import org.junit.rules.ExpectedException;
@EnableRuleMigrationSupport
public class RuleMigrationSupportUnitTest {
@Rule
public ExpectedException exceptionRule = ExpectedException.none();
@Test
public void whenExceptionThrown_thenExpectationSatisfied() {
exceptionRule.expect(NullPointerException.class);
String test = null;
test.length();
}
@Test
public void whenExceptionThrown_thenRuleIsApplied() {
exceptionRule.expect(NumberFormatException.class);
exceptionRule.expectMessage("For input string");
Integer.parseInt("1a");
}
}

View File

@ -0,0 +1,39 @@
package com.baeldung.junit5;
import org.junit.jupiter.api.*;
import java.util.logging.Logger;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class TestAnnotationsUnitTest {
private static final Logger log = Logger.getLogger(TestAnnotationsUnitTest.class.getName());
@BeforeAll
static void setup() {
log.info("@BeforeAll - executes once before all test methods in this class");
}
@BeforeEach
void init() {
log.info("@BeforeEach - executes before each test method in this class");
}
@Test
@Disabled
void disabledTest() {
assertTrue(false);
}
@AfterEach
void tearDown() {
log.info("@AfterEach - executed after each test method.");
}
@AfterAll
static void done() {
log.info("@AfterAll - executed after all test methods.");
}
}

View File

@ -0,0 +1,19 @@
package com.baeldung.junit5;
import org.junit.jupiter.api.extension.AfterEachCallback;
import org.junit.jupiter.api.extension.BeforeEachCallback;
import org.junit.jupiter.api.extension.ExtensionContext;
public class TraceUnitExtension implements AfterEachCallback, BeforeEachCallback {
@Override
public void beforeEach(ExtensionContext context) throws Exception {
System.out.println("Starting test ... " + context.getDisplayName());
}
@Override
public void afterEach(ExtensionContext context) throws Exception {
System.out.println("... test finished. " + context.getDisplayName());
}
}

View File

@ -1,54 +0,0 @@
<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.junit</groupId>
<artifactId>applicationtesting</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>applicationtesting</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
<junit-jupiter.version>5.2.0</junit-jupiter.version>
<junit-launcher.version>1.2.0</junit-launcher.version>
<junit4.version>4.12</junit4.version>
<maven-compiler-plugin.version>3.7.0</maven-compiler-plugin.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit-jupiter.version}</version>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-launcher</artifactId>
<version>${junit-launcher.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit4.version}</version>
</dependency>
</dependencies>
</project>

View File

@ -1,41 +0,0 @@
package com.baeldung.junit.runfromjava.listnode;
public class ListNode {
private int value;
private ListNode next;
public ListNode(int v) {
value = v;
}
public ListNode(int v, ListNode next) {
value = v;
this.next = next;
}
public int getValue() {
return value;
}
public ListNode getNext() {
return next;
}
public void setNext(ListNode next) {
this.next = next;
}
public String toString() {
String result = "";
ListNode tmp = this;
while (tmp.next != null) {
result += tmp.value + "->";
tmp = tmp.next;
}
result += tmp.value;
return result.toString();
}
}

View File

@ -1,22 +0,0 @@
package com.baeldung.junit.runfromjava.listnode;
public class MergeLists {
public ListNode merge(ListNode list1, ListNode list2) {
if (list1 == null) {
return list2;
}
if (list2 == null) {
return list1;
}
if (list1.getValue() <= list2.getValue()) {
list1.setNext(merge(list1.getNext(), list2));
return list1;
} else {
list2.setNext(merge(list2.getNext(), list1));
return list2;
}
}
}

View File

@ -1,26 +0,0 @@
package com.baeldung.junit.runfromjava.listnode;
public class RemovedNthElement {
public ListNode removeNthFromEnd(ListNode head, int n) {
ListNode start = new ListNode(0);
start.setNext(head);
ListNode fast = start;
ListNode slow = start;
for (int i = 0; i < n + 1 && fast != null; i++) {
fast = fast.getNext();
}
while (fast != null) {
fast = fast.getNext();
slow = slow.getNext();
}
slow.setNext(slow.getNext()
.getNext());
return start.getNext();
}
}

View File

@ -1,30 +0,0 @@
package com.baeldung.junit.runfromjava.listnode;
public class RotateList {
public ListNode rotateRight(ListNode list, int n) {
if (list == null || list.getNext() == null) {
return list;
}
ListNode tmpList = new ListNode(0);
tmpList.setNext(list);
ListNode fast = tmpList;
ListNode slow = tmpList;
int listLength;
for (listLength = 0; fast.getNext() != null; listLength++) {
fast = fast.getNext();
}
for (int j = listLength - n % listLength; j > 0; j--) {
slow = slow.getNext();
}
fast.setNext(tmpList.getNext());
tmpList.setNext(slow.getNext());
slow.setNext(null);
return tmpList.getNext();
}
}

View File

@ -1,33 +0,0 @@
package com.baeldung.junit.runfromjava.listnode;
public class SwapNodes {
public ListNode swapPairs(ListNode listHead) {
ListNode result = new ListNode(0);
result.setNext(listHead);
ListNode current = result;
while (current.getNext() != null && current
.getNext()
.getNext() != null) {
ListNode first = current.getNext();
ListNode second = current
.getNext()
.getNext();
first.setNext(second.getNext());
current.setNext(second);
current
.getNext()
.setNext(first);
current = current
.getNext()
.getNext();
}
return result.getNext();
}
}

View File

@ -109,7 +109,7 @@
<testcontainers.version>1.7.2</testcontainers.version>
<postgresql.version>42.2.2</postgresql.version>
<selenium-remote-driver.version>3.12.0</selenium-remote-driver.version>
<maven-surefire-plugin.version>2.19.1</maven-surefire-plugin.version>
<maven-surefire-plugin.version>2.21.0</maven-surefire-plugin.version>
</properties>
</project>

View File

@ -0,0 +1,24 @@
package com.baeldung.runfromjava;
import org.junit.Test;
import static org.junit.Assert.assertTrue;
public class FirstUnitTest {
@Test
public void whenThis_thenThat() {
assertTrue(true);
}
@Test
public void whenSomething_thenSomething() {
assertTrue(true);
}
@Test
public void whenSomethingElse_thenSomethingElse() {
assertTrue(true);
}
}

View File

@ -1,4 +1,4 @@
package com.baeldung.junit4.runfromjava;
package com.baeldung.runfromjava;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;

View File

@ -1,4 +1,4 @@
package com.baeldung.junit4.runfromjava;
package com.baeldung.runfromjava;
import junit.extensions.ActiveTestSuite;
import junit.extensions.RepeatedTest;
@ -10,7 +10,7 @@ import org.junit.runner.JUnitCore;
import org.junit.runner.Result;
import org.junit.runner.notification.Failure;
public class RunJUnit4Tests {
public class RunJUnit4TestsFromJava {
public static void runOne() {
JUnitCore junit = new JUnitCore();

View File

@ -0,0 +1,18 @@
package com.baeldung.runfromjava;
import org.junit.Test;
import static org.junit.Assert.assertTrue;
public class SecondUnitTest {
@Test
public void whenSomething_thenSomething() {
assertTrue(true);
}
@Test
public void whensomethingElse_thenSomethingElse() {
assertTrue(true);
}
}