Merge branch 'master' of https://github.com/eugenp/tutorials into BAEL-4883
This commit is contained in:
@@ -20,19 +20,16 @@
|
||||
<version>${org.assertj.core.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-collections4</artifactId>
|
||||
<version>${commons-collections4.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
<version>${guava.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.squareup.retrofit2</groupId>
|
||||
<artifactId>retrofit</artifactId>
|
||||
@@ -43,13 +40,11 @@
|
||||
<artifactId>converter-jackson</artifactId>
|
||||
<version>${retrofit.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
<version>${commons.lang3.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>pl.pragmatists</groupId>
|
||||
<artifactId>JUnitParams</artifactId>
|
||||
|
||||
@@ -39,7 +39,6 @@
|
||||
<artifactId>junit-platform-commons</artifactId>
|
||||
<version>${junit.platform.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.assertj</groupId>
|
||||
<artifactId>assertj-core</artifactId>
|
||||
|
||||
@@ -20,4 +20,4 @@
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
</project>
|
||||
@@ -37,4 +37,4 @@
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
</project>
|
||||
@@ -52,4 +52,4 @@
|
||||
<httpclient.version>4.5.2</httpclient.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
</project>
|
||||
@@ -107,4 +107,4 @@
|
||||
<cargo-maven2-plugin.version>1.6.1</cargo-maven2-plugin.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
</project>
|
||||
+1
-1
@@ -38,4 +38,4 @@
|
||||
<cxf.version>3.1.8</cxf.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
</project>
|
||||
@@ -18,4 +18,4 @@
|
||||
<module>sse-jaxrs-client</module>
|
||||
</modules>
|
||||
|
||||
</project>
|
||||
</project>
|
||||
@@ -14,7 +14,6 @@
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>javax.ws.rs</groupId>
|
||||
<artifactId>javax.ws.rs-api</artifactId>
|
||||
@@ -33,7 +32,6 @@
|
||||
<version>${bind-api.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
@@ -85,4 +83,4 @@
|
||||
<bind-api.version>1.0</bind-api.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
</project>
|
||||
@@ -183,7 +183,6 @@
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
<!-- meecrowave -->
|
||||
<plugin>
|
||||
<groupId>org.apache.meecrowave</groupId>
|
||||
@@ -216,4 +215,4 @@
|
||||
<solr.solr-solrj.version>6.4.0</solr.solr-solrj.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
</project>
|
||||
@@ -25,4 +25,5 @@
|
||||
<geode.core>1.6.0</geode.core>
|
||||
<rocketmq.version>2.0.4</rocketmq.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
@@ -91,7 +91,7 @@
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<repositories>
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>SparkPackagesRepo</id>
|
||||
<url>https://repos.spark-packages.org</url>
|
||||
|
||||
@@ -77,7 +77,6 @@
|
||||
<optimize>true</optimize>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
@@ -88,7 +87,6 @@
|
||||
</systemPropertyVariables>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<!-- Run the application using "mvn jetty:run" -->
|
||||
<plugin>
|
||||
<groupId>org.mortbay.jetty</groupId>
|
||||
@@ -119,7 +117,6 @@
|
||||
<id>jboss</id>
|
||||
<url>http://repository.jboss.org/nexus/content/groups/public/</url>
|
||||
</repository>
|
||||
|
||||
<!-- This repository is only needed when the Tapestry version is a preview release, rather than
|
||||
a final release. -->
|
||||
<repository>
|
||||
|
||||
+1
-1
@@ -68,4 +68,4 @@
|
||||
<asciidoctorj-pdf.plugin.version>1.5.0-alpha.15</asciidoctorj-pdf.plugin.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
</project>
|
||||
+1
-1
@@ -31,4 +31,4 @@
|
||||
<atomix-all.version>1.0.0-rc9</atomix-all.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
</project>
|
||||
+1
-1
@@ -20,4 +20,4 @@
|
||||
<module>todo-reminder/ToDoFunction</module>
|
||||
</modules>
|
||||
|
||||
</project>
|
||||
</project>
|
||||
@@ -1,4 +1,5 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>helloworld</groupId>
|
||||
@@ -6,10 +7,6 @@
|
||||
<version>1.0</version>
|
||||
<packaging>jar</packaging>
|
||||
<name>ToDoFunction</name>
|
||||
<properties>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
@@ -18,9 +15,9 @@
|
||||
<version>1.2.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.amazonaws</groupId>
|
||||
<artifactId>aws-lambda-java-events</artifactId>
|
||||
<version>3.6.0</version>
|
||||
<groupId>com.amazonaws</groupId>
|
||||
<artifactId>aws-lambda-java-events</artifactId>
|
||||
<version>3.6.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>uk.org.webcompere</groupId>
|
||||
@@ -58,10 +55,10 @@
|
||||
<version>5.0.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.13.1</version>
|
||||
<scope>test</scope>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.13.1</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>uk.org.webcompere</groupId>
|
||||
@@ -84,22 +81,28 @@
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.2.4</version>
|
||||
<configuration>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.2.4</version>
|
||||
<configuration>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
@@ -93,4 +93,5 @@
|
||||
<spring.version>2.2.1.RELEASE</spring.version>
|
||||
<awssdk.version>2.10.27</awssdk.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
@@ -83,7 +83,6 @@
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
<version>${assembly.plugin.version}</version>
|
||||
|
||||
@@ -48,13 +48,11 @@
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>${maven-shade-plugin.version}</version>
|
||||
</plugin>
|
||||
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project
|
||||
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
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>
|
||||
@@ -20,4 +19,4 @@
|
||||
<module>cf-uaa-oauth2-resource-server</module>
|
||||
</modules>
|
||||
|
||||
</project>
|
||||
</project>
|
||||
@@ -173,4 +173,4 @@
|
||||
<groovy.compiler.version>3.3.0-01</groovy.compiler.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
</project>
|
||||
@@ -1,49 +1,60 @@
|
||||
<?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-12</artifactId>
|
||||
<version>0.1.0-SNAPSHOT</version>
|
||||
<name>core-java-12</name>
|
||||
<packaging>jar</packaging>
|
||||
<url>http://maven.apache.org</url>
|
||||
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-12</artifactId>
|
||||
<version>0.1.0-SNAPSHOT</version>
|
||||
<name>core-java-12</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>
|
||||
<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>
|
||||
</dependencies>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.assertj</groupId>
|
||||
<artifactId>assertj-core</artifactId>
|
||||
<version>${assertj.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-io</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
<version>2.11.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>${maven-compiler-plugin.version}</version>
|
||||
<configuration>
|
||||
<source>${maven.compiler.source.version}</source>
|
||||
<target>${maven.compiler.target.version}</target>
|
||||
<compilerArgs>--enable-preview</compilerArgs>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>${maven-compiler-plugin.version}</version>
|
||||
<configuration>
|
||||
<source>${maven.compiler.source.version}</source>
|
||||
<target>${maven.compiler.target.version}</target>
|
||||
<compilerArgs>--enable-preview</compilerArgs>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<configuration>
|
||||
<argLine>--enable-preview</argLine>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source.version>12</maven.compiler.source.version>
|
||||
<maven.compiler.target.version>12</maven.compiler.target.version>
|
||||
<assertj.version>3.6.1</assertj.version>
|
||||
</properties>
|
||||
<properties>
|
||||
<maven.compiler.source.version>12</maven.compiler.source.version>
|
||||
<maven.compiler.target.version>12</maven.compiler.target.version>
|
||||
<assertj.version>3.6.1</assertj.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
+88
@@ -0,0 +1,88 @@
|
||||
package com.baeldung.file.content.comparison;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.RandomAccessFile;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.MappedByteBuffer;
|
||||
import java.nio.channels.FileChannel;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
public class CompareFileContents {
|
||||
|
||||
public static long filesCompareByByte(Path path1, Path path2) throws IOException {
|
||||
|
||||
if (path1.getFileSystem()
|
||||
.provider()
|
||||
.isSameFile(path1, path2)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
try (BufferedInputStream fis1 = new BufferedInputStream(new FileInputStream(path1.toFile()));
|
||||
BufferedInputStream fis2 = new BufferedInputStream(new FileInputStream(path2.toFile()))) {
|
||||
int ch = 0;
|
||||
long pos = 1;
|
||||
while ((ch = fis1.read()) != -1) {
|
||||
if (ch != fis2.read()) {
|
||||
return pos;
|
||||
}
|
||||
pos++;
|
||||
}
|
||||
if (fis2.read() == -1) {
|
||||
return -1;
|
||||
} else {
|
||||
return pos;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static long filesCompareByLine(Path path1, Path path2) throws IOException {
|
||||
|
||||
if (path1.getFileSystem()
|
||||
.provider()
|
||||
.isSameFile(path1, path2)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
try (BufferedReader bf1 = Files.newBufferedReader(path1);
|
||||
BufferedReader bf2 = Files.newBufferedReader(path2)) {
|
||||
|
||||
long lineNumber = 1;
|
||||
String line1 = "", line2 = "";
|
||||
while ((line1 = bf1.readLine()) != null) {
|
||||
line2 = bf2.readLine();
|
||||
if (line2 == null || !line1.equals(line2)) {
|
||||
return lineNumber;
|
||||
}
|
||||
lineNumber++;
|
||||
}
|
||||
if (bf2.readLine() == null) {
|
||||
return -1;
|
||||
} else {
|
||||
return lineNumber;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean compareByMemoryMappedFiles(Path path1, Path path2) throws IOException {
|
||||
|
||||
try (RandomAccessFile randomAccessFile1 = new RandomAccessFile(path1.toFile(), "r");
|
||||
RandomAccessFile randomAccessFile2 = new RandomAccessFile(path2.toFile(), "r")) {
|
||||
|
||||
FileChannel ch1 = randomAccessFile1.getChannel();
|
||||
FileChannel ch2 = randomAccessFile2.getChannel();
|
||||
if (ch1.size() != ch2.size()) {
|
||||
|
||||
return false;
|
||||
}
|
||||
long size = ch1.size();
|
||||
MappedByteBuffer m1 = ch1.map(FileChannel.MapMode.READ_ONLY, 0L, size);
|
||||
MappedByteBuffer m2 = ch2.map(FileChannel.MapMode.READ_ONLY, 0L, size);
|
||||
|
||||
return m1.equals(m2);
|
||||
}
|
||||
}
|
||||
}
|
||||
+88
@@ -0,0 +1,88 @@
|
||||
package com.baeldung.file.content.comparison;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.Reader;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class CampareFileContentsApacheIOUnitTest {
|
||||
|
||||
public static Path path1 = null;
|
||||
public static Path path2 = null;
|
||||
|
||||
@BeforeAll
|
||||
public static void setup() throws IOException {
|
||||
|
||||
path1 = Files.createTempFile("file1Test", ".txt");
|
||||
path2 = Files.createTempFile("file2Test", ".txt");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenFilesIdentical_thenReturnTrue() throws IOException {
|
||||
|
||||
InputStream inputStream1 = new FileInputStream(path1.toFile());
|
||||
InputStream inputStream2 = new FileInputStream(path2.toFile());
|
||||
|
||||
Files.writeString(path1, "testing line 1" + System.lineSeparator() + "line 2");
|
||||
Files.writeString(path2, "testing line 1" + System.lineSeparator() + "line 2");
|
||||
|
||||
assertTrue(IOUtils.contentEquals(inputStream1, inputStream2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenFilesDifferent_thenReturnFalse() throws IOException {
|
||||
|
||||
InputStream inputStream1 = new FileInputStream(path1.toFile());
|
||||
InputStream inputStream2 = new FileInputStream(path2.toFile());
|
||||
|
||||
Files.writeString(path1, "testing line " + System.lineSeparator() + "line 2");
|
||||
Files.writeString(path2, "testing line 1" + System.lineSeparator() + "line 2");
|
||||
|
||||
assertFalse(IOUtils.contentEquals(inputStream1, inputStream2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenFilesIdenticalIgnoreEOF_thenReturnTrue() throws IOException {
|
||||
|
||||
Files.writeString(path1, "testing line 1 \n line 2");
|
||||
Files.writeString(path2, "testing line 1 \r\n line 2");
|
||||
|
||||
Reader reader1 = new BufferedReader(new FileReader(path1.toFile()));
|
||||
Reader reader2 = new BufferedReader(new FileReader(path2.toFile()));
|
||||
|
||||
assertTrue(IOUtils.contentEqualsIgnoreEOL(reader1, reader2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenFilesNotIdenticalIgnoreEOF_thenReturnFalse() throws IOException {
|
||||
|
||||
Files.writeString(path1, "testing line \n line 2");
|
||||
Files.writeString(path2, "testing line 1 \r\n line 2");
|
||||
|
||||
Reader reader1 = new BufferedReader(new FileReader(path1.toFile()));
|
||||
Reader reader2 = new BufferedReader(new FileReader(path2.toFile()));
|
||||
|
||||
assertFalse(IOUtils.contentEqualsIgnoreEOL(reader1, reader2));
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
public static void shutDown() {
|
||||
|
||||
path1.toFile()
|
||||
.deleteOnExit();
|
||||
path2.toFile()
|
||||
.deleteOnExit();
|
||||
}
|
||||
}
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
package com.baeldung.file.content.comparison;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class CompareByMemoryMappedFilesUnitTest {
|
||||
|
||||
public static Path path1 = null;
|
||||
public static Path path2 = null;
|
||||
|
||||
@BeforeAll
|
||||
public static void setup() throws IOException {
|
||||
|
||||
path1 = Files.createTempFile("file1Test", ".txt");
|
||||
path2 = Files.createTempFile("file2Test", ".txt");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenFilesIdentical_thenReturnTrue() throws IOException {
|
||||
|
||||
Files.writeString(path1, "testing line 1" + System.lineSeparator() + "line 2");
|
||||
Files.writeString(path2, "testing line 1" + System.lineSeparator() + "line 2");
|
||||
|
||||
assertTrue(CompareFileContents.compareByMemoryMappedFiles(path1, path2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenFilesDifferent_thenReturnFalse() throws IOException {
|
||||
|
||||
Files.writeString(path1, "testing line " + System.lineSeparator() + "line 2");
|
||||
Files.writeString(path2, "testing line 1" + System.lineSeparator() + "line 2");
|
||||
|
||||
assertFalse(CompareFileContents.compareByMemoryMappedFiles(path1, path2));
|
||||
}
|
||||
}
|
||||
+96
@@ -0,0 +1,96 @@
|
||||
package com.baeldung.file.content.comparison;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class CompareFileContentsByBytesUnitTest {
|
||||
|
||||
public static Path path1 = null;
|
||||
public static Path path2 = null;
|
||||
|
||||
@BeforeAll
|
||||
public static void setup() throws IOException {
|
||||
|
||||
path1 = Files.createTempFile("file1Test", ".txt");
|
||||
path2 = Files.createTempFile("file2Test", ".txt");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenFirstFileShorter_thenPositionInSecondFile() throws IOException {
|
||||
|
||||
Files.writeString(path1, "testing");
|
||||
Files.writeString(path2, "testing1");
|
||||
|
||||
assertEquals(8, CompareFileContents.filesCompareByByte(path1, path2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSecondFileShorter_thenPositionInFirstFile() throws IOException {
|
||||
|
||||
Files.writeString(path1, "testing1");
|
||||
Files.writeString(path2, "testing");
|
||||
|
||||
assertEquals(8, CompareFileContents.filesCompareByByte(path1, path2));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenFilesIdentical_thenSuccess() throws IOException {
|
||||
|
||||
Files.writeString(path1, "testing");
|
||||
Files.writeString(path2, "testing");
|
||||
|
||||
assertEquals(-1, CompareFileContents.filesCompareByByte(path1, path2));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenFilesDifferent_thenPosition() throws IOException {
|
||||
|
||||
Files.writeString(path1, "tesXing");
|
||||
Files.writeString(path2, "testing");
|
||||
|
||||
assertEquals(4, CompareFileContents.filesCompareByByte(path1, path2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenBothFilesEmpty_thenEqual() throws IOException {
|
||||
|
||||
Files.writeString(path1, "");
|
||||
Files.writeString(path2, "");
|
||||
|
||||
assertEquals(-1, CompareFileContents.filesCompareByByte(path1, path2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenFirstEmpty_thenPositionFirst() throws IOException {
|
||||
|
||||
Files.writeString(path1, "");
|
||||
Files.writeString(path2, "test");
|
||||
|
||||
assertEquals(1, CompareFileContents.filesCompareByByte(path1, path2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSecondEmpty_thenPositionFirst() throws IOException {
|
||||
|
||||
Files.writeString(path1, "test");
|
||||
Files.writeString(path2, "");
|
||||
|
||||
assertEquals(1, CompareFileContents.filesCompareByByte(path1, path2));
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
public static void shutDown() {
|
||||
|
||||
path1.toFile().deleteOnExit();
|
||||
path2.toFile().deleteOnExit();
|
||||
}
|
||||
}
|
||||
+94
@@ -0,0 +1,94 @@
|
||||
package com.baeldung.file.content.comparison;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class CompareFileContentsByLinesUnitTest {
|
||||
|
||||
public static Path path1 = null;
|
||||
public static Path path2 = null;
|
||||
|
||||
@BeforeAll
|
||||
public static void setup() throws IOException {
|
||||
|
||||
path1 = Files.createTempFile("file1Test", ".txt");
|
||||
path2 = Files.createTempFile("file2Test", ".txt");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenFirstFileShorter_thenLineNumbersFirstFile() throws IOException {
|
||||
|
||||
Files.writeString(path1, "testing line 1");
|
||||
Files.writeString(path2, "testing1 line 1" + System.lineSeparator() + "line 2");
|
||||
|
||||
assertEquals(1, CompareFileContents.filesCompareByLine(path1, path2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSecondFileShorter_thenLineNumbersSecondFile() throws IOException {
|
||||
|
||||
Files.writeString(path1, "testing1 line 1" + System.lineSeparator() + "line 2");
|
||||
Files.writeString(path2, "testing line 1");
|
||||
|
||||
assertEquals(1, CompareFileContents.filesCompareByLine(path1, path2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenFileIdentical_thenLineSuccess() throws IOException {
|
||||
|
||||
Files.writeString(path1, "testing1 line 1" + System.lineSeparator() + "line 2");
|
||||
Files.writeString(path2, "testing1 line 1" + System.lineSeparator() + "line 2");
|
||||
|
||||
assertEquals(-1, CompareFileContents.filesCompareByLine(path1, path2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenFilesDifferent_thenLineNumber() throws IOException {
|
||||
|
||||
Files.writeString(path1, "testing1 line 1" + System.lineSeparator() + "line 2");
|
||||
Files.writeString(path2, "testing1 line 1" + System.lineSeparator() + "linX 2");
|
||||
|
||||
assertEquals(2, CompareFileContents.filesCompareByLine(path1, path2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenBothFilesEmpty_thenEqual() throws IOException {
|
||||
|
||||
Files.writeString(path1, "");
|
||||
Files.writeString(path2, "");
|
||||
|
||||
assertEquals(-1, CompareFileContents.filesCompareByByte(path1, path2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenFirstEmpty_thenPositionFirst() throws IOException {
|
||||
|
||||
Files.writeString(path1, "");
|
||||
Files.writeString(path2, "testing1 line 1" + System.lineSeparator() + "line 2");
|
||||
|
||||
assertEquals(1, CompareFileContents.filesCompareByByte(path1, path2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSecondEmpty_thenPositionFirst() throws IOException {
|
||||
|
||||
Files.writeString(path1, "testing1 line 1" + System.lineSeparator() + "line 2");
|
||||
Files.writeString(path2, "");
|
||||
|
||||
assertEquals(1, CompareFileContents.filesCompareByByte(path1, path2));
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
public static void shutDown() {
|
||||
|
||||
path1.toFile().deleteOnExit();
|
||||
path2.toFile().deleteOnExit();
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -1,6 +1,6 @@
|
||||
package java.com.baeldung.newfeatures;
|
||||
package com.baeldung.newfeatures;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.text.NumberFormat;
|
||||
import java.util.Locale;
|
||||
@@ -16,6 +16,6 @@ public class CompactNumbersUnitTest {
|
||||
assertEquals("2.59K", likesShort.format(2592));
|
||||
NumberFormat likesLong = NumberFormat.getCompactNumberInstance(new Locale("en", "US"), NumberFormat.Style.LONG);
|
||||
likesLong.setMaximumFractionDigits(2);
|
||||
assertEquals("2.59 thousand", likesShort.format(2592));
|
||||
assertEquals("2.59 thousand", likesLong.format(2592));
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
package java.com.baeldung.newfeatures;
|
||||
package com.baeldung.newfeatures;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user