Merge branch 'eugenp:master' into master

This commit is contained in:
lsieun
2021-11-02 01:40:07 +08:00
committed by GitHub
199 changed files with 2783 additions and 431 deletions
+1 -2
View File
@@ -37,7 +37,7 @@
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-commons</artifactId>
<version>${junit.platform.version}</version>
<version>${junit-platform.version}</version>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
@@ -53,7 +53,6 @@
<commons-codec.version>1.11</commons-codec.version>
<commons-math3.version>3.6.1</commons-math3.version>
<guava.version>28.1-jre</guava.version>
<junit.platform.version>1.6.0</junit.platform.version>
</properties>
</project>
+1 -2
View File
@@ -22,7 +22,7 @@
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-commons</artifactId>
<version>${junit.platform.version}</version>
<version>${junit-platform.version}</version>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
@@ -46,7 +46,6 @@
<properties>
<guava.version>28.1-jre</guava.version>
<org.assertj.core.version>3.9.0</org.assertj.core.version>
<junit.platform.version>1.6.0</junit.platform.version>
<commons-math3.version>3.6.1</commons-math3.version>
</properties>
+1 -2
View File
@@ -32,7 +32,7 @@
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit-jupiter-api.version}</version>
<version>${junit-jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
@@ -47,7 +47,6 @@
<commons-math3.version>3.6.1</commons-math3.version>
<org.assertj.core.version>3.9.0</org.assertj.core.version>
<commons-codec.version>1.11</commons-codec.version>
<junit-jupiter-api.version>5.3.1</junit-jupiter-api.version>
</properties>
</project>
+1 -2
View File
@@ -33,7 +33,7 @@
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit-jupiter-api.version}</version>
<version>${junit-jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
@@ -48,7 +48,6 @@
<commons-math3.version>3.6.1</commons-math3.version>
<org.assertj.core.version>3.9.0</org.assertj.core.version>
<commons-codec.version>1.11</commons-codec.version>
<junit-jupiter-api.version>5.3.1</junit-jupiter-api.version>
</properties>
</project>
@@ -0,0 +1,18 @@
package com.baeldung.poi.excel.multilinetext;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Row;
public class MultilineText {
public void formatMultilineText(Cell cell, int cellNumber) {
cell.getRow()
.setHeightInPoints(cell.getSheet()
.getDefaultRowHeightInPoints() * 2);
CellStyle cellStyle = cell.getSheet()
.getWorkbook()
.createCellStyle();
cellStyle.setWrapText(true);
cell.setCellStyle(cellStyle);
}
}
@@ -0,0 +1,69 @@
package com.baeldung.poi.excel.multilinetext;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URISyntaxException;
import java.nio.file.Paths;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.DataFormatter;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.junit.Before;
import org.junit.Test;
public class MultilineTextUnitTest {
private static String FILE_NAME = "com/baeldung/poi/excel/multilinetext/MultilineTextTest.xlsx";
private static final String NEW_FILE_NAME = "MultilineTextTest_output.xlsx";
private static final int STRING_ROW_INDEX = 1;
private static final int STRING_CELL_INDEX = 0;
private String fileLocation;
@Before
public void setup() throws IOException, URISyntaxException {
fileLocation = Paths.get(ClassLoader.getSystemResource(FILE_NAME)
.toURI())
.toString();
}
@Test
public void givenMultilineTextCell_whenFormated_thenMultilineTextVisible() throws IOException {
Workbook workbook = new XSSFWorkbook(fileLocation);
Sheet sheet = workbook.getSheetAt(0);
sheet.createRow(STRING_ROW_INDEX);
Row row = sheet.getRow(STRING_ROW_INDEX);
Cell cell = row.createCell(STRING_CELL_INDEX);
cell.setCellValue("Hello \n world!");
MultilineText multilineText = new MultilineText();
multilineText.formatMultilineText(cell, STRING_CELL_INDEX);
FileOutputStream outputStream = new FileOutputStream(NEW_FILE_NAME);
workbook.write(outputStream);
outputStream.close();
File file = new File(NEW_FILE_NAME);
FileInputStream fileInputStream = new FileInputStream(file);
Workbook testWorkbook = new XSSFWorkbook(fileInputStream);
assertTrue(row.getHeightInPoints() == testWorkbook.getSheetAt(0)
.getRow(STRING_ROW_INDEX)
.getHeightInPoints());
DataFormatter formatter = new DataFormatter();
assertEquals("Hello \n world!", formatter.formatCellValue(testWorkbook.getSheetAt(0)
.getRow(STRING_ROW_INDEX)
.getCell(STRING_CELL_INDEX)));
testWorkbook.close();
fileInputStream.close();
file.delete();
workbook.close();
}
}
-4
View File
@@ -39,10 +39,6 @@
<scope>runtime</scope>
</dependency>
<!-- spring-sec -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
+3 -3
View File
@@ -72,9 +72,9 @@
<version>${derby.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>${junit-jupiter.version}</version>
<scope>test</scope>
</dependency>
<!-- the JTA API -->
+7
View File
@@ -62,6 +62,13 @@
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>${json-simple.version}</version>
<exclusions>
<!-- junit4 dependency is excluded as it should to be resolved from junit-vintage-engine included in parent-modules. -->
<exclusion>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
@@ -12,23 +12,17 @@
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-lambda-java-core</artifactId>
<version>1.2.0</version>
<version>${aws-lambda-java-core.version}</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-lambda-java-events</artifactId>
<version>3.1.0</version>
<version>${aws-lambda-java-events.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.11.2</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
<version>${jackson-databind.version}</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
@@ -43,7 +37,7 @@
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.2.16</version>
<version>${postgresql.version}</version>
</dependency>
</dependencies>
@@ -71,6 +65,10 @@
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<hibernate.version>5.4.21.Final</hibernate.version>
<aws-lambda-java-core.version>1.2.0</aws-lambda-java-core.version>
<aws-lambda-java-events.version>3.1.0</aws-lambda-java-events.version>
<jackson-databind.version>2.11.2</jackson-databind.version>
<postgresql.version>42.2.16</postgresql.version>
</properties>
</project>
+26 -15
View File
@@ -12,70 +12,70 @@
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-lambda-java-core</artifactId>
<version>1.2.1</version>
<version>${aws-lambda-java-core.version}</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-lambda-java-events</artifactId>
<version>3.6.0</version>
<version>${aws-lambda-java-events.version}</version>
</dependency>
<dependency>
<groupId>uk.org.webcompere</groupId>
<artifactId>lightweight-config</artifactId>
<version>1.1.0</version>
<version>${lightweight-config.version}</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-lambda-java-log4j2</artifactId>
<version>1.2.0</version>
<version>${aws-lambda-java-log4j2.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>2.13.2</version>
<version>${log4j-slf4j-impl.version}</version>
</dependency>
<dependency>
<groupId>io.github.openfeign</groupId>
<artifactId>feign-core</artifactId>
<version>11.2</version>
<version>${feign-core.version}</version>
</dependency>
<dependency>
<groupId>io.github.openfeign</groupId>
<artifactId>feign-slf4j</artifactId>
<version>11.2</version>
<version>${feign-core.version}</version>
</dependency>
<dependency>
<groupId>io.github.openfeign</groupId>
<artifactId>feign-gson</artifactId>
<version>11.2</version>
<version>${feign-core.version}</version>
</dependency>
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<version>5.0.1</version>
<version>${guice.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.1</version>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>${junit-jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>uk.org.webcompere</groupId>
<artifactId>system-stubs-junit4</artifactId>
<version>1.2.0</version>
<version>${system-stubs-junit4.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>3.3.0</version>
<version>${mockito-core.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.19.0</version>
<version>${assertj-core.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
@@ -103,6 +103,17 @@
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<aws-lambda-java-core.version>1.2.1</aws-lambda-java-core.version>
<aws-lambda-java-events.version>3.6.0</aws-lambda-java-events.version>
<lightweight-config.version>1.1.0</lightweight-config.version>
<aws-lambda-java-log4j2.version>1.2.0</aws-lambda-java-log4j2.version>
<log4j-slf4j-impl.version>2.13.2</log4j-slf4j-impl.version>
<feign-core.version>11.2</feign-core.version>
<guice.version>5.0.1</guice.version>
<system-stubs-junit4.version>1.2.0</system-stubs-junit4.version>
<mockito-core.version>3.3.0</mockito-core.version>
<assertj-core.version>3.19.0</assertj-core.version>
<junit-jupiter.version>5.8.1</junit-jupiter.version>
</properties>
</project>
+1
View File
@@ -70,6 +70,7 @@
<artifactId>maven-failsafe-plugin</artifactId>
<version>${maven-failsafe-plugin.version}</version>
<configuration>
<skipITs>true</skipITs>
<includes>
<include>**/*LiveTest.java</include>
</includes>
+2 -3
View File
@@ -33,7 +33,7 @@
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-runner</artifactId>
<version>${junit.platform.version}</version>
<version>${junit-platform.version}</version>
<scope>test</scope>
</dependency>
<dependency>
@@ -95,7 +95,7 @@
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-surefire-provider</artifactId>
<version>${junit.platform.version}</version>
<version>${junit-platform-surefire-provider.version}</version>
</dependency>
</dependencies>
<executions>
@@ -165,7 +165,6 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<junit.platform.version>1.0.0</junit.platform.version>
<hsqldb.version>2.4.0</hsqldb.version>
<spock-core.version>1.1-groovy-2.4</spock-core.version>
<commons-lang3.version>3.9</commons-lang3.version>
+2 -3
View File
@@ -34,7 +34,7 @@
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-runner</artifactId>
<version>${junit.platform.version}</version>
<version>${junit-platform.version}</version>
<scope>test</scope>
</dependency>
<dependency>
@@ -94,7 +94,7 @@
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-surefire-provider</artifactId>
<version>${junit.platform.version}</version>
<version>${junit-platform-surefire-provider.version}</version>
</dependency>
</dependencies>
<executions>
@@ -162,7 +162,6 @@
</repositories>
<properties>
<junit.platform.version>1.0.0</junit.platform.version>
<hsqldb.version>2.4.0</hsqldb.version>
<spock-core.version>1.1-groovy-2.4</spock-core.version>
<groovy-wslite.version>1.1.3</groovy-wslite.version>
+2 -3
View File
@@ -39,7 +39,7 @@
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-runner</artifactId>
<version>${junit.platform.version}</version>
<version>${junit-platform.version}</version>
<scope>test</scope>
</dependency>
<dependency>
@@ -80,7 +80,7 @@
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-surefire-provider</artifactId>
<version>${junit.platform.version}</version>
<version>${junit-platform-surefire-provider.version}</version>
</dependency>
</dependencies>
<executions>
@@ -119,7 +119,6 @@
</repositories>
<properties>
<junit.platform.version>1.0.0</junit.platform.version>
<groovy.version>2.5.6</groovy.version>
<groovy-all.version>2.5.6</groovy-all.version>
<groovy-sql.version>2.5.6</groovy-sql.version>
+2 -3
View File
@@ -39,7 +39,7 @@
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-runner</artifactId>
<version>${junit.platform.version}</version>
<version>${junit-platform.version}</version>
<scope>test</scope>
</dependency>
<dependency>
@@ -80,7 +80,7 @@
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-surefire-provider</artifactId>
<version>${junit.platform.version}</version>
<version>${junit-platform-surefire-provider.version}</version>
</dependency>
</dependencies>
<executions>
@@ -109,7 +109,6 @@
</repositories>
<properties>
<junit.platform.version>1.0.0</junit.platform.version>
<groovy.version>2.5.6</groovy.version>
<groovy-all.version>2.5.6</groovy-all.version>
<groovy-sql.version>2.5.6</groovy-sql.version>
+2 -3
View File
@@ -39,7 +39,7 @@
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-runner</artifactId>
<version>${junit.platform.version}</version>
<version>${junit-platform.version}</version>
<scope>test</scope>
</dependency>
<dependency>
@@ -80,7 +80,7 @@
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-surefire-provider</artifactId>
<version>${junit.platform.version}</version>
<version>${junit-platform-surefire-provider.version}</version>
</dependency>
</dependencies>
<executions>
@@ -109,7 +109,6 @@
</repositories>
<properties>
<junit.platform.version>1.0.0</junit.platform.version>
<groovy.version>2.5.6</groovy.version>
<groovy-all.version>2.5.6</groovy-all.version>
<groovy-sql.version>2.5.6</groovy-sql.version>
+3 -4
View File
@@ -35,19 +35,19 @@
<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-params</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>
<version>${junit-jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
@@ -106,7 +106,6 @@
<maven.compiler.source.version>11</maven.compiler.source.version>
<maven.compiler.target.version>11</maven.compiler.target.version>
<guava.version>29.0-jre</guava.version>
<junit.jupiter.version>5.7.0</junit.jupiter.version>
<assertj.version>3.17.2</assertj.version>
<mockserver.version>5.11.1</mockserver.version>
<commons-lang3.version>3.12.0</commons-lang3.version>
+3
View File
@@ -0,0 +1,3 @@
### Relevant articles:
- [Pattern Matching for Switch](https://www.baeldung.com/java-switch-pattern-matching)
+81
View File
@@ -0,0 +1,81 @@
<?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>core-java-17</artifactId>
<version>0.1.0-SNAPSHOT</version>
<name>core-java-17</name>
<packaging>jar</packaging>
<url>http://maven.apache.org</url>
<parent>
<groupId>com.baeldung</groupId>
<artifactId>parent-modules</artifactId>
<version>1.0.0-SNAPSHOT</version>
<relativePath>../../</relativePath>
</parent>
<dependencies>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>${assertj.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<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>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<configuration>
<release>${maven.compiler.release}</release>
<compilerArgs>--enable-preview</compilerArgs>
<source>${maven.compiler.source.version}</source>
<target>${maven.compiler.target.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${surefire.plugin.version}</version>
<configuration>
<argLine>--enable-preview</argLine>
<forkCount>1</forkCount>
</configuration>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-api</artifactId>
<version>${surefire.plugin.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
<properties>
<maven.compiler.source.version>17</maven.compiler.source.version>
<maven.compiler.target.version>17</maven.compiler.target.version>
<maven.compiler.release>17</maven.compiler.release>
<maven-compiler-plugin.version>3.8.1</maven-compiler-plugin.version>
<surefire.plugin.version>3.0.0-M5</surefire.plugin.version>
<assertj.version>3.17.2</assertj.version>
</properties>
</project>
@@ -0,0 +1,25 @@
package com.baeldung.switchpatterns;
public class GuardedPatterns {
static double getDoubleValueUsingIf(Object o) {
return switch (o) {
case String s -> {
if (s.length() > 0) {
yield Double.parseDouble(s);
} else {
yield 0d;
}
}
default -> 0d;
};
}
static double getDoubleValueUsingGuardedPatterns(Object o) {
return switch (o) {
case String s && s.length() > 0 -> Double.parseDouble(s);
default -> 0d;
};
}
}
@@ -0,0 +1,20 @@
package com.baeldung.switchpatterns;
public class HandlingNullValues {
static double getDoubleUsingSwitchNullCase(Object o) {
return switch (o) {
case String s -> Double.parseDouble(s);
case null -> 0d;
default -> 0d;
};
}
static double getDoubleUsingSwitchTotalType(Object o) {
return switch (o) {
case String s -> Double.parseDouble(s);
case Object ob -> 0d;
};
}
}
@@ -0,0 +1,29 @@
package com.baeldung.switchpatterns;
public class ParenthesizedPatterns {
static double getDoubleValueUsingIf(Object o) {
return switch (o) {
case String s -> {
if (s.length() > 0) {
if (s.contains("#") || s.contains("@")) {
yield 0d;
} else {
yield Double.parseDouble(s);
}
} else {
yield 0d;
}
}
default -> 0d;
};
}
static double getDoubleValueUsingParenthesizedPatterns(Object o) {
return switch (o) {
case String s && s.length() > 0 && !(s.contains("#") || s.contains("@")) -> Double.parseDouble(s);
default -> 0d;
};
}
}
@@ -0,0 +1,14 @@
package com.baeldung.switchpatterns;
public class PatternMatching {
public static void main(String[] args) {
Object o = args[0];
if (o instanceof String s) {
System.out.printf("Object is a string %s", s);
} else if(o instanceof Number n) {
System.out.printf("Object is a number %n", n);
}
}
}
@@ -0,0 +1,14 @@
package com.baeldung.switchpatterns;
public class SwitchStatement {
public static void main(String[] args) {
final String b = "B";
switch (args[0]) {
case "A" -> System.out.println("Parameter is A");
case b -> System.out.println("Parameter is b");
default -> System.out.println("Parameter is unknown");
};
}
}
@@ -0,0 +1,30 @@
package com.baeldung.switchpatterns;
public class TypePatterns {
static double getDoubleUsingIf(Object o) {
double result;
if (o instanceof Integer) {
result = ((Integer) o).doubleValue();
} else if (o instanceof Float) {
result = ((Float) o).doubleValue();
} else if (o instanceof String) {
result = Double.parseDouble(((String) o));
} else {
result = 0d;
}
return result;
}
static double getDoubleUsingSwitch(Object o) {
return switch (o) {
case Integer i -> i.doubleValue();
case Float f -> f.doubleValue();
case String s -> Double.parseDouble(s);
default -> 0d;
};
}
}
@@ -0,0 +1,30 @@
package com.baeldung.switchpatterns;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static com.baeldung.switchpatterns.GuardedPatterns.*;
class GuardedPatternsUnitTest {
@Test
void givenIfImplementation_whenUsingEmptyString_thenDoubleIsReturned() {
assertEquals(0d, getDoubleValueUsingIf(""));
}
@Test
void givenIfImplementation_whenUsingNonEmptyString_thenDoubleIsReturned() {
assertEquals(10d, getDoubleValueUsingIf("10"));
}
@Test
void givenPatternsImplementation_whenUsingEmptyString_thenDoubleIsReturned() {
assertEquals(0d, getDoubleValueUsingGuardedPatterns(""));
}
@Test
void givenPatternsImplementation_whenUsingNonEmptyString_thenDoubleIsReturned() {
assertEquals(10d, getDoubleValueUsingGuardedPatterns("10"));
}
}
@@ -0,0 +1,30 @@
package com.baeldung.switchpatterns;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static com.baeldung.switchpatterns.HandlingNullValues.*;
class HandlingNullValuesUnitTest {
@Test
void givenNullCaseInSwitch_whenUsingStringAsArgument_thenDoubleIsReturned() {
assertEquals(10d, getDoubleUsingSwitchNullCase("10"));
}
@Test
void givenTotalTypeInSwitch_whenUsingNullArgument_thenDoubleIsReturned() {
assertEquals(0d, getDoubleUsingSwitchNullCase(null));
}
@Test
void givenTotalTypeInSwitch_whenUsingStringAsArgument_thenDoubleIsReturned() {
assertEquals(10d, getDoubleUsingSwitchTotalType("10"));
}
@Test
void givenNullCaseInSwitch_whenUsingNullArgument_thenDoubleIsReturned() {
assertEquals(0d, getDoubleUsingSwitchTotalType(null));
}
}
@@ -0,0 +1,40 @@
package com.baeldung.switchpatterns;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static com.baeldung.switchpatterns.ParenthesizedPatterns.*;
class ParenthesizedPatternsUnitTest {
@Test
void givenIfImplementation_whenUsingEmptyString_thenDoubleIsReturned() {
assertEquals(0d, getDoubleValueUsingIf(""));
}
@Test
void givenIfImplementation_whenUsingNonEmptyString_thenDoubleIsReturned() {
assertEquals(10d, getDoubleValueUsingIf("10"));
}
@Test
void givenIfImplementation_whenStringContainsSpecialChar_thenDoubleIsReturned() {
assertEquals(0d, getDoubleValueUsingIf("@10"));
}
@Test
void givenPatternsImplementation_whenUsingEmptyString_thenDoubleIsReturned() {
assertEquals(0d, getDoubleValueUsingParenthesizedPatterns(""));
}
@Test
void givenPatternsImplementation_whenUsingNonEmptyString_thenDoubleIsReturned() {
assertEquals(10d, getDoubleValueUsingParenthesizedPatterns("10"));
}
@Test
void givenPatternsImplementation_whenStringContainsSpecialChar_thenDoubleIsReturned() {
assertEquals(0d, getDoubleValueUsingParenthesizedPatterns("@10"));
}
}
@@ -0,0 +1,49 @@
package com.baeldung.switchpatterns;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static com.baeldung.switchpatterns.TypePatterns.*;
class TypePatternsUnitTest {
@Test
void givenIfImplementation_whenUsingIntegerAsArgument_thenDoubleIsReturned() {
assertEquals(10d, getDoubleUsingIf(10));
}
@Test
void givenIfImplementation_whenUsingDoubleAsArgument_thenDoubleIsReturned() {
assertEquals(10d, getDoubleUsingIf(10.0f));
}
@Test
void givenIfImplementation_whenUsingStringAsArgument_thenDoubleIsReturned() {
assertEquals(10d, getDoubleUsingIf("10"));
}
@Test
void givenIfImplementation_whenUsingCharAsArgument_thenDoubleIsReturned() {
assertEquals(0d, getDoubleUsingIf('c'));
}
@Test
void givenSwitchImplementation_whenUsingIntegerAsArgument_thenDoubleIsReturned() {
assertEquals(10d, getDoubleUsingSwitch(10));
}
@Test
void givenSwitchImplementation_whenUsingDoubleAsArgument_thenDoubleIsReturned() {
assertEquals(10d, getDoubleUsingSwitch(10.0f));
}
@Test
void givenSwitchImplementation_whenUsingStringAsArgument_thenDoubleIsReturned() {
assertEquals(10d, getDoubleUsingSwitch("10"));
}
@Test
void givenSwitchImplementation_whenUsingCharAsArgument_thenDoubleIsReturned() {
assertEquals(0d, getDoubleUsingSwitch('c'));
}
}
@@ -40,7 +40,7 @@
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-runner</artifactId>
<version>${junit.platform.version}</version>
<version>${junit-platform.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
@@ -70,7 +70,6 @@
<properties>
<!-- testing -->
<assertj.version>3.10.0</assertj.version>
<junit.platform.version>1.2.0</junit.platform.version>
<awaitility.version>1.7.0</awaitility.version>
<maven.compiler.source>1.9</maven.compiler.source>
<maven.compiler.target>1.9</maven.compiler.target>
@@ -29,7 +29,7 @@
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-runner</artifactId>
<version>${junit.platform.version}</version>
<version>${junit-platform.version}</version>
<scope>test</scope>
</dependency>
<dependency>
@@ -158,7 +158,6 @@
<rxjava.version>3.0.0</rxjava.version>
<!-- testing -->
<assertj.version>3.10.0</assertj.version>
<junit.platform.version>1.2.0</junit.platform.version>
<awaitility.version>4.0.2</awaitility.version>
<maven.compiler.source>1.9</maven.compiler.source>
<maven.compiler.target>1.9</maven.compiler.target>
+1 -2
View File
@@ -35,7 +35,7 @@
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-runner</artifactId>
<version>${junit.platform.version}</version>
<version>${junit-platform.version}</version>
<scope>test</scope>
</dependency>
<dependency>
@@ -80,7 +80,6 @@
<properties>
<!-- testing -->
<assertj.version>3.10.0</assertj.version>
<junit.platform.version>1.2.0</junit.platform.version>
<awaitility.version>1.7.0</awaitility.version>
<maven.compiler.source>1.9</maven.compiler.source>
<maven.compiler.target>1.9</maven.compiler.target>
@@ -5,3 +5,4 @@ This module contains articles about arrays conversion in Java
## Relevant Articles
- [Convert a Float to a Byte Array in Java](https://www.baeldung.com/java-convert-float-to-byte-array)
- [Converting Between Stream and Array in Java](https://www.baeldung.com/java-stream-to-array)
- [Convert a Byte Array to a Numeric Representation in Java](https://www.baeldung.com/java-byte-array-to-number)
@@ -43,7 +43,7 @@
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-runner</artifactId>
<version>${junit.platform.version}</version>
<version>${junit-platform.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
@@ -52,7 +52,6 @@
<eclipse.collections.version>7.1.0</eclipse.collections.version>
<commons-collections4.version>4.1</commons-collections4.version>
<assertj.version>3.11.1</assertj.version>
<junit.platform.version>1.2.0</junit.platform.version>
<commons-exec.version>1.3</commons-exec.version>
</properties>
@@ -16,9 +16,8 @@
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
@@ -96,7 +95,6 @@
</build>
<properties>
<junit.version>4.13</junit.version>
<threadweaver.version>0.2</threadweaver.version>
<tempus-fugit.version>1.1</tempus-fugit.version>
<multithreadedtc.version>1.01</multithreadedtc.version>
+3 -4
View File
@@ -18,19 +18,19 @@
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>${jupiter.version}</version>
<version>${junit-jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${jupiter.version}</version>
<version>${junit-jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${jupiter.version}</version>
<version>${junit-jupiter.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
@@ -76,7 +76,6 @@
<properties>
<spring.version>5.0.9.RELEASE</spring.version>
<h2.version>1.4.199</h2.version>
<jupiter.version>5.5.1</jupiter.version>
<source.version>1.8</source.version>
<target.version>1.8</target.version>
</properties>
+2 -3
View File
@@ -16,9 +16,8 @@
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
+2 -3
View File
@@ -17,9 +17,8 @@
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
@@ -36,9 +36,8 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
+1 -2
View File
@@ -19,7 +19,7 @@
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit-jupiter-engine.version}</version>
<version>${junit-jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
@@ -94,7 +94,6 @@
<guava.version>25.1-jre</guava.version>
<unix4j.version>0.4</unix4j.version>
<grep4j.version>1.8.7</grep4j.version>
<junit-jupiter-engine.version>5.7.2</junit-jupiter-engine.version>
</properties>
</project>
@@ -1,5 +1,6 @@
package com.baeldung.example.soundapi;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Assertions;
@@ -37,6 +38,7 @@ public class AppUnitTest {
}
@Test
@Disabled
public void Given_TargetLineDataObject_When_Run_Then_GeneratesOutputStream() {
soundRecorder.setFormat(af);
@@ -52,6 +54,7 @@ public class AppUnitTest {
}
@Test
@Disabled
public void Given_AudioInputStream_When_NotNull_Then_SaveToWavFile() {
soundRecorder.setFormat(af);
soundRecorder.build(af);
@@ -31,11 +31,9 @@
<version>${log4j.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<scope>test</scope>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
@@ -10,3 +10,4 @@ This module contains articles about string APIs.
- [CharSequence vs. String in Java](https://www.baeldung.com/java-char-sequence-string)
- [StringBuilder vs StringBuffer in Java](https://www.baeldung.com/java-string-builder-string-buffer)
- [Generate a Secure Random Password in Java](https://www.baeldung.com/java-generate-secure-password)
- [Getting a Character by Index From a String in Java](https://www.baeldung.com/java-character-at-position)
@@ -0,0 +1,29 @@
package com.baeldung.stringapi;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
public class StringCharAtUnitTest {
@Test
public void whenCallCharAt_thenSuccess() {
String sample = "abcdefg";
assertEquals('d', sample.charAt(3));
}
@Test()
public void whenCharAtNonExist_thenIndexOutOfBoundsExceptionThrown() {
String sample = "abcdefg";
assertThrows(IndexOutOfBoundsException.class, () -> sample.charAt(-1));
assertThrows(IndexOutOfBoundsException.class, () -> sample.charAt(sample.length()));
}
@Test
public void whenCallCharAt_thenReturnString() {
String sample = "abcdefg";
assertEquals("a", Character.toString(sample.charAt(0)));
assertEquals("a", String.valueOf(sample.charAt(0)));
}
}
@@ -21,9 +21,8 @@
<version>${guava.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
@@ -6,3 +6,4 @@
- [Split a String in Java and Keep the Delimiters](https://www.baeldung.com/java-split-string-keep-delimiters)
- [Validate String as Filename in Java](https://www.baeldung.com/java-validate-filename)
- [Count Spaces in a Java String](https://www.baeldung.com/java-string-count-spaces)
- [Remove Accents and Diacritics From a String in Java](https://www.baeldung.com/java-remove-accents-from-text)
@@ -52,6 +52,11 @@
<artifactId>semver4j</artifactId>
<version>${semver4j.version}</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${guava.version}</version>
</dependency>
</dependencies>
<build>
@@ -80,6 +85,7 @@
<assertj.version>3.6.1</assertj.version>
<spring-core.version>5.3.9</spring-core.version>
<apache-commons-lang3.version>3.12.0</apache-commons-lang3.version>
<guava.version>31.0.1-jre</guava.version>
<maven-artifact.version>3.6.3</maven-artifact.version>
<gradle-core.version>6.1.1</gradle-core.version>
<jackson-core.version>2.11.1</jackson-core.version>
@@ -0,0 +1,66 @@
package com.baeldung.multipledelimiterssplit;
import com.google.common.base.CharMatcher;
import com.google.common.base.Splitter;
import com.google.common.collect.Iterators;
import org.apache.commons.lang3.StringUtils;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import java.util.Arrays;
import java.util.regex.Pattern;
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class MultipleDelimitersSplitUnitTest {
@Test
public void givenString_whenSplittingByMultipleDelimitersWithRegEx_thenStringSplit() {
String example = "Mary;Thomas:Jane-Kate";
String[] names = example.split(";|:|-");
String[] expectedNames = new String[]{"Mary", "Thomas", "Jane", "Kate"};
Assertions.assertEquals(4, names.length);
Assertions.assertArrayEquals(expectedNames, names);
}
@Test
public void givenString_whenSplittingByWithCharMatcherAndOnMethod_thenStringSplit() {
String example = "Mary;Thomas:Jane-Kate";
String[] expectedArray = new String[]{"Mary", "Thomas", "Jane", "Kate"};
Iterable<String> expected = Arrays.asList(expectedArray);
Iterable<String> names = Splitter.on(CharMatcher.anyOf(";:-")).split(example);
Assertions.assertEquals(4, Iterators.size(names.iterator()));
Assertions.assertIterableEquals(expected, names);
}
@Test
public void givenString_whenSplittingByWithRegexAndOnPatternMethod_thenStringSplit() {
String example = "Mary;Thomas:Jane-Kate";
String[] expectedArray = new String[]{"Mary", "Thomas", "Jane", "Kate"};
Iterable<String> expected = Arrays.asList(expectedArray);
Iterable<String> names = Splitter.on(Pattern.compile(";|:|-")).split(example);
Assertions.assertEquals(4, Iterators.size(names.iterator()));
Assertions.assertIterableEquals(expected, names);
}
@Test
public void givenString_whenSplittingByMultipleDelimitersWithGuava_thenStringSplit() {
String example = "Mary;Thomas:Jane-Kate";
String[] expectedArray = new String[]{"Mary", "Thomas", "Jane", "Kate"};
Iterable<String> expected = Arrays.asList(expectedArray);
Iterable<String> names = Splitter.onPattern(";|:|-").split(example);
Assertions.assertEquals(4, Iterators.size(names.iterator()));
Assertions.assertIterableEquals(expected, names);
}
@Test
public void givenString_whenSplittingByMultipleDelimitersWithApache_thenStringSplit() {
String example = "Mary;Thomas:Jane-Kate";
String[] expectedNames = new String[]{"Mary", "Thomas", "Jane", "Kate"};
String[] names = StringUtils.split(example, ";:-");
Assertions.assertEquals(4, names.length);
Assertions.assertArrayEquals(expectedNames, names);
}
}
@@ -25,12 +25,6 @@
<dependencyManagement>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
-1
View File
@@ -136,7 +136,6 @@
<properties>
<maven-surefire-plugin.version>2.22.2</maven-surefire-plugin.version>
<junit-jupiter.version>5.6.2</junit-jupiter.version>
</properties>
</project>
-1
View File
@@ -81,7 +81,6 @@
<appmodules.version>1.0</appmodules.version>
<junit-jupiter.version>5.6.2</junit-jupiter.version>
<assertj-core.version>3.12.2</assertj-core.version>
</properties>
+1
View File
@@ -4,3 +4,4 @@
- [Reusing Docker Layers with Spring Boot](https://www.baeldung.com/docker-layers-spring-boot)
- [Running Spring Boot with PostgreSQL in Docker Compose](https://www.baeldung.com/spring-boot-postgresql-docker)
- [How To Configure Java Heap Size Inside a Docker Container](https://www.baeldung.com/ops/docker-jvm-heap-size)
- [Dockerfile Strategies for Git](https://www.baeldung.com/ops/dockerfile-git-strategies)
+12 -5
View File
@@ -1,7 +1,7 @@
<?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">
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.ethereum</groupId>
<artifactId>ethereum</artifactId>
@@ -112,6 +112,13 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<version>${spring.boot.version}</version>
<exclusions>
<!-- junit4 dependency is excluded as it should to be resolved from junit-vintage-engine included in parent-modules. -->
<exclusion>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
@@ -138,9 +145,9 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>${junit-jupiter.version}</version>
<scope>test</scope>
<exclusions>
<exclusion>
+3 -3
View File
@@ -45,9 +45,9 @@
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>${junit-jupiter.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
+3 -3
View File
@@ -38,9 +38,9 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>${junit-jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
@@ -70,7 +70,6 @@
<!-- testing -->
<assertj.version>3.6.1</assertj.version>
<java-hamcrest.version>2.0.0.0</java-hamcrest.version>
<junit-jupiter.version>5.6.2</junit-jupiter.version>
</properties>
</project>
@@ -40,7 +40,4 @@
</resources>
</build>
<properties>
<junit-jupiter.version>5.6.2</junit-jupiter.version>
</properties>
</project>
@@ -43,7 +43,6 @@
<properties>
<!-- testing -->
<assertj.version>3.6.1</assertj.version>
<junit-jupiter.version>5.6.2</junit-jupiter.version>
</properties>
</project>
-1
View File
@@ -76,7 +76,6 @@
<!-- testing -->
<assertj.version>3.6.1</assertj.version>
<java-hamcrest.version>2.0.0.0</java-hamcrest.version>
<junit-jupiter.version>5.6.2</junit-jupiter.version>
</properties>
</project>
-4
View File
@@ -39,8 +39,4 @@
</resources>
</build>
<properties>
<junit-jupiter.version>5.6.2</junit-jupiter.version>
</properties>
</project>
-1
View File
@@ -53,7 +53,6 @@
<properties>
<!-- testing -->
<junit-jupiter.version>5.6.2</junit-jupiter.version>
<assertj.version>3.6.1</assertj.version>
</properties>
-1
View File
@@ -50,7 +50,6 @@
<properties>
<maven-surefire-plugin.version>2.22.2</maven-surefire-plugin.version>
<junit-jupiter.version>5.6.2</junit-jupiter.version>
<guava.version>29.0-jre</guava.version>
</properties>
+2 -4
View File
@@ -19,7 +19,7 @@
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-runner</artifactId>
<version>${junit.platform.version}</version>
<version>${junit-platform.version}</version>
<scope>test</scope>
</dependency>
<dependency>
@@ -160,7 +160,7 @@
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-surefire-provider</artifactId>
<version>${junit.platform.version}</version>
<version>${junit-platform-surefire-provider.version}</version>
</dependency>
</dependencies>
<executions>
@@ -191,8 +191,6 @@
<kotlinx.version>0.22.5</kotlinx.version>
<mockito-kotlin.version>1.5.0</mockito-kotlin.version>
<commons-math3.version>3.6.1</commons-math3.version>
<junit.platform.version>1.0.0</junit.platform.version>
<junit.vintage.version>5.2.0</junit.vintage.version>
<assertj.version>3.10.0</assertj.version>
<maven-compiler-plugin.version>3.7.0</maven-compiler-plugin.version>
<spek.api.version>1.1.5</spek.api.version>
+2 -5
View File
@@ -18,12 +18,12 @@
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>${junit.jupiter.version}</version>
<version>${junit-jupiter.version}</version>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>${junit-vintage.version}</version>
<version>${junit-jupiter.version}</version>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
@@ -59,9 +59,6 @@
</build>
<properties>
<junit.jupiter.version>5.0.0-M4</junit.jupiter.version>
<junit-vintage.version>4.12.0-M4</junit-vintage.version>
<log4j-core.version>2.8.2</log4j-core.version>
<junit-platform-surefire-provider.version>1.0.0-M4</junit-platform-surefire-provider.version>
</properties>
</project>
@@ -1,9 +1,9 @@
package com.baeldung.jackson.advancedannotations;
import com.fasterxml.jackson.databind.PropertyNamingStrategy;
import com.fasterxml.jackson.databind.PropertyNamingStrategies;
import com.fasterxml.jackson.databind.annotation.JsonNaming;
@JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class)
@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class)
public class NamingBean {
private int id;
private String beanName;
-4
View File
@@ -49,8 +49,4 @@
</dependency>
</dependencies>
<properties>
<junit-jupiter.version>5.6.2</junit-jupiter.version>
</properties>
</project>
-1
View File
@@ -54,7 +54,6 @@
<properties>
<!-- testing -->
<junit-jupiter.version>5.6.2</junit-jupiter.version>
<assertj.version>3.11.0</assertj.version>
</properties>
+3 -3
View File
@@ -33,9 +33,9 @@
<version>${modelmapper.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>${junit-jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
+1 -1
View File
@@ -39,7 +39,7 @@
</build>
<properties>
<commons-collections4.version>4.1</commons-collections4.version>
<commons-collections4.version>4.4</commons-collections4.version>
</properties>
</project>
+1
View File
@@ -5,3 +5,4 @@
- [Using the Map.Entry Java Class](https://www.baeldung.com/java-map-entry)
- [Optimizing HashMaps Performance](https://www.baeldung.com/java-hashmap-optimize-performance)
- [Update the Value Associated With a Key in a HashMap](https://www.baeldung.com/java-hashmap-update-value-by-key)
- [Java Map keySet() vs. entrySet() vs. values() Methods](https://www.baeldung.com/java-map-entries-methods)
@@ -0,0 +1,30 @@
package com.baeldung.map.keysetValuesEntrySet;
import org.junit.Test;
import java.util.AbstractMap.SimpleEntry;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
public class EntrySetExampleUnitTest {
@Test
public void givenHashMap_whenEntrySetApplied_thenShouldReturnSetOfEntries() {
Map<String, Integer> map = new HashMap<>();
map.put("one", 1);
map.put("two", 2);
Set<Map.Entry<String, Integer>> actualValues = map.entrySet();
assertEquals(2, actualValues.size());
assertTrue(actualValues.contains(new SimpleEntry<>("one", 1)));
assertTrue(actualValues.contains(new SimpleEntry<>("two", 2)));
}
}
@@ -0,0 +1,27 @@
package com.baeldung.map.keysetValuesEntrySet;
import org.junit.Test;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
public class KeySetExampleUnitTest {
@Test
public void givenHashMap_whenKeySetApplied_thenShouldReturnSetOfKeys() {
Map<String, Integer> map = new HashMap<>();
map.put("one", 1);
map.put("two", 2);
Set<String> actualValues = map.keySet();
assertEquals(2, actualValues.size());
assertTrue(actualValues.contains("one"));
assertTrue(actualValues.contains("two"));
}
}
@@ -0,0 +1,27 @@
package com.baeldung.map.keysetValuesEntrySet;
import org.junit.Test;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
public class ValuesExampleUnitTest {
@Test
public void givenHashMap_whenValuesApplied_thenShouldReturnCollectionOfValues() {
Map<String, Integer> map = new HashMap<>();
map.put("one", 1);
map.put("two", 2);
Collection<Integer> actualValues = map.values();
assertEquals(2, actualValues.size());
assertTrue(actualValues.contains(1));
assertTrue(actualValues.contains(2));
}
}
+4 -4
View File
@@ -8,8 +8,8 @@
<version>0.0.1-SNAPSHOT</version>
<parent>
<artifactId>parent-modules</artifactId>
<groupId>com.baeldung</groupId>
<artifactId>parent-modules</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
@@ -25,9 +25,9 @@
<version>${jsoniter.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>${junit-jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
+6
View File
@@ -0,0 +1,6 @@
## JUnit5
This module contains articles about the JUnit 5
### Relevant Articles:
+36
View File
@@ -0,0 +1,36 @@
<?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</artifactId>
<name>junit5</name>
<parent>
<artifactId>parent-modules</artifactId>
<groupId>com.baeldung</groupId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
@@ -0,0 +1,21 @@
package com.baeldung.junit5;
import org.junit.jupiter.api.Test;
public class A_UnitTest {
@Test
public void first() throws Exception{
System.out.println("Test A first() start => " + Thread.currentThread().getName());
Thread.sleep(500);
System.out.println("Test A first() end => " + Thread.currentThread().getName());
}
@Test
public void second() throws Exception{
System.out.println("Test A second() start => " + Thread.currentThread().getName());
Thread.sleep(500);
System.out.println("Test A second() end => " + Thread.currentThread().getName());
}
}
@@ -0,0 +1,23 @@
package com.baeldung.junit5;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.parallel.Execution;
import org.junit.jupiter.api.parallel.ExecutionMode;
public class B_UnitTest {
@Test
public void first() throws Exception{
System.out.println("Test B first() start => " + Thread.currentThread().getName());
Thread.sleep(500);
System.out.println("Test B first() end => " + Thread.currentThread().getName());
}
@Test
public void second() throws Exception{
System.out.println("Test B second() start => " + Thread.currentThread().getName());
Thread.sleep(500);
System.out.println("Test B second() end => " + Thread.currentThread().getName());
}
}
@@ -0,0 +1,45 @@
package com.baeldung.junit5;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.parallel.ResourceLock;
import java.util.ArrayList;
import java.util.List;
public class C_UnitTest {
private List<String> resources;
@BeforeEach
void before() {
resources = new ArrayList<>();
resources.add("test");
}
@AfterEach
void after() {
resources.clear();
}
@Test
@ResourceLock(value = "resources")
public void first() throws Exception {
System.out.println("Test C first() start => " + Thread.currentThread().getName());
resources.add("first");
System.out.println(resources);
Thread.sleep(500);
System.out.println("Test C first() end => " + Thread.currentThread().getName());
}
@Test
@ResourceLock(value = "resources")
public void second() throws Exception {
System.out.println("Test C second() start => " + Thread.currentThread().getName());
resources.add("second");
System.out.println(resources);
Thread.sleep(500);
System.out.println("Test C second() end => " + Thread.currentThread().getName());
}
}
@@ -0,0 +1,4 @@
junit.jupiter.execution.parallel.enabled = true
junit.jupiter.execution.parallel.config.strategy=dynamic
junit.jupiter.execution.parallel.mode.default = concurrent
junit.jupiter.execution.parallel.mode.classes.default = concurrent
+1 -1
View File
@@ -3,7 +3,7 @@
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>ksqldb-app</artifactId>
<artifactId>ksqldb</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>ksqldb</name>
+1 -1
View File
@@ -20,7 +20,7 @@
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.3</version>
<version>${logback.version}</version>
</dependency>
</dependencies>
+7
View File
@@ -53,6 +53,13 @@
<groupId>org.jbpm</groupId>
<artifactId>jbpm-test</artifactId>
<version>${jbpm.version}</version>
<exclusions>
<!-- junit4 dependency is excluded as it should to be resolved from junit-vintage-engine included in parent-modules. -->
<exclusion>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>info.picocli</groupId>
+3 -3
View File
@@ -15,9 +15,9 @@
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>${junit-jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
+5
View File
@@ -94,6 +94,11 @@
<artifactId>jackson-databind</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
+23 -5
View File
@@ -15,11 +15,16 @@
<artifactId>fastutil</artifactId>
<version>${fastutil.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/junit/junit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>${junit-jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>${junit-jupiter.version}</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.openjdk.jmh/jmh-core -->
@@ -43,14 +48,27 @@
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
</plugin>
</plugins>
</pluginManagement>
</build>
<properties>
<fastutil.version>8.2.2</fastutil.version>
<junit.version>4.12</junit.version>
<eclipse-collections.version>10.0.0</eclipse-collections.version>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<jmh-core.version>1.28</jmh-core.version>
<jmh-generator.version>1.28</jmh-generator.version>
<junit-jupiter.version>5.8.1</junit-jupiter.version>
<maven-surefire-plugin.version>2.22.2</maven-surefire-plugin.version>
</properties>
</project>
+2 -2
View File
@@ -49,8 +49,8 @@
<version>${bouncycastle.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
+3 -3
View File
@@ -62,9 +62,9 @@
<version>${netty.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>${junit-jupiter.version}</version>
<scope>test</scope>
</dependency>
<!-- tomcat -->
+3 -3
View File
@@ -147,9 +147,9 @@
<version>${jmh-core.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>${junit-jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
-1
View File
@@ -97,7 +97,6 @@
<log4j2.version>2.7</log4j2.version>
<disruptor.version>3.3.6</disruptor.version>
<jbosslogging.version>3.3.0.Final</jbosslogging.version>
<junit-jupiter.version>5.6.2</junit-jupiter.version>
</properties>
</project>
-4
View File
@@ -22,8 +22,4 @@
<module>log-mdc</module>
</modules>
<properties>
<junit-jupiter.version>5.6.2</junit-jupiter.version>
</properties>
</project>
@@ -9,20 +9,11 @@
<name>copy-rename-maven-plugin</name>
<parent>
<artifactId>maven-copy-files</artifactId>
<groupId>com.baeldung</groupId>
<artifactId>maven-copy-files</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
@@ -9,20 +9,11 @@
<name>maven-antrun-plugin</name>
<parent>
<artifactId>maven-copy-files</artifactId>
<groupId>com.baeldung</groupId>
<artifactId>maven-copy-files</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
@@ -6,23 +6,14 @@
<groupId>org.baeldung</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>1.0-SNAPSHOT</version>
<name>maven-resoures-plugin</name>
<name>maven-resources-plugin</name>
<parent>
<artifactId>maven-copy-files</artifactId>
<groupId>com.baeldung</groupId>
<artifactId>maven-copy-files</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<pluginManagement>
<!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
+3 -4
View File
@@ -12,8 +12,8 @@
<url>http://www.example.com</url>
<parent>
<artifactId>maven-modules</artifactId>
<groupId>com.baeldung</groupId>
<artifactId>maven-modules</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
@@ -25,9 +25,8 @@
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
@@ -15,9 +15,9 @@
<version>${commons.lang3.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>${junit-jupiter.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
@@ -44,7 +44,7 @@
<properties>
<commons.lang3.version>3.9</commons.lang3.version>
<junit.version>4.12</junit.version>
<junit-jupiter.version>5.8.1</junit-jupiter.version>
</properties>
</project>
@@ -1,29 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.baeldung</groupId>
<artifactId>maven-dependency</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>pom</packaging>
<parent>
<artifactId>maven-modules</artifactId>
<groupId>com.baeldung</groupId>
<artifactId>maven-modules</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
@@ -34,12 +26,13 @@
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
</dependencies>
</project>

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