Update and merge
This commit is contained in:
@@ -101,3 +101,4 @@
|
||||
- [HashSet and TreeSet Comparison](http://www.baeldung.com/java-hashset-vs-treeset)
|
||||
- [How to Perform a Simple HTTP Request in Java](http://www.baeldung.com/java-http-request)
|
||||
- [Call Methods at Runtime Using Java Reflection](http://www.baeldung.com/java-method-reflection)
|
||||
- [Guide to DelayQueue](http://www.baeldung.com/java-delay-queue)
|
||||
|
||||
+357
-328
@@ -1,363 +1,392 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>core-java</artifactId>
|
||||
<version>0.1.0-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
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>core-java</artifactId>
|
||||
<version>0.1.0-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>core-java</name>
|
||||
<name>core-java</name>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>parent-modules</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<!-- utils -->
|
||||
<dependency>
|
||||
<groupId>net.sourceforge.collections</groupId>
|
||||
<artifactId>collections-generic</artifactId>
|
||||
<version>${collections-generic.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
<version>${guava.version}</version>
|
||||
</dependency>
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-collections4</artifactId>
|
||||
<version>${commons-collections4.version}</version>
|
||||
</dependency>
|
||||
<!-- utils -->
|
||||
<dependency>
|
||||
<groupId>net.sourceforge.collections</groupId>
|
||||
<artifactId>collections-generic</artifactId>
|
||||
<version>${collections-generic.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
<version>${guava.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>commons-io</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
<version>${commons-io.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-collections4</artifactId>
|
||||
<version>${commons-collections4.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
<version>${commons-lang3.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-io</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
<version>${commons-io.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-math3</artifactId>
|
||||
<version>${commons-math3.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
<version>${commons-lang3.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.bouncycastle</groupId>
|
||||
<artifactId>bcprov-jdk15on</artifactId>
|
||||
<version>${bouncycastle.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-math3</artifactId>
|
||||
<version>${commons-math3.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.unix4j</groupId>
|
||||
<artifactId>unix4j-command</artifactId>
|
||||
<version>${unix4j.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.bouncycastle</groupId>
|
||||
<artifactId>bcprov-jdk15on</artifactId>
|
||||
<version>${bouncycastle.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.googlecode.grep4j</groupId>
|
||||
<artifactId>grep4j</artifactId>
|
||||
<version>${grep4j.version}</version>
|
||||
</dependency>
|
||||
<!-- web -->
|
||||
<dependency>
|
||||
<groupId>org.unix4j</groupId>
|
||||
<artifactId>unix4j-command</artifactId>
|
||||
<version>${unix4j.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- marshalling -->
|
||||
<dependency>
|
||||
<groupId>com.googlecode.grep4j</groupId>
|
||||
<artifactId>grep4j</artifactId>
|
||||
<version>${grep4j.version}</version>
|
||||
</dependency>
|
||||
<!-- web -->
|
||||
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
<version>${jackson.version}</version>
|
||||
</dependency>
|
||||
<!-- marshalling -->
|
||||
|
||||
<!-- logging -->
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>jcl-over-slf4j</artifactId>
|
||||
<version>${org.slf4j.version}</version>
|
||||
<!-- <scope>runtime</scope> --> <!-- some spring dependencies need to compile against jcl -->
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>${lombok.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- mysql -->
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<version>${mysql.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
<version>${jackson.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- test scoped -->
|
||||
<!-- logging -->
|
||||
|
||||
<dependency>
|
||||
<groupId>org.hamcrest</groupId>
|
||||
<artifactId>hamcrest-all</artifactId>
|
||||
<version>1.3</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
<version>${org.slf4j.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>ch.qos.logback</groupId>
|
||||
<artifactId>logback-classic</artifactId>
|
||||
<version>${logback.version}</version>
|
||||
<!-- <scope>runtime</scope> -->
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>jcl-over-slf4j</artifactId>
|
||||
<version>${org.slf4j.version}</version>
|
||||
<!-- <scope>runtime</scope> --> <!-- some spring dependencies need to compile against jcl -->
|
||||
</dependency>
|
||||
<dependency> <!-- needed to bridge to slf4j for projects that use the log4j APIs directly -->
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>log4j-over-slf4j</artifactId>
|
||||
<version>${org.slf4j.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>${lombok.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.hamcrest</groupId>
|
||||
<artifactId>hamcrest-core</artifactId>
|
||||
<version>${org.hamcrest.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hamcrest</groupId>
|
||||
<artifactId>hamcrest-library</artifactId>
|
||||
<version>${org.hamcrest.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<!-- test scoped -->
|
||||
|
||||
<dependency>
|
||||
<groupId>org.assertj</groupId>
|
||||
<artifactId>assertj-core</artifactId>
|
||||
<version>${assertj.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hamcrest</groupId>
|
||||
<artifactId>hamcrest-all</artifactId>
|
||||
<version>1.3</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-core</artifactId>
|
||||
<version>${mockito.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.jayway.awaitility</groupId>
|
||||
<artifactId>awaitility</artifactId>
|
||||
<version>${avaitility.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>${junit.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.hamcrest</groupId>
|
||||
<artifactId>hamcrest-core</artifactId>
|
||||
<version>${org.hamcrest.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hamcrest</groupId>
|
||||
<artifactId>hamcrest-library</artifactId>
|
||||
<version>${org.hamcrest.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.assertj</groupId>
|
||||
<artifactId>assertj-core</artifactId>
|
||||
<version>${assertj.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-core</artifactId>
|
||||
<version>${mockito.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.jayway.awaitility</groupId>
|
||||
<artifactId>awaitility</artifactId>
|
||||
<version>${avaitility.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>commons-codec</groupId>
|
||||
<artifactId>commons-codec</artifactId>
|
||||
<version>${commons-codec.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.javamoney</groupId>
|
||||
<artifactId>moneta</artifactId>
|
||||
<version>1.1</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>commons-codec</groupId>
|
||||
<artifactId>commons-codec</artifactId>
|
||||
<version>${commons-codec.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.javamoney</groupId>
|
||||
<artifactId>moneta</artifactId>
|
||||
<version>1.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.owasp.esapi</groupId>
|
||||
<artifactId>esapi</artifactId>
|
||||
<version>2.1.0.1</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>commons-logging</artifactId>
|
||||
<groupId>commons-logging</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.owasp.esapi</groupId>
|
||||
<artifactId>esapi</artifactId>
|
||||
<version>2.1.0.1</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>commons-logging</artifactId>
|
||||
<groupId>commons-logging</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</dependencies>
|
||||
<build>
|
||||
<finalName>core-java</finalName>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<filtering>true</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
|
||||
<build>
|
||||
<finalName>core-java</finalName>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<filtering>true</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
<plugins>
|
||||
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-dependency-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>copy-dependencies</id>
|
||||
<phase>prepare-package</phase>
|
||||
<goals>
|
||||
<goal>copy-dependencies</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<outputDirectory>${project.build.directory}/libs</outputDirectory>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>${maven-compiler-plugin.version}</version>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<configuration>
|
||||
<archive>
|
||||
<manifest>
|
||||
<addClasspath>true</addClasspath>
|
||||
<classpathPrefix>libs/</classpathPrefix>
|
||||
<mainClass>org.baeldung.executable.ExecutableMavenJar</mainClass>
|
||||
</manifest>
|
||||
</archive>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>single</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<archiveBaseDirectory>${project.basedir}</archiveBaseDirectory>
|
||||
<archive>
|
||||
<manifest>
|
||||
<mainClass>org.baeldung.executable.ExecutableMavenJar</mainClass>
|
||||
</manifest>
|
||||
</archive>
|
||||
<descriptorRefs>
|
||||
<descriptorRef>jar-with-dependencies</descriptorRef>
|
||||
</descriptorRefs>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<shadedArtifactAttached>true</shadedArtifactAttached>
|
||||
<transformers>
|
||||
<transformer
|
||||
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
|
||||
<mainClass>org.baeldung.executable.ExecutableMavenJar</mainClass>
|
||||
</transformer>
|
||||
</transformers>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>com.jolira</groupId>
|
||||
<artifactId>onejar-maven-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<configuration>
|
||||
<mainClass>org.baeldung.executable.ExecutableMavenJar</mainClass>
|
||||
<attachToBuild>true</attachToBuild>
|
||||
<filename>${project.build.finalName}-onejar.${project.packaging}</filename>
|
||||
</configuration>
|
||||
<goals>
|
||||
<goal>one-jar</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>repackage</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<classifier>spring-boot</classifier>
|
||||
<mainClass>org.baeldung.executable.ExecutableMavenJar</mainClass>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<configuration>
|
||||
<excludes>
|
||||
<exclude>**/*IntegrationTest.java</exclude>
|
||||
<exclude>**/*LongRunningUnitTest.java</exclude>
|
||||
<exclude>**/*ManualTest.java</exclude>
|
||||
</excludes>
|
||||
<testFailureIgnore>true</testFailureIgnore>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
</build>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-dependency-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>copy-dependencies</id>
|
||||
<phase>prepare-package</phase>
|
||||
<goals>
|
||||
<goal>copy-dependencies</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<outputDirectory>${project.build.directory}/libs</outputDirectory>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
<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>
|
||||
</excludes>
|
||||
<includes>
|
||||
<include>**/*IntegrationTest.java</include>
|
||||
</includes>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<systemPropertyVariables>
|
||||
<test.mime>json</test.mime>
|
||||
</systemPropertyVariables>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</profile>
|
||||
</profiles>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<configuration>
|
||||
<archive>
|
||||
<manifest>
|
||||
<addClasspath>true</addClasspath>
|
||||
<classpathPrefix>libs/</classpathPrefix>
|
||||
<mainClass>org.baeldung.executable.ExecutableMavenJar</mainClass>
|
||||
</manifest>
|
||||
</archive>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<properties>
|
||||
<!-- marshalling -->
|
||||
<jackson.version>2.8.5</jackson.version>
|
||||
|
||||
<!-- mysql -->
|
||||
<mysql.version>6.0.6</mysql.version>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>single</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<archiveBaseDirectory>${project.basedir}</archiveBaseDirectory>
|
||||
<archive>
|
||||
<manifest>
|
||||
<mainClass>org.baeldung.executable.ExecutableMavenJar</mainClass>
|
||||
</manifest>
|
||||
</archive>
|
||||
<descriptorRefs>
|
||||
<descriptorRef>jar-with-dependencies</descriptorRef>
|
||||
</descriptorRefs>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
<!-- util -->
|
||||
<guava.version>21.0</guava.version>
|
||||
<commons-lang3.version>3.5</commons-lang3.version>
|
||||
<bouncycastle.version>1.55</bouncycastle.version>
|
||||
<commons-codec.version>1.10</commons-codec.version>
|
||||
<commons-math3.version>3.6.1</commons-math3.version>
|
||||
<commons-io.version>2.5</commons-io.version>
|
||||
<commons-collections4.version>4.1</commons-collections4.version>
|
||||
<collections-generic.version>4.01</collections-generic.version>
|
||||
<unix4j.version>0.4</unix4j.version>
|
||||
<grep4j.version>1.8.7</grep4j.version>
|
||||
<lombok.version>1.16.12</lombok.version>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<shadedArtifactAttached>true</shadedArtifactAttached>
|
||||
<transformers>
|
||||
<transformer
|
||||
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
|
||||
<mainClass>org.baeldung.executable.ExecutableMavenJar</mainClass>
|
||||
</transformer>
|
||||
</transformers>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
<!-- testing -->
|
||||
<org.hamcrest.version>1.3</org.hamcrest.version>
|
||||
<mockito.version>1.10.19</mockito.version>
|
||||
<assertj.version>3.6.1</assertj.version>
|
||||
<avaitility.version>1.7.0</avaitility.version>
|
||||
<plugin>
|
||||
<groupId>com.jolira</groupId>
|
||||
<artifactId>onejar-maven-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<configuration>
|
||||
<mainClass>org.baeldung.executable.ExecutableMavenJar</mainClass>
|
||||
<attachToBuild>true</attachToBuild>
|
||||
<filename>${project.build.finalName}-onejar.${project.packaging}</filename>
|
||||
</configuration>
|
||||
<goals>
|
||||
<goal>one-jar</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
</properties>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>repackage</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<classifier>spring-boot</classifier>
|
||||
<mainClass>org.baeldung.executable.ExecutableMavenJar</mainClass>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
</project>
|
||||
</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>
|
||||
</excludes>
|
||||
<includes>
|
||||
<include>**/*IntegrationTest.java</include>
|
||||
</includes>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<systemPropertyVariables>
|
||||
<test.mime>json</test.mime>
|
||||
</systemPropertyVariables>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</profile>
|
||||
</profiles>
|
||||
|
||||
<properties>
|
||||
<!-- marshalling -->
|
||||
<jackson.version>2.8.5</jackson.version>
|
||||
|
||||
<!-- logging -->
|
||||
<org.slf4j.version>1.7.21</org.slf4j.version>
|
||||
<logback.version>1.1.7</logback.version>
|
||||
|
||||
<!-- util -->
|
||||
<guava.version>21.0</guava.version>
|
||||
<commons-lang3.version>3.5</commons-lang3.version>
|
||||
<bouncycastle.version>1.55</bouncycastle.version>
|
||||
<commons-codec.version>1.10</commons-codec.version>
|
||||
<commons-math3.version>3.6.1</commons-math3.version>
|
||||
<commons-io.version>2.5</commons-io.version>
|
||||
<commons-collections4.version>4.1</commons-collections4.version>
|
||||
<collections-generic.version>4.01</collections-generic.version>
|
||||
<unix4j.version>0.4</unix4j.version>
|
||||
<grep4j.version>1.8.7</grep4j.version>
|
||||
<lombok.version>1.16.12</lombok.version>
|
||||
|
||||
<!-- testing -->
|
||||
<org.hamcrest.version>1.3</org.hamcrest.version>
|
||||
<junit.version>4.12</junit.version>
|
||||
<mockito.version>1.10.19</mockito.version>
|
||||
<assertj.version>3.6.1</assertj.version>
|
||||
<avaitility.version>1.7.0</avaitility.version>
|
||||
|
||||
<!-- maven plugins -->
|
||||
<maven-compiler-plugin.version>3.6.0</maven-compiler-plugin.version>
|
||||
<maven-surefire-plugin.version>2.19.1</maven-surefire-plugin.version>
|
||||
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.baeldung.concurrent.delayqueue;
|
||||
|
||||
import com.google.common.primitives.Ints;
|
||||
|
||||
import java.util.concurrent.Delayed;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class DelayObject implements Delayed {
|
||||
private String data;
|
||||
private long startTime;
|
||||
|
||||
public DelayObject(String data, long delayInMilliseconds) {
|
||||
this.data = data;
|
||||
this.startTime = System.currentTimeMillis() + delayInMilliseconds;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getDelay(TimeUnit unit) {
|
||||
long diff = startTime - System.currentTimeMillis();
|
||||
return unit.convert(diff, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(Delayed o) {
|
||||
return Ints.saturatedCast(this.startTime - ((DelayObject) o).startTime);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "{" +
|
||||
"data='" + data + '\'' +
|
||||
", startTime=" + startTime +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.baeldung.concurrent.delayqueue;
|
||||
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
|
||||
public class DelayQueueConsumer implements Runnable {
|
||||
private BlockingQueue<DelayObject> queue;
|
||||
private final Integer numberOfElementsToTake;
|
||||
public final AtomicInteger numberOfConsumedElements = new AtomicInteger();
|
||||
|
||||
public DelayQueueConsumer(BlockingQueue<DelayObject> queue, Integer numberOfElementsToTake) {
|
||||
this.queue = queue;
|
||||
this.numberOfElementsToTake = numberOfElementsToTake;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
for (int i = 0; i < numberOfElementsToTake; i++) {
|
||||
try {
|
||||
DelayObject object = queue.take();
|
||||
numberOfConsumedElements.incrementAndGet();
|
||||
System.out.println("Consumer take: " + object);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.baeldung.concurrent.delayqueue;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
|
||||
|
||||
public class DelayQueueProducer implements Runnable {
|
||||
private BlockingQueue<DelayObject> queue;
|
||||
private final Integer numberOfElementsToProduce;
|
||||
private final Integer delayOfEachProducedMessageMilliseconds;
|
||||
|
||||
public DelayQueueProducer(BlockingQueue<DelayObject> queue,
|
||||
Integer numberOfElementsToProduce,
|
||||
Integer delayOfEachProducedMessageMilliseconds) {
|
||||
this.queue = queue;
|
||||
this.numberOfElementsToProduce = numberOfElementsToProduce;
|
||||
this.delayOfEachProducedMessageMilliseconds = delayOfEachProducedMessageMilliseconds;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
for (int i = 0; i < numberOfElementsToProduce; i++) {
|
||||
DelayObject object
|
||||
= new DelayObject(UUID.randomUUID().toString(), delayOfEachProducedMessageMilliseconds);
|
||||
System.out.println("Put object = " + object);
|
||||
try {
|
||||
queue.put(object);
|
||||
Thread.sleep(500);
|
||||
} catch (InterruptedException ie) {
|
||||
ie.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.baeuldung.serialization;
|
||||
|
||||
public class Address {
|
||||
|
||||
private int houseNumber;
|
||||
|
||||
public int getHouseNumber() {
|
||||
return houseNumber;
|
||||
}
|
||||
|
||||
public void setHouseNumber(int houseNumber) {
|
||||
this.houseNumber = houseNumber;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package com.baeuldung.serialization;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.Serializable;
|
||||
|
||||
public class Employee implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private transient Address address; // not an serializable object
|
||||
private Person person;
|
||||
|
||||
public Address getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
public void setAddress(Address address) {
|
||||
this.address = address;
|
||||
}
|
||||
|
||||
public Person getPerson() {
|
||||
return person;
|
||||
}
|
||||
|
||||
public void setPerson(Person person) {
|
||||
this.person = person;
|
||||
}
|
||||
|
||||
private void writeObject(ObjectOutputStream oos) throws IOException {
|
||||
oos.defaultWriteObject();
|
||||
oos.writeObject(address.getHouseNumber());
|
||||
}
|
||||
|
||||
private void readObject(ObjectInputStream ois) throws ClassNotFoundException, IOException {
|
||||
ois.defaultReadObject();
|
||||
Integer houseNumber = (Integer) ois.readObject();
|
||||
Address a = new Address();
|
||||
a.setHouseNumber(houseNumber);
|
||||
this.setAddress(a);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.baeuldung.serialization;
|
||||
import java.io.Serializable;
|
||||
|
||||
public class Person implements Serializable {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private int age;
|
||||
private String name;
|
||||
|
||||
public int getAge() {
|
||||
return age;
|
||||
}
|
||||
|
||||
public void setAge(int age) {
|
||||
this.age = age;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
}
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
package com.baeldung.stackoverflowerror;
|
||||
|
||||
public class RecursionWithCorrectTerminationCondition {
|
||||
public static int calculateFactorial(final int number) {
|
||||
public int calculateFactorial(final int number) {
|
||||
return number <= 1 ? 1 : number * calculateFactorial(number - 1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,10 @@ public class StringHelper {
|
||||
public static String removeLastCharRegexOptional(String s) {
|
||||
return Optional.ofNullable(s)
|
||||
.map(str -> str.replaceAll(".$", ""))
|
||||
<<<<<<< HEAD
|
||||
.orElse(s);
|
||||
=======
|
||||
.orElse(null);
|
||||
>>>>>>> refs/remotes/eugenp/master
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
dataSourceClassName=//TBD
|
||||
dataSource.user=//TBD
|
||||
dataSource.password=//TBD
|
||||
dataSource.databaseName=//TBD
|
||||
dataSource.portNumber=//TBD
|
||||
dataSource.serverName=//TBD
|
||||
+1
-1
@@ -9,7 +9,7 @@ import org.junit.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class ArrayCopyUtilTest {
|
||||
public class ArrayCopyUtilUnitTest {
|
||||
private static Employee[] employees;
|
||||
private static final int MAX = 2;
|
||||
|
||||
+1
-1
@@ -11,7 +11,7 @@ import java.util.stream.IntStream;
|
||||
|
||||
import static junit.framework.TestCase.assertEquals;
|
||||
|
||||
public class LongAccumulatorTest {
|
||||
public class LongAccumulatorUnitTest {
|
||||
|
||||
@Test
|
||||
public void givenLongAccumulator_whenApplyActionOnItFromMultipleThrads_thenShouldProduceProperResult() throws InterruptedException {
|
||||
+1
-1
@@ -11,7 +11,7 @@ import java.util.stream.IntStream;
|
||||
import static com.jayway.awaitility.Awaitility.await;
|
||||
import static junit.framework.TestCase.assertEquals;
|
||||
|
||||
public class LongAdderTest {
|
||||
public class LongAdderUnitTest {
|
||||
@Test
|
||||
public void givenMultipleThread_whenTheyWriteToSharedLongAdder_thenShouldCalculateSumForThem() throws InterruptedException {
|
||||
//given
|
||||
+1
-1
@@ -11,7 +11,7 @@ import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
|
||||
public class CopyOnWriteArrayListTest {
|
||||
public class CopyOnWriteArrayListUnitTest {
|
||||
|
||||
@Test
|
||||
public void givenCopyOnWriteList_whenIterateAndAddElementToUnderneathList_thenShouldNotChangeIterator() {
|
||||
+78
@@ -0,0 +1,78 @@
|
||||
package com.baeldung.concurrent.delayqueue;
|
||||
|
||||
import org.junit.FixMethodOrder;
|
||||
import org.junit.Test;
|
||||
import org.junit.runners.MethodSorters;
|
||||
|
||||
import java.util.concurrent.*;
|
||||
|
||||
import static junit.framework.TestCase.assertEquals;
|
||||
|
||||
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
||||
public class DelayQueueIntegrationTest {
|
||||
@Test
|
||||
public void givenDelayQueue_whenProduceElement_thenShouldConsumeAfterGivenDelay() throws InterruptedException {
|
||||
//given
|
||||
ExecutorService executor = Executors.newFixedThreadPool(2);
|
||||
BlockingQueue<DelayObject> queue = new DelayQueue<>();
|
||||
int numberOfElementsToProduce = 2;
|
||||
int delayOfEachProducedMessageMilliseconds = 500;
|
||||
DelayQueueConsumer consumer = new DelayQueueConsumer(queue, numberOfElementsToProduce);
|
||||
DelayQueueProducer producer
|
||||
= new DelayQueueProducer(queue, numberOfElementsToProduce, delayOfEachProducedMessageMilliseconds);
|
||||
|
||||
//when
|
||||
executor.submit(producer);
|
||||
executor.submit(consumer);
|
||||
|
||||
//then
|
||||
executor.awaitTermination(5, TimeUnit.SECONDS);
|
||||
executor.shutdown();
|
||||
assertEquals(consumer.numberOfConsumedElements.get(), numberOfElementsToProduce);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenDelayQueue_whenProduceElementWithHugeDelay_thenConsumerWasNotAbleToConsumeMessageInGivenTime() throws InterruptedException {
|
||||
//given
|
||||
ExecutorService executor = Executors.newFixedThreadPool(2);
|
||||
BlockingQueue<DelayObject> queue = new DelayQueue<>();
|
||||
int numberOfElementsToProduce = 1;
|
||||
int delayOfEachProducedMessageMilliseconds = 10_000;
|
||||
DelayQueueConsumer consumer = new DelayQueueConsumer(queue, numberOfElementsToProduce);
|
||||
DelayQueueProducer producer
|
||||
= new DelayQueueProducer(queue, numberOfElementsToProduce, delayOfEachProducedMessageMilliseconds);
|
||||
|
||||
//when
|
||||
executor.submit(producer);
|
||||
executor.submit(consumer);
|
||||
|
||||
//then
|
||||
executor.awaitTermination(5, TimeUnit.SECONDS);
|
||||
executor.shutdown();
|
||||
assertEquals(consumer.numberOfConsumedElements.get(), 0);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenDelayQueue_whenProduceElementWithNegativeDelay_thenConsumeMessageImmediately() throws InterruptedException {
|
||||
//given
|
||||
ExecutorService executor = Executors.newFixedThreadPool(2);
|
||||
BlockingQueue<DelayObject> queue = new DelayQueue<>();
|
||||
int numberOfElementsToProduce = 1;
|
||||
int delayOfEachProducedMessageMilliseconds = -10_000;
|
||||
DelayQueueConsumer consumer = new DelayQueueConsumer(queue, numberOfElementsToProduce);
|
||||
DelayQueueProducer producer
|
||||
= new DelayQueueProducer(queue, numberOfElementsToProduce, delayOfEachProducedMessageMilliseconds);
|
||||
|
||||
//when
|
||||
executor.submit(producer);
|
||||
executor.submit(consumer);
|
||||
|
||||
//then
|
||||
executor.awaitTermination(1, TimeUnit.SECONDS);
|
||||
executor.shutdown();
|
||||
assertEquals(consumer.numberOfConsumedElements.get(), 1);
|
||||
|
||||
}
|
||||
}
|
||||
+1
-3
@@ -66,9 +66,7 @@ public class SharedObjectWithLockManualTest {
|
||||
|
||||
private void executeThreads(SharedObjectWithLock object, int threadCount, ExecutorService service) {
|
||||
for (int i = 0; i < threadCount; i++) {
|
||||
service.execute(() -> {
|
||||
object.perform();
|
||||
});
|
||||
service.execute(object::perform);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -11,7 +11,7 @@ import java.util.concurrent.Phaser;
|
||||
import static junit.framework.TestCase.assertEquals;
|
||||
|
||||
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
||||
public class PhaserTest {
|
||||
public class PhaserUnitTest {
|
||||
|
||||
@Test
|
||||
public void givenPhaser_whenCoordinateWorksBetweenThreads_thenShouldCoordinateBetweenMultiplePhases() {
|
||||
+1
-1
@@ -9,7 +9,7 @@ import java.time.temporal.ChronoUnit;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class JavaDurationTest {
|
||||
public class JavaDurationUnitTest {
|
||||
|
||||
@Test
|
||||
public void test2() {
|
||||
+2
-2
@@ -9,9 +9,9 @@ import java.time.Period;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
|
||||
public class JavaPeriodTest {
|
||||
public class JavaPeriodUnitTest {
|
||||
|
||||
private static final Logger LOG = Logger.getLogger(JavaPeriodTest.class);
|
||||
private static final Logger LOG = Logger.getLogger(JavaPeriodUnitTest.class);
|
||||
|
||||
@Test
|
||||
public void whenTestPeriod_thenOk() {
|
||||
+5
-5
@@ -9,18 +9,18 @@ import java.util.Map;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
public class DynamicProxyTest {
|
||||
public class DynamicProxyIntegrationTest {
|
||||
|
||||
@Test
|
||||
public void givenDynamicProxy_thenPutWorks() {
|
||||
Map proxyInstance = (Map) Proxy.newProxyInstance(DynamicProxyTest.class.getClassLoader(), new Class[] { Map.class }, new DynamicInvocationHandler());
|
||||
Map proxyInstance = (Map) Proxy.newProxyInstance(DynamicProxyIntegrationTest.class.getClassLoader(), new Class[] { Map.class }, new DynamicInvocationHandler());
|
||||
|
||||
proxyInstance.put("hello", "world");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenInlineDynamicProxy_thenGetWorksOtherMethodsDoNot() {
|
||||
Map proxyInstance = (Map) Proxy.newProxyInstance(DynamicProxyTest.class.getClassLoader(), new Class[] { Map.class }, (proxy, method, methodArgs) -> {
|
||||
Map proxyInstance = (Map) Proxy.newProxyInstance(DynamicProxyIntegrationTest.class.getClassLoader(), new Class[] { Map.class }, (proxy, method, methodArgs) -> {
|
||||
|
||||
if (method.getName().equals("get")) {
|
||||
return 42;
|
||||
@@ -43,12 +43,12 @@ public class DynamicProxyTest {
|
||||
|
||||
@Test
|
||||
public void givenTimingDynamicProxy_thenMethodInvokationsProduceTiming() {
|
||||
Map mapProxyInstance = (Map) Proxy.newProxyInstance(DynamicProxyTest.class.getClassLoader(), new Class[] { Map.class }, new TimingDynamicInvocationHandler(new HashMap<>()));
|
||||
Map mapProxyInstance = (Map) Proxy.newProxyInstance(DynamicProxyIntegrationTest.class.getClassLoader(), new Class[] { Map.class }, new TimingDynamicInvocationHandler(new HashMap<>()));
|
||||
|
||||
mapProxyInstance.put("hello", "world");
|
||||
assertEquals("world", mapProxyInstance.get("hello"));
|
||||
|
||||
CharSequence csProxyInstance = (CharSequence) Proxy.newProxyInstance(DynamicProxyTest.class.getClassLoader(), new Class[] { CharSequence.class }, new TimingDynamicInvocationHandler("Hello World"));
|
||||
CharSequence csProxyInstance = (CharSequence) Proxy.newProxyInstance(DynamicProxyIntegrationTest.class.getClassLoader(), new Class[] { CharSequence.class }, new TimingDynamicInvocationHandler("Hello World"));
|
||||
|
||||
assertEquals('l', csProxyInstance.charAt(2));
|
||||
assertEquals(11, csProxyInstance.length());
|
||||
+2
-3
@@ -14,8 +14,7 @@ import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class FileOperationsUnitTest {
|
||||
public class FileOperationsManualTest {
|
||||
|
||||
@Test
|
||||
public void givenFileName_whenUsingClassloader_thenFileData() throws IOException {
|
||||
@@ -33,7 +32,7 @@ public class FileOperationsUnitTest {
|
||||
public void givenFileNameAsAbsolutePath_whenUsingClasspath_thenFileData() throws IOException {
|
||||
String expectedData = "Hello World from fileTest.txt!!!";
|
||||
|
||||
Class clazz = FileOperationsUnitTest.class;
|
||||
Class clazz = FileOperationsManualTest.class;
|
||||
InputStream inputStream = clazz.getResourceAsStream("/fileTest.txt");
|
||||
String data = readFromInputStream(inputStream);
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@ import static org.hamcrest.CoreMatchers.hasItems;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
public class GenericsTest {
|
||||
public class GenericsUnitTest {
|
||||
|
||||
// testing the generic method with Integer
|
||||
@Test
|
||||
+1
-1
@@ -12,7 +12,7 @@ import org.unix4j.line.Line;
|
||||
import static org.unix4j.unix.Grep.*;
|
||||
import static org.unix4j.unix.cut.CutOption.*;
|
||||
|
||||
public class GrepWithUnix4JTest {
|
||||
public class GrepWithUnix4JIntegrationTest {
|
||||
|
||||
private File fileToGrep;
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@ import com.google.common.collect.EnumHashBiMap;
|
||||
import com.google.common.collect.HashBiMap;
|
||||
import com.google.common.collect.ImmutableBiMap;
|
||||
|
||||
public class GuavaBiMapTest {
|
||||
public class GuavaBiMapUnitTest {
|
||||
@Test
|
||||
public void whenQueryByValue_returnsKey() {
|
||||
final BiMap<String, String> capitalCountryBiMap = HashBiMap.create();
|
||||
+1
-1
@@ -4,7 +4,7 @@ import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class SHA256HashingTest {
|
||||
public class SHA256HashingUnitTest {
|
||||
|
||||
private static String originalValue = "abc123";
|
||||
private static String hashedValue = "6ca13d52ca70c883e0f0bb101e425a89e8624de51db2d2392593af6a84118090";
|
||||
+5
-5
@@ -1,13 +1,13 @@
|
||||
package com.baeldung.hexToAscii;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class HexToAscii {
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class HexToAsciiUnitTest {
|
||||
|
||||
@Test
|
||||
public static void whenHexToAscii() {
|
||||
public void whenHexToAscii() {
|
||||
String asciiString = "http://www.baeldung.com/jackson-serialize-dates";
|
||||
String hexEquivalent = "687474703a2f2f7777772e6261656c64756e672e636f6d2f6a61636b736f6e2d73657269616c697a652d6461746573";
|
||||
|
||||
@@ -15,7 +15,7 @@ public class HexToAscii {
|
||||
}
|
||||
|
||||
@Test
|
||||
public static void whenAsciiToHex() {
|
||||
public void whenAsciiToHex() {
|
||||
String asciiString = "http://www.baeldung.com/jackson-serialize-dates";
|
||||
String hexEquivalent = "687474703a2f2f7777772e6261656c64756e672e636f6d2f6a61636b736f6e2d73657269616c697a652d6461746573";
|
||||
|
||||
+1
-1
@@ -17,7 +17,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
public class HttpRequestTest {
|
||||
public class HttpRequestLiveTest {
|
||||
|
||||
@Test
|
||||
public void whenGetRequest_thenOk() throws IOException {
|
||||
+1
-1
@@ -8,7 +8,7 @@ import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import static java.util.Arrays.asList;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class ConcurrentModificationExceptionTest {
|
||||
public class ConcurrentModificationExceptionUnitTest {
|
||||
|
||||
@Test
|
||||
public void changingContentWithSetDoesNotThrowConcurrentModificationException() throws Exception {
|
||||
+1
-1
@@ -12,7 +12,7 @@ import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class ConcurrentNavigableMapManualTests {
|
||||
public class ConcurrentNavigableMapManualTest {
|
||||
|
||||
@Test
|
||||
public void givenSkipListMap_whenAccessInMultiThreads_thenOrderingStable() throws InterruptedException {
|
||||
+1
-1
@@ -11,7 +11,7 @@ import java.util.stream.StreamSupport;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.collection.IsIterableContainingInOrder.contains;
|
||||
|
||||
public class IterableStreamConversionTest {
|
||||
public class IterableStreamConversionUnitTest {
|
||||
|
||||
@Test
|
||||
public void givenIterable_whenConvertedToStream_thenNotNull() {
|
||||
+1
-1
@@ -15,7 +15,7 @@ import org.junit.Test;
|
||||
|
||||
import com.baeldung.datetime.UseLocalDateTime;
|
||||
|
||||
public class StringConversionTest {
|
||||
public class StringConversionUnitTest {
|
||||
|
||||
@Test
|
||||
public void whenConvertedToInt_thenCorrect() {
|
||||
+93
@@ -0,0 +1,93 @@
|
||||
package com.baeldung.java.countingChars;
|
||||
|
||||
import com.google.common.base.CharMatcher;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
|
||||
/***
|
||||
* Example of counting chars in a String.
|
||||
*/
|
||||
public class CountCharsExampleUnitTest {
|
||||
|
||||
@Test
|
||||
public void givenString_whenUsingLoop_thenCountChars() {
|
||||
String someString = "elephant";
|
||||
char someChar = 'e';
|
||||
int count = 0;
|
||||
for (int i = 0; i < someString.length(); i++) {
|
||||
if (someString.charAt(i) == someChar) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
assertEquals(2, count);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenString_whenUsingReplace_thenCountChars() {
|
||||
String someString = "elephant";
|
||||
int count = someString.length() - someString.replace("e", "").length();
|
||||
assertEquals(2, count);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenString_whenUsingSplit_thenCountChars() {
|
||||
String someString = "elephant";
|
||||
int count = someString.split("e", -1).length - 1;
|
||||
assertEquals(2, count);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenString_whenUsingReqExp_thenCountChars() {
|
||||
Pattern pattern = Pattern.compile("[^e]*e");
|
||||
Matcher matcher = pattern.matcher("elephant");
|
||||
int count = 0;
|
||||
while (matcher.find()) {
|
||||
count++;
|
||||
}
|
||||
assertEquals(2, count);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenString_whenUsingRecursion_thenCountChars() {
|
||||
int count = useRecursion("elephant", 'e', 0);
|
||||
assertEquals(2, count);
|
||||
}
|
||||
|
||||
private int useRecursion(String someString, char searchedChar, int index) {
|
||||
if (index >= someString.length()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int count = someString.charAt(index) == searchedChar ? 1 : 0;
|
||||
return count + useRecursion(someString, searchedChar, index + 1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenString_whenUsingStringUtils_thenCountChars() throws InterruptedException {
|
||||
int count = StringUtils.countMatches("elephant", "e");
|
||||
assertEquals(2, count);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenString_whenUsingJava8Features_thenCountChars() {
|
||||
String someString = "elephant";
|
||||
long count = someString.chars().filter(ch -> ch == 'e').count();
|
||||
assertEquals(2, count);
|
||||
|
||||
long count2 = someString.codePoints().filter(ch -> ch == 'e').count();
|
||||
assertEquals(2, count2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenString_whenUsingGuavaCharMatcher_thenCountChars() {
|
||||
int count = CharMatcher.is('e').countIn("elephant");
|
||||
assertEquals(2, count);
|
||||
}
|
||||
|
||||
}
|
||||
+1
-1
@@ -11,7 +11,7 @@ import static java.util.stream.Collectors.collectingAndThen;
|
||||
import static java.util.stream.Collectors.toSet;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class DoubleBraceTest {
|
||||
public class DoubleBraceUnitTest {
|
||||
|
||||
@Test
|
||||
public void whenInitializeSetWithoutDoubleBraces_containsElements() {
|
||||
+2
-2
@@ -9,8 +9,8 @@ import java.util.Map.Entry;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class MapTest {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(MapTest.class);
|
||||
public class MapUnitTest {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(MapUnitTest.class);
|
||||
|
||||
|
||||
@Test
|
||||
+1
-1
@@ -13,7 +13,7 @@ import java.util.UUID;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class FileTest {
|
||||
public class FileIntegrationTest {
|
||||
private static final String TEMP_DIR = String.format("%s/temp%s", System.getProperty("user.home"), UUID.randomUUID().toString());
|
||||
|
||||
@BeforeClass
|
||||
+1
-1
@@ -8,7 +8,7 @@ import java.io.IOException;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class AsyncEchoTest {
|
||||
public class AsyncEchoIntegrationTest {
|
||||
|
||||
Process server;
|
||||
AsyncEchoClient client;
|
||||
+2
-2
@@ -16,7 +16,7 @@ import java.util.concurrent.Future;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class AsyncFileTest {
|
||||
public class AsyncFileIntegrationTest {
|
||||
@Test
|
||||
public void givenPath_whenReadsContentWithFuture_thenCorrect() throws IOException, ExecutionException, InterruptedException {
|
||||
Path path = Paths.get(URI.create(this.getClass().getClassLoader().getResource("file.txt").toString()));
|
||||
@@ -36,7 +36,7 @@ public class AsyncFileTest {
|
||||
|
||||
@Test
|
||||
public void givenPath_whenReadsContentWithCompletionHandler_thenCorrect() throws IOException {
|
||||
Path path = Paths.get(URI.create(AsyncFileTest.class.getResource("/file.txt").toString()));
|
||||
Path path = Paths.get(URI.create(AsyncFileIntegrationTest.class.getResource("/file.txt").toString()));
|
||||
AsynchronousFileChannel fileChannel = AsynchronousFileChannel.open(path, StandardOpenOption.READ);
|
||||
|
||||
ByteBuffer buffer = ByteBuffer.allocate(1024);
|
||||
+2
-2
@@ -16,9 +16,9 @@ import java.nio.file.attribute.FileTime;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class BasicAttribsTest {
|
||||
public class BasicAttribsIntegrationTest {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(BasicAttribsTest.class);
|
||||
private static final Logger LOG = LoggerFactory.getLogger(BasicAttribsIntegrationTest.class);
|
||||
|
||||
|
||||
private static final String HOME = System.getProperty("user.home");
|
||||
+2
-2
@@ -9,9 +9,9 @@ import java.util.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class SetTest {
|
||||
public class SetUnitTest {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(SetTest.class);
|
||||
private static final Logger LOG = LoggerFactory.getLogger(SetUnitTest.class);
|
||||
|
||||
@Test
|
||||
public void givenTreeSet_whenRetrievesObjects_thenNaturalOrder() {
|
||||
+1
-1
@@ -11,7 +11,7 @@ import static org.hamcrest.Matchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class Java8FindAnyFindFirstTest {
|
||||
public class Java8FindAnyFindFirstUnitTest {
|
||||
|
||||
@Test
|
||||
public void createStream_whenFindAnyResultIsPresent_thenCorrect() {
|
||||
+2
-2
@@ -8,9 +8,9 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class Java8ForEachTest {
|
||||
public class Java8ForEachUnitTest {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(Java8ForEachTest.class);
|
||||
private static final Logger LOG = LoggerFactory.getLogger(Java8ForEachUnitTest.class);
|
||||
|
||||
@Test
|
||||
public void compareForEachMethods_thenPrintResults() {
|
||||
+1
-1
@@ -10,7 +10,7 @@ import java.util.NoSuchElementException;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class Java8MaxMinTest {
|
||||
public class Java8MaxMinUnitTest {
|
||||
|
||||
@Test
|
||||
public void whenListIsOfIntegerThenMaxCanBeDoneUsingIntegerComparator() {
|
||||
+1
-1
@@ -8,7 +8,7 @@ import org.junit.Test;
|
||||
import lombok.Data;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class Java8ComparatorTest {
|
||||
public class Java8ComparatorUnitTest {
|
||||
|
||||
private Employee[] employees;
|
||||
private Employee[] employeesArrayWithNulls;
|
||||
+2
-2
@@ -11,9 +11,9 @@ import java.util.List;
|
||||
|
||||
import static com.baeldung.java8.lambda.exceptions.LambdaExceptionWrappers.*;
|
||||
|
||||
public class LambdaExceptionWrappersTest {
|
||||
public class LambdaExceptionWrappersUnitTest {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(LambdaExceptionWrappersTest.class);
|
||||
private static final Logger LOG = LoggerFactory.getLogger(LambdaExceptionWrappersUnitTest.class);
|
||||
|
||||
|
||||
private List<Integer> integers;
|
||||
+2
-2
@@ -13,9 +13,9 @@ import java.util.Optional;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class OptionalTest {
|
||||
public class OptionalUnitTest {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(OptionalTest.class);
|
||||
private static final Logger LOG = LoggerFactory.getLogger(OptionalUnitTest.class);
|
||||
|
||||
|
||||
// creating Optional
|
||||
+2
-2
@@ -21,9 +21,9 @@ import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class JdbcTest {
|
||||
public class JdbcIntegrationTest {
|
||||
|
||||
private static final Logger LOG = Logger.getLogger(JdbcTest.class);
|
||||
private static final Logger LOG = Logger.getLogger(JdbcIntegrationTest.class);
|
||||
|
||||
private Connection con;
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@ import static org.junit.Assert.assertEquals;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
public class DivisibilityTest {
|
||||
public class DivisibilityUnitTest {
|
||||
|
||||
private static int number;
|
||||
|
||||
+2
-2
@@ -11,12 +11,12 @@ import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
|
||||
@RunWith(value = Parameterized.class)
|
||||
public class ParametrizedTests {
|
||||
public class ParametrizedUnitTest {
|
||||
|
||||
private int value;
|
||||
private boolean isEven;
|
||||
|
||||
public ParametrizedTests(int value, boolean isEven) {
|
||||
public ParametrizedUnitTest(int value, boolean isEven) {
|
||||
this.value = value;
|
||||
this.isEven = isEven;
|
||||
}
|
||||
+2
-2
@@ -5,8 +5,8 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
||||
public class RegistrationTest {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(RegistrationTest.class);
|
||||
public class RegistrationUnitTest {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(RegistrationUnitTest.class);
|
||||
|
||||
@Test
|
||||
public void whenCalledFromSuite_thanOK() {
|
||||
+2
-2
@@ -4,8 +4,8 @@ import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class SignInTest {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(SignInTest.class);
|
||||
public class SignInUnitTest {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(SignInUnitTest.class);
|
||||
|
||||
@Test
|
||||
public void whenCalledFromSuite_thanOK() {
|
||||
+1
-1
@@ -7,7 +7,7 @@ import org.junit.Test;
|
||||
import org.junit.runners.MethodSorters;
|
||||
|
||||
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
||||
public class SortedTests {
|
||||
public class SortedUnitTest {
|
||||
|
||||
@Test
|
||||
public void a_givenString_whenChangedtoInt_thenTrue() {
|
||||
+1
-1
@@ -5,7 +5,7 @@ import static org.junit.Assert.assertEquals;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
public class StringCaseTest {
|
||||
public class StringCaseUnitTest {
|
||||
|
||||
private static String data;
|
||||
|
||||
@@ -4,7 +4,7 @@ import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Suite;
|
||||
|
||||
@RunWith(Suite.class)
|
||||
@Suite.SuiteClasses({ RegistrationTest.class, SignInTest.class })
|
||||
@Suite.SuiteClasses({ RegistrationUnitTest.class, SignInUnitTest.class })
|
||||
public class SuiteTest {
|
||||
|
||||
}
|
||||
|
||||
+1
-1
@@ -11,7 +11,7 @@ import org.junit.Test;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class SummationServiceTest {
|
||||
public class SummationServiceIntegrationTest {
|
||||
private static List<Integer> numbers;
|
||||
|
||||
@BeforeClass
|
||||
+1
-1
@@ -13,7 +13,7 @@ import java.util.stream.Collectors;
|
||||
import org.hamcrest.collection.IsIterableContainingInOrder;
|
||||
import org.junit.Test;
|
||||
|
||||
public class FlattenNestedListTest {
|
||||
public class FlattenNestedListUnitTest {
|
||||
List<List<String>> lol = asList(asList("one:one"), asList("two:one", "two:two", "two:three"), asList("three:one", "three:two", "three:three", "three:four"));
|
||||
|
||||
@Test
|
||||
+1
-1
@@ -7,7 +7,7 @@ import static org.junit.Assert.assertEquals;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class ListOfListsTest {
|
||||
public class ListOfListsUnitTest {
|
||||
|
||||
private List<ArrayList<? extends Stationery>> listOfLists = new ArrayList<ArrayList<? extends Stationery>>();
|
||||
private ArrayList<Pen> penList = new ArrayList<>();
|
||||
+1
-1
@@ -16,7 +16,7 @@ import java.util.List;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
public class MappedByteBufferTest {
|
||||
public class MappedByteBufferUnitTest {
|
||||
|
||||
|
||||
@Test
|
||||
+1
-1
@@ -21,7 +21,7 @@ import java.util.Locale;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class JavaMoneyTest {
|
||||
public class JavaMoneyUnitTest {
|
||||
|
||||
@Test
|
||||
public void givenCurrencyCode_whenString_thanExist() {
|
||||
+5
-5
@@ -9,7 +9,7 @@ import java.io.InputStreamReader;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class NashornTest {
|
||||
public class NashornUnitTest {
|
||||
|
||||
private ScriptEngine engine;
|
||||
|
||||
@@ -20,17 +20,17 @@ public class NashornTest {
|
||||
|
||||
@Test
|
||||
public void trim() throws ScriptException {
|
||||
engine.eval(new InputStreamReader(NashornTest.class.getResourceAsStream("/js/trim.js")));
|
||||
engine.eval(new InputStreamReader(NashornUnitTest.class.getResourceAsStream("/js/trim.js")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void locations() throws ScriptException {
|
||||
engine.eval(new InputStreamReader(NashornTest.class.getResourceAsStream("/js/locations.js")));
|
||||
engine.eval(new InputStreamReader(NashornUnitTest.class.getResourceAsStream("/js/locations.js")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bindProperties() throws ScriptException {
|
||||
engine.eval(new InputStreamReader(NashornTest.class.getResourceAsStream("/js/bind.js")));
|
||||
engine.eval(new InputStreamReader(NashornUnitTest.class.getResourceAsStream("/js/bind.js")));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -40,7 +40,7 @@ public class NashornTest {
|
||||
|
||||
@Test
|
||||
public void typedArrays() throws ScriptException {
|
||||
engine.eval(new InputStreamReader(NashornTest.class.getResourceAsStream("/js/typed_arrays.js")));
|
||||
engine.eval(new InputStreamReader(NashornUnitTest.class.getResourceAsStream("/js/typed_arrays.js")));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -0,0 +1,64 @@
|
||||
package com.baeuldung.serialization;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class PersonUnitTest {
|
||||
|
||||
@Test
|
||||
public void whenSerializingAndDeserializing_ThenObjectIsTheSame() throws IOException, ClassNotFoundException {
|
||||
Person p = new Person();
|
||||
p.setAge(20);
|
||||
p.setName("Joe");
|
||||
|
||||
FileOutputStream fileOutputStream = new FileOutputStream("yofile.txt");
|
||||
ObjectOutputStream objectOutputStream = new ObjectOutputStream(fileOutputStream);
|
||||
objectOutputStream.writeObject(p);
|
||||
objectOutputStream.flush();
|
||||
objectOutputStream.close();
|
||||
|
||||
FileInputStream fileInputStream = new FileInputStream("yofile.txt");
|
||||
ObjectInputStream objectInputStream = new ObjectInputStream(fileInputStream);
|
||||
Person p2 = (Person) objectInputStream.readObject();
|
||||
objectInputStream.close();
|
||||
|
||||
assertTrue(p2.getAge() == p.getAge());
|
||||
assertTrue(p2.getName().equals(p.getName()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenCustomSerializingAndDeserializing_ThenObjectIsTheSame() throws IOException, ClassNotFoundException {
|
||||
Person p = new Person();
|
||||
p.setAge(20);
|
||||
p.setName("Joe");
|
||||
|
||||
Address a = new Address();
|
||||
a.setHouseNumber(1);
|
||||
|
||||
Employee e = new Employee();
|
||||
e.setPerson(p);
|
||||
e.setAddress(a);
|
||||
|
||||
FileOutputStream fileOutputStream = new FileOutputStream("yofile2.txt");
|
||||
ObjectOutputStream objectOutputStream = new ObjectOutputStream(fileOutputStream);
|
||||
objectOutputStream.writeObject(e);
|
||||
objectOutputStream.flush();
|
||||
objectOutputStream.close();
|
||||
|
||||
FileInputStream fileInputStream = new FileInputStream("yofile2.txt");
|
||||
ObjectInputStream objectInputStream = new ObjectInputStream(fileInputStream);
|
||||
Employee e2 = (Employee) objectInputStream.readObject();
|
||||
objectInputStream.close();
|
||||
|
||||
assertTrue(e2.getPerson().getAge() == e.getPerson().getAge());
|
||||
assertTrue(e2.getAddress().getHouseNumber() == (e.getAddress().getHouseNumber()));
|
||||
}
|
||||
|
||||
}
|
||||
+1
-6
@@ -4,13 +4,8 @@ import static org.junit.Assert.fail;
|
||||
import org.junit.Test;
|
||||
|
||||
public class CyclicDependancyManualTest {
|
||||
@Test
|
||||
@Test(expected = StackOverflowError.class)
|
||||
public void whenInstanciatingClassOne_thenThrowsException() {
|
||||
try {
|
||||
ClassOne obj = new ClassOne();
|
||||
fail();
|
||||
} catch (StackOverflowError soe) {
|
||||
soe.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+3
-8
@@ -6,7 +6,7 @@ import org.junit.Test;
|
||||
|
||||
public class InfiniteRecursionWithTerminationConditionManualTest {
|
||||
@Test
|
||||
public void givenPositiveIntNoOne_whenCalcFact_thenThrowsException() {
|
||||
public void givenPositiveIntNoOne_whenCalcFact_thenCorrectlyCalc() {
|
||||
int numToCalcFactorial = 1;
|
||||
InfiniteRecursionWithTerminationCondition irtc = new InfiniteRecursionWithTerminationCondition();
|
||||
|
||||
@@ -14,23 +14,18 @@ public class InfiniteRecursionWithTerminationConditionManualTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenPositiveIntGtOne_whenCalcFact_thenThrowsException() {
|
||||
public void givenPositiveIntGtOne_whenCalcFact_thenCorrectlyCalc() {
|
||||
int numToCalcFactorial = 5;
|
||||
InfiniteRecursionWithTerminationCondition irtc = new InfiniteRecursionWithTerminationCondition();
|
||||
|
||||
assertEquals(120, irtc.calculateFactorial(numToCalcFactorial));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Test(expected = StackOverflowError.class)
|
||||
public void givenNegativeInt_whenCalcFact_thenThrowsException() {
|
||||
try {
|
||||
int numToCalcFactorial = -1;
|
||||
InfiniteRecursionWithTerminationCondition irtc = new InfiniteRecursionWithTerminationCondition();
|
||||
|
||||
irtc.calculateFactorial(numToCalcFactorial);
|
||||
fail();
|
||||
} catch (StackOverflowError soe) {
|
||||
soe.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
package com.baeldung.stackoverflowerror;
|
||||
|
||||
import static junit.framework.TestCase.assertEquals;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class RecursionWithCorrectTerminationConditionManualTest {
|
||||
@Test
|
||||
public void givenNegativeInt_whenCalcFact_thenCorrectlyCalc() {
|
||||
int numToCalcFactorial = -1;
|
||||
RecursionWithCorrectTerminationCondition rctc = new RecursionWithCorrectTerminationCondition();
|
||||
|
||||
assertEquals(1, rctc.calculateFactorial(numToCalcFactorial));
|
||||
}
|
||||
}
|
||||
+3
-6
@@ -7,8 +7,7 @@ public class UnintendedInfiniteRecursionManualTest {
|
||||
@Test(expected = StackOverflowError.class)
|
||||
public void givenPositiveIntNoOne_whenCalFact_thenThrowsException() {
|
||||
int numToCalcFactorial= 1;
|
||||
UnintendedInfiniteRecursion uir
|
||||
= new UnintendedInfiniteRecursion();
|
||||
UnintendedInfiniteRecursion uir = new UnintendedInfiniteRecursion();
|
||||
|
||||
uir.calculateFactorial(numToCalcFactorial);
|
||||
}
|
||||
@@ -16,8 +15,7 @@ public class UnintendedInfiniteRecursionManualTest {
|
||||
@Test(expected = StackOverflowError.class)
|
||||
public void givenPositiveIntGtOne_whenCalcFact_thenThrowsException() {
|
||||
int numToCalcFactorial= 2;
|
||||
UnintendedInfiniteRecursion uir
|
||||
= new UnintendedInfiniteRecursion();
|
||||
UnintendedInfiniteRecursion uir = new UnintendedInfiniteRecursion();
|
||||
|
||||
uir.calculateFactorial(numToCalcFactorial);
|
||||
}
|
||||
@@ -25,8 +23,7 @@ public class UnintendedInfiniteRecursionManualTest {
|
||||
@Test(expected = StackOverflowError.class)
|
||||
public void givenNegativeInt_whenCalcFact_thenThrowsException() {
|
||||
int numToCalcFactorial= -1;
|
||||
UnintendedInfiniteRecursion uir
|
||||
= new UnintendedInfiniteRecursion();
|
||||
UnintendedInfiniteRecursion uir = new UnintendedInfiniteRecursion();
|
||||
|
||||
uir.calculateFactorial(numToCalcFactorial);
|
||||
}
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@ import java.util.stream.Stream;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class InfiniteStreamTest {
|
||||
public class InfiniteStreamUnitTest {
|
||||
|
||||
@Test
|
||||
public void givenInfiniteStream_whenUseIntermediateLimitMethod_thenShouldTerminateInFiniteTime() {
|
||||
+1
-1
@@ -9,7 +9,7 @@ import org.junit.Test;
|
||||
|
||||
import com.baeldung.string.JoinerSplitter;
|
||||
|
||||
public class JoinerSplitterTest {
|
||||
public class JoinerSplitterUnitTest {
|
||||
|
||||
@Test
|
||||
public void provided_array_convert_to_stream_and_convert_to_string() {
|
||||
@@ -1,32 +0,0 @@
|
||||
package com.baeldung.string;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
|
||||
public class SplitTest {
|
||||
|
||||
@Test
|
||||
public void givenString_whenSplit_thenRetrunsArray_through_JavaLangString() {
|
||||
assertArrayEquals("split by comma", Arrays.asList("peter", "james", "thomas").toArray(), "peter,james,thomas".split(","));
|
||||
assertArrayEquals("split by whitespace", Arrays.asList("car", "jeep", "scooter").toArray(), "car jeep scooter".split(" "));
|
||||
assertArrayEquals("split by hyphen", Arrays.asList("1", "120", "232323").toArray(), "1-120-232323".split("-"));
|
||||
assertArrayEquals("split by dot", Arrays.asList("192", "168", "1", "178").toArray(), "192.168.1.178".split("\\."));
|
||||
assertArrayEquals("split by a regex", Arrays.asList("b", "a", "e", "l", "d", "u", "n", "g").toArray(),
|
||||
"b a, e, l.d u, n g".split("\\s+|,\\s*|\\.\\s*"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenString_whenSplit_thenRetrunsArray_through_StringUtils() {
|
||||
StringUtils.split("car jeep scooter");
|
||||
|
||||
assertArrayEquals("split by whitespace", Arrays.asList("car", "jeep", "scooter").toArray(), StringUtils.split("car jeep scooter"));
|
||||
assertArrayEquals("split by space, extra spaces ignored", Arrays.asList("car", "jeep", "scooter").toArray(),
|
||||
StringUtils.split("car jeep scooter"));
|
||||
assertArrayEquals("split by colon", Arrays.asList("car", "jeep", "scooter").toArray(), StringUtils.split("car:jeep:scooter", ":"));
|
||||
assertArrayEquals("split by dot", Arrays.asList("car", "jeep", "scooter").toArray(), StringUtils.split("car.jeep.scooter", "."));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package com.baeldung.string;
|
||||
|
||||
import com.google.common.base.Splitter;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.assertj.core.util.Lists;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class SplitUnitTest {
|
||||
|
||||
@Test
|
||||
public void givenString_whenSplit_thenReturnsArray_through_JavaLangString() {
|
||||
assertThat("peter,james,thomas".split(","))
|
||||
.containsExactly("peter", "james", "thomas");
|
||||
|
||||
assertThat("car jeep scooter".split(" "))
|
||||
.containsExactly("car", "jeep", "scooter");
|
||||
|
||||
assertThat("1-120-232323".split("-"))
|
||||
.containsExactly("1", "120", "232323");
|
||||
|
||||
assertThat("192.168.1.178".split("\\."))
|
||||
.containsExactly("192", "168", "1", "178");
|
||||
|
||||
assertThat("b a, e, l.d u, n g".split("\\s+|,\\s*|\\.\\s*"))
|
||||
.containsExactly("b", "a", "e", "l", "d", "u", "n", "g");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenString_whenSplit_thenReturnsArray_through_StringUtils() {
|
||||
StringUtils.split("car jeep scooter");
|
||||
|
||||
assertThat(StringUtils.split("car jeep scooter"))
|
||||
.containsExactly("car", "jeep", "scooter");
|
||||
|
||||
assertThat(StringUtils.split("car jeep scooter"))
|
||||
.containsExactly("car", "jeep", "scooter");
|
||||
|
||||
assertThat(StringUtils.split("car:jeep:scooter", ":"))
|
||||
.containsExactly("car", "jeep", "scooter");
|
||||
|
||||
assertThat(StringUtils.split("car.jeep.scooter", "."))
|
||||
.containsExactly("car", "jeep", "scooter");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenString_whenSplit_thenReturnsIterable_Splitter() {
|
||||
//given
|
||||
Iterable<String> result = Splitter.on(',').trimResults().omitEmptyStrings().split("car,jeep,, scooter");
|
||||
List<String> resultList = Lists.newArrayList(result);
|
||||
|
||||
assertThat(resultList)
|
||||
.containsExactly("car", "jeep", "scooter");
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -5,7 +5,7 @@ import static org.junit.Assert.assertNotEquals;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.junit.Test;
|
||||
|
||||
public class StringHelperTest {
|
||||
public class StringHelperUnitTest {
|
||||
|
||||
public static final String TEST_STRING = "abcdef";
|
||||
public static final String NULL_STRING = null;
|
||||
+1
-1
@@ -7,7 +7,7 @@ import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class TokenizerTest {
|
||||
public class TokenizerUnitTest {
|
||||
|
||||
private final MyTokenizer myTokenizer = new MyTokenizer();
|
||||
private final List<String> expectedTokensForString = Arrays.asList("Welcome", "to", "baeldung.com");
|
||||
+2
-2
@@ -12,9 +12,9 @@ import java.util.concurrent.atomic.AtomicInteger;
|
||||
import static junit.framework.TestCase.assertEquals;
|
||||
|
||||
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
||||
public class SynchronousQueueTest {
|
||||
public class SynchronousQueueUnitTest {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(SynchronousQueueTest.class);
|
||||
private static final Logger LOG = LoggerFactory.getLogger(SynchronousQueueUnitTest.class);
|
||||
|
||||
|
||||
@Test
|
||||
+1
-1
@@ -14,7 +14,7 @@ import java.util.stream.IntStream;
|
||||
import static junit.framework.Assert.assertTrue;
|
||||
import static junit.framework.TestCase.assertEquals;
|
||||
|
||||
public class UnsafeTest {
|
||||
public class UnsafeUnitTest {
|
||||
|
||||
private Unsafe unsafe;
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@ import java.util.concurrent.TimeUnit;
|
||||
import static com.jayway.awaitility.Awaitility.await;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class WeakHashMapTest {
|
||||
public class WeakHashMapUnitTest {
|
||||
|
||||
@Test
|
||||
public void givenWeakHashMap_whenCacheValueThatHasNoReferenceToIt_GCShouldReclaimThatObject() {
|
||||
@@ -36,7 +36,7 @@ public class JavaInputStreamToXUnitTest {
|
||||
|
||||
final StringBuilder textBuilder = new StringBuilder();
|
||||
try (Reader reader = new BufferedReader(new InputStreamReader(inputStream, Charset.forName(StandardCharsets.UTF_8.name())))) {
|
||||
int c = 0;
|
||||
int c;
|
||||
while ((c = reader.read()) != -1) {
|
||||
textBuilder.append((char) c);
|
||||
}
|
||||
@@ -50,7 +50,7 @@ public class JavaInputStreamToXUnitTest {
|
||||
final InputStream inputStream = new ByteArrayInputStream(originalString.getBytes()); // exampleString.getBytes(StandardCharsets.UTF_8);
|
||||
|
||||
// When
|
||||
String text = null;
|
||||
String text;
|
||||
try (Scanner scanner = new Scanner(inputStream, StandardCharsets.UTF_8.name())) {
|
||||
text = scanner.useDelimiter("\\A").next();
|
||||
}
|
||||
@@ -81,7 +81,7 @@ public class JavaInputStreamToXUnitTest {
|
||||
final InputStream inputStream = new ByteArrayInputStream(originalString.getBytes());
|
||||
|
||||
// When
|
||||
String text = null;
|
||||
String text;
|
||||
try (final Reader reader = new InputStreamReader(inputStream)) {
|
||||
text = CharStreams.toString(reader);
|
||||
}
|
||||
@@ -210,5 +210,24 @@ public class JavaInputStreamToXUnitTest {
|
||||
|
||||
FileUtils.copyInputStreamToFile(initialStream, targetFile);
|
||||
}
|
||||
|
||||
@Test
|
||||
public final void givenUsingPlainJava_whenConvertingAnInputStreamToString_thenCorrect() throws IOException {
|
||||
String originalString = randomAlphabetic(8);
|
||||
InputStream inputStream = new ByteArrayInputStream(originalString.getBytes());
|
||||
|
||||
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
|
||||
int nRead;
|
||||
byte[] data = new byte[1024];
|
||||
while ((nRead = inputStream.read(data, 0, data.length)) != -1) {
|
||||
buffer.write(data, 0, nRead);
|
||||
}
|
||||
|
||||
buffer.flush();
|
||||
byte[] byteArray = buffer.toByteArray();
|
||||
|
||||
String text = new String(byteArray, StandardCharsets.UTF_8);
|
||||
assertThat(text, equalTo(originalString));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+14
-55
@@ -1,34 +1,20 @@
|
||||
package org.baeldung.java.sorting;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import com.google.common.primitives.Ints;
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.google.common.primitives.Ints;
|
||||
import java.util.*;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
public class JavaSorting {
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class JavaSortingUnitTest {
|
||||
|
||||
private int[] toSort;
|
||||
private int[] sortedInts;
|
||||
private int[] sortedRangeInts;
|
||||
// private Integer [] integers;
|
||||
// private Integer [] sortedIntegers;
|
||||
// private List<Integer> integersList;
|
||||
// private List<Integer> sortedIntegersList;
|
||||
private Employee[] employees;
|
||||
private Employee[] employeesSorted;
|
||||
private Employee[] employeesSortedByAge;
|
||||
@@ -41,19 +27,11 @@ public class JavaSorting {
|
||||
sortedInts = new int[] { 1, 5, 7, 66, 88, 89, 123, 200, 255 };
|
||||
sortedRangeInts = new int[] { 5, 1, 89, 7, 88, 200, 255, 123, 66 };
|
||||
|
||||
// integers = new Integer[]
|
||||
// { 5, 1, 89, 255, 7, 88, 200, 123, 66 };
|
||||
// sortedIntegers = new Integer[]
|
||||
// {1, 5, 7, 66, 88, 89, 123, 200, 255};
|
||||
//
|
||||
// integersList = Arrays.asList(new Integer[] { 5, 1, 89, 255, 7, 88, 200, 123, 66 });
|
||||
// sortedIntegersList = Arrays.asList(new Integer[] {1, 5, 7, 66, 88, 89, 123, 200, 255});
|
||||
|
||||
employees = new Employee[] { new Employee("John", 23, 5000), new Employee("Steve", 26, 6000), new Employee("Frank", 33, 7000), new Employee("Earl", 43, 10000), new Employee("Jessica", 23, 4000), new Employee("Pearl", 33, 6000) };
|
||||
employeesSorted = new Employee[] { new Employee("Earl", 43, 10000), new Employee("Frank", 33, 70000), new Employee("Jessica", 23, 4000), new Employee("John", 23, 5000), new Employee("Pearl", 33, 4000), new Employee("Steve", 26, 6000) };
|
||||
employeesSortedByAge = new Employee[] { new Employee("John", 23, 5000), new Employee("Jessica", 23, 4000), new Employee("Steve", 26, 6000), new Employee("Frank", 33, 70000), new Employee("Pearl", 33, 4000), new Employee("Earl", 43, 10000) };
|
||||
|
||||
HashMap<Integer, String> map = new HashMap<>();
|
||||
map = new HashMap<>();
|
||||
map.put(55, "John");
|
||||
map.put(22, "Apple");
|
||||
map.put(66, "Earl");
|
||||
@@ -73,12 +51,7 @@ public class JavaSorting {
|
||||
@Test
|
||||
public void givenIntegerArray_whenUsingSort_thenSortedArray() {
|
||||
Integer[] integers = ArrayUtils.toObject(toSort);
|
||||
Arrays.sort(integers, new Comparator<Integer>() {
|
||||
@Override
|
||||
public int compare(Integer a, Integer b) {
|
||||
return a - b;
|
||||
}
|
||||
});
|
||||
Arrays.sort(integers, Comparator.comparingInt(a -> a));
|
||||
|
||||
assertTrue(Arrays.equals(integers, ArrayUtils.toObject(sortedInts)));
|
||||
}
|
||||
@@ -86,9 +59,7 @@ public class JavaSorting {
|
||||
@Test
|
||||
public void givenArray_whenUsingSortWithLambdas_thenSortedArray() {
|
||||
Integer[] integersToSort = ArrayUtils.toObject(toSort);
|
||||
Arrays.sort(integersToSort, (a, b) -> {
|
||||
return a - b;
|
||||
});
|
||||
Arrays.sort(integersToSort, Comparator.comparingInt(a -> a));
|
||||
|
||||
assertTrue(Arrays.equals(integersToSort, ArrayUtils.toObject(sortedInts)));
|
||||
}
|
||||
@@ -136,12 +107,7 @@ public class JavaSorting {
|
||||
Integer[] sortedKeys = new Integer[] { 6, 12, 22, 55, 66, 77 };
|
||||
|
||||
List<Map.Entry<Integer, String>> entries = new ArrayList<>(map.entrySet());
|
||||
Collections.sort(entries, new Comparator<Entry<Integer, String>>() {
|
||||
@Override
|
||||
public int compare(Entry<Integer, String> o1, Entry<Integer, String> o2) {
|
||||
return o1.getKey().compareTo(o2.getKey());
|
||||
}
|
||||
});
|
||||
entries.sort(Comparator.comparing(Entry::getKey));
|
||||
HashMap<Integer, String> sortedMap = new LinkedHashMap<>();
|
||||
for (Map.Entry<Integer, String> entry : entries) {
|
||||
sortedMap.put(entry.getKey(), entry.getValue());
|
||||
@@ -155,12 +121,7 @@ public class JavaSorting {
|
||||
String[] sortedValues = new String[] { "Apple", "Earl", "George", "John", "Pearl", "Rocky" };
|
||||
|
||||
List<Map.Entry<Integer, String>> entries = new ArrayList<>(map.entrySet());
|
||||
Collections.sort(entries, new Comparator<Entry<Integer, String>>() {
|
||||
@Override
|
||||
public int compare(Entry<Integer, String> o1, Entry<Integer, String> o2) {
|
||||
return o1.getValue().compareTo(o2.getValue());
|
||||
}
|
||||
});
|
||||
entries.sort(Comparator.comparing(Entry::getValue));
|
||||
HashMap<Integer, String> sortedMap = new LinkedHashMap<>();
|
||||
for (Map.Entry<Integer, String> entry : entries) {
|
||||
sortedMap.put(entry.getKey(), entry.getValue());
|
||||
@@ -172,12 +133,10 @@ public class JavaSorting {
|
||||
@Test
|
||||
public void givenSet_whenUsingSort_thenSortedSet() {
|
||||
HashSet<Integer> integersSet = new LinkedHashSet<>(Ints.asList(toSort));
|
||||
HashSet<Integer> descSortedIntegersSet = new LinkedHashSet<>(Arrays.asList(new Integer[] { 255, 200, 123, 89, 88, 66, 7, 5, 1 }));
|
||||
HashSet<Integer> descSortedIntegersSet = new LinkedHashSet<>(Arrays.asList(255, 200, 123, 89, 88, 66, 7, 5, 1));
|
||||
|
||||
ArrayList<Integer> list = new ArrayList<Integer>(integersSet);
|
||||
Collections.sort(list, (i1, i2) -> {
|
||||
return i2 - i1;
|
||||
});
|
||||
ArrayList<Integer> list = new ArrayList<>(integersSet);
|
||||
list.sort((i1, i2) -> i2 - i1);
|
||||
integersSet = new LinkedHashSet<>(list);
|
||||
|
||||
assertTrue(Arrays.equals(integersSet.toArray(), descSortedIntegersSet.toArray()));
|
||||
Reference in New Issue
Block a user