aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/java_tools/singlejar/javatests/com/google
diff options
context:
space:
mode:
Diffstat (limited to 'src/java_tools/singlejar/javatests/com/google')
-rw-r--r--src/java_tools/singlejar/javatests/com/google/devtools/build/singlejar/ConcatenateStrategyTest.java29
-rw-r--r--src/java_tools/singlejar/javatests/com/google/devtools/build/singlejar/CopyEntryFilterTest.java13
-rw-r--r--src/java_tools/singlejar/javatests/com/google/devtools/build/singlejar/DefaultJarEntryFilterTest.java40
-rw-r--r--src/java_tools/singlejar/javatests/com/google/devtools/build/singlejar/FakeZipFile.java43
-rw-r--r--src/java_tools/singlejar/javatests/com/google/devtools/build/singlejar/MockSimpleFileSystem.java14
-rw-r--r--src/java_tools/singlejar/javatests/com/google/devtools/build/singlejar/OptionFileExpanderTest.java18
-rw-r--r--src/java_tools/singlejar/javatests/com/google/devtools/build/singlejar/PrefixListPathFilterTest.java14
-rw-r--r--src/java_tools/singlejar/javatests/com/google/devtools/build/singlejar/SingleJarTest.java12
-rw-r--r--src/java_tools/singlejar/javatests/com/google/devtools/build/singlejar/ZipCombinerTest.java99
-rw-r--r--src/java_tools/singlejar/javatests/com/google/devtools/build/zip/ZipReaderTest.java18
-rw-r--r--src/java_tools/singlejar/javatests/com/google/devtools/build/zip/ZipWriterTest.java23
11 files changed, 154 insertions, 169 deletions
diff --git a/src/java_tools/singlejar/javatests/com/google/devtools/build/singlejar/ConcatenateStrategyTest.java b/src/java_tools/singlejar/javatests/com/google/devtools/build/singlejar/ConcatenateStrategyTest.java
index 45c78dd324..1d46ffa8a3 100644
--- a/src/java_tools/singlejar/javatests/com/google/devtools/build/singlejar/ConcatenateStrategyTest.java
+++ b/src/java_tools/singlejar/javatests/com/google/devtools/build/singlejar/ConcatenateStrategyTest.java
@@ -14,20 +14,17 @@
package com.google.devtools.build.singlejar;
+import static com.google.common.truth.Truth.assertThat;
import static java.nio.charset.StandardCharsets.UTF_8;
-import static org.junit.Assert.assertEquals;
-
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.JUnit4;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
-/**
- * Unit tests for {@link ConcatenateStrategy}.
- */
+/** Unit tests for {@link ConcatenateStrategy}. */
@RunWith(JUnit4.class)
public class ConcatenateStrategyTest {
@@ -51,25 +48,25 @@ public class ConcatenateStrategyTest {
@Test
public void testSingleInput() throws IOException {
- assertEquals("a", merge("a"));
- assertEquals("a", mergeNoNewLine("a"));
+ assertThat(merge("a")).isEqualTo("a");
+ assertThat(mergeNoNewLine("a")).isEqualTo("a");
}
@Test
public void testTwoInputs() throws IOException {
- assertEquals("a\nb", merge("a\n", "b"));
- assertEquals("a\nb", mergeNoNewLine("a\n", "b"));
+ assertThat(merge("a\n", "b")).isEqualTo("a\nb");
+ assertThat(mergeNoNewLine("a\n", "b")).isEqualTo("a\nb");
}
@Test
public void testAutomaticNewline() throws IOException {
- assertEquals("a\nb", merge("a", "b"));
- assertEquals("ab", mergeNoNewLine("a", "b"));
+ assertThat(merge("a", "b")).isEqualTo("a\nb");
+ assertThat(mergeNoNewLine("a", "b")).isEqualTo("ab");
}
@Test
public void testAutomaticNewlineAndEmptyFile() throws IOException {
- assertEquals("a\nb", merge("a", "", "b"));
- assertEquals("ab", mergeNoNewLine("a", "", "b"));
+ assertThat(merge("a", "", "b")).isEqualTo("a\nb");
+ assertThat(mergeNoNewLine("a", "", "b")).isEqualTo("ab");
}
}
diff --git a/src/java_tools/singlejar/javatests/com/google/devtools/build/singlejar/CopyEntryFilterTest.java b/src/java_tools/singlejar/javatests/com/google/devtools/build/singlejar/CopyEntryFilterTest.java
index 68bebafb7f..47f4a361d0 100644
--- a/src/java_tools/singlejar/javatests/com/google/devtools/build/singlejar/CopyEntryFilterTest.java
+++ b/src/java_tools/singlejar/javatests/com/google/devtools/build/singlejar/CopyEntryFilterTest.java
@@ -14,18 +14,15 @@
package com.google.devtools.build.singlejar;
-import static org.junit.Assert.assertEquals;
+import static com.google.common.truth.Truth.assertThat;
+import java.io.IOException;
+import java.util.Arrays;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
-import java.io.IOException;
-import java.util.Arrays;
-
-/**
- * Unit tests for {@link CopyEntryFilter}.
- */
+/** Unit tests for {@link CopyEntryFilter}. */
@RunWith(JUnit4.class)
public class CopyEntryFilterTest {
@@ -33,7 +30,7 @@ public class CopyEntryFilterTest {
public void testSingleInput() throws IOException {
RecordingCallback callback = new RecordingCallback();
new CopyEntryFilter().accept("abc", callback);
- assertEquals(Arrays.asList("copy"), callback.calls);
+ assertThat(callback.calls).isEqualTo(Arrays.asList("copy"));
}
}
diff --git a/src/java_tools/singlejar/javatests/com/google/devtools/build/singlejar/DefaultJarEntryFilterTest.java b/src/java_tools/singlejar/javatests/com/google/devtools/build/singlejar/DefaultJarEntryFilterTest.java
index df92ee62c1..6b9799da15 100644
--- a/src/java_tools/singlejar/javatests/com/google/devtools/build/singlejar/DefaultJarEntryFilterTest.java
+++ b/src/java_tools/singlejar/javatests/com/google/devtools/build/singlejar/DefaultJarEntryFilterTest.java
@@ -14,16 +14,15 @@
package com.google.devtools.build.singlejar;
-import static org.junit.Assert.assertEquals;
-
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.JUnit4;
+import static com.google.common.truth.Truth.assertThat;
import java.io.IOException;
import java.util.Arrays;
import java.util.Date;
import java.util.jar.JarFile;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
/**
* Unit tests for {@link DefaultJarEntryFilter}.
@@ -37,55 +36,56 @@ public class DefaultJarEntryFilterTest {
public void testSingleInput() throws IOException {
RecordingCallback callback = new RecordingCallback();
new DefaultJarEntryFilter().accept("abc", callback);
- assertEquals(Arrays.asList("copy"), callback.calls);
- assertEquals(Arrays.asList(DOS_EPOCH), callback.dates);
+ assertThat(callback.calls).isEqualTo(Arrays.asList("copy"));
+ assertThat(callback.dates).isEqualTo(Arrays.asList(DOS_EPOCH));
}
@Test
public void testProtobufExtensionsInput() throws IOException {
RecordingCallback callback = new RecordingCallback();
new DefaultJarEntryFilter().accept("protobuf.meta", callback);
- assertEquals(Arrays.asList("customMerge"), callback.calls);
- assertEquals(Arrays.asList(DOS_EPOCH), callback.dates);
+ assertThat(callback.calls).isEqualTo(Arrays.asList("customMerge"));
+ assertThat(callback.dates).isEqualTo(Arrays.asList(DOS_EPOCH));
}
@Test
public void testManifestInput() throws IOException {
RecordingCallback callback = new RecordingCallback();
new DefaultJarEntryFilter().accept(JarFile.MANIFEST_NAME, callback);
- assertEquals(Arrays.asList("skip"), callback.calls);
+ assertThat(callback.calls).isEqualTo(Arrays.asList("skip"));
}
@Test
public void testServiceInput() throws IOException {
RecordingCallback callback = new RecordingCallback();
new DefaultJarEntryFilter().accept("META-INF/services/any.service", callback);
- assertEquals(Arrays.asList("customMerge"), callback.calls);
- assertEquals(Arrays.asList(DOS_EPOCH), callback.dates);
+ assertThat(callback.calls).isEqualTo(Arrays.asList("customMerge"));
+ assertThat(callback.dates).isEqualTo(Arrays.asList(DOS_EPOCH));
}
@Test
public void testSpringHandlers() throws IOException {
RecordingCallback callback = new RecordingCallback();
new DefaultJarEntryFilter().accept("META-INF/spring.handlers", callback);
- assertEquals(Arrays.asList("customMerge"), callback.calls);
- assertEquals(Arrays.asList(DOS_EPOCH), callback.dates);
+ assertThat(callback.calls).isEqualTo(Arrays.asList("customMerge"));
+ assertThat(callback.dates).isEqualTo(Arrays.asList(DOS_EPOCH));
}
@Test
public void testSpringSchemas() throws IOException {
RecordingCallback callback = new RecordingCallback();
new DefaultJarEntryFilter().accept("META-INF/spring.schemas", callback);
- assertEquals(Arrays.asList("customMerge"), callback.calls);
- assertEquals(Arrays.asList(DOS_EPOCH), callback.dates);
+ assertThat(callback.calls).isEqualTo(Arrays.asList("customMerge"));
+ assertThat(callback.dates).isEqualTo(Arrays.asList(DOS_EPOCH));
}
@Test
public void testClassInput() throws IOException {
RecordingCallback callback = new RecordingCallback();
new DefaultJarEntryFilter().accept("a.class", callback);
- assertEquals(Arrays.asList("copy"), callback.calls);
- assertEquals(Arrays.asList(DefaultJarEntryFilter.DOS_EPOCH_PLUS_2_SECONDS), callback.dates);
+ assertThat(callback.calls).isEqualTo(Arrays.asList("copy"));
+ assertThat(callback.dates)
+ .isEqualTo(Arrays.asList(DefaultJarEntryFilter.DOS_EPOCH_PLUS_2_SECONDS));
}
@Test
@@ -95,7 +95,7 @@ public class DefaultJarEntryFilterTest {
filter.accept("a.SF", callback);
filter.accept("a.DSA", callback);
filter.accept("a.RSA", callback);
- assertEquals(Arrays.asList("skip", "skip", "skip"), callback.calls);
- assertEquals(Arrays.<Date>asList(), callback.dates);
+ assertThat(callback.calls).isEqualTo(Arrays.asList("skip", "skip", "skip"));
+ assertThat(callback.dates).isEqualTo(Arrays.<Date>asList());
}
}
diff --git a/src/java_tools/singlejar/javatests/com/google/devtools/build/singlejar/FakeZipFile.java b/src/java_tools/singlejar/javatests/com/google/devtools/build/singlejar/FakeZipFile.java
index cdddd0d0e7..8b9bdf75bf 100644
--- a/src/java_tools/singlejar/javatests/com/google/devtools/build/singlejar/FakeZipFile.java
+++ b/src/java_tools/singlejar/javatests/com/google/devtools/build/singlejar/FakeZipFile.java
@@ -14,15 +14,12 @@
package com.google.devtools.build.singlejar;
+import static com.google.common.truth.Truth.assertThat;
+import static com.google.common.truth.Truth.assertWithMessage;
import static java.nio.charset.StandardCharsets.UTF_8;
-import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
import com.google.devtools.build.singlejar.SingleJarTest.EntryMode;
-
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
@@ -54,9 +51,9 @@ public final class FakeZipFile {
private static void assertSameByteArray(byte[] expected, byte[] actual) {
if (expected == null) {
- assertNull(actual);
+ assertThat(actual).isNull();
} else {
- assertArrayEquals(expected, actual);
+ assertThat(actual).isEqualTo(expected);
}
}
@@ -111,7 +108,7 @@ public final class FakeZipFile {
public void assertNext(ZipInputStream zipInput) throws IOException {
ZipEntry zipEntry = zipInput.getNextEntry();
- assertNotNull(zipEntry);
+ assertThat(zipEntry).isNotNull();
switch (mode) {
case EXPECT_DEFLATE:
assertEquals(ZipEntry.DEFLATED, zipEntry.getMethod());
@@ -123,9 +120,9 @@ public final class FakeZipFile {
// we don't care.
break;
}
- assertEquals(name, zipEntry.getName());
+ assertThat(zipEntry.getName()).isEqualTo(name);
if (date != null) {
- assertEquals(date.getTime(), zipEntry.getTime());
+ assertThat(zipEntry.getTime()).isEqualTo(date.getTime());
}
assertSameByteArray(extra, zipEntry.getExtra());
content.validate(readZipEntryContent(zipInput));
@@ -210,20 +207,20 @@ public final class FakeZipFile {
offset += preamble.length;
length -= offset;
byte[] maybePreamble = Arrays.copyOfRange(data, 0, offset);
- assertTrue(Arrays.equals(preamble, maybePreamble));
+ assertThat(maybePreamble).isEqualTo(preamble);
}
ZipInputStream zipInput = new ZipInputStream(new ByteArrayInputStream(data, offset, length));
for (FakeZipEntry entry : entries) {
entry.assertNext(zipInput);
}
- assertNull(zipInput.getNextEntry());
+ assertThat(zipInput.getNextEntry()).isNull();
// Verify that the end of central directory data is correct.
// This assumes that the end of directory is at the end of input and that there is no zip file
// comment.
int count = getUnsignedShort(data, data.length-14);
- assertEquals(entries.size(), count);
+ assertThat(count).isEqualTo(entries.size());
count = getUnsignedShort(data, data.length-12);
- assertEquals(entries.size(), count);
+ assertThat(count).isEqualTo(entries.size());
}
/**
@@ -244,22 +241,26 @@ public final class FakeZipFile {
parseZipEntry(expectedZip, expectedFileList, expectedEntries, expectedEntryContents);
parseZipEntry(actualZip, actualFileList, actualEntries, actualEntryContents);
// Compare the ordered file list first.
- assertEquals(expectedFileList.toString(), actualFileList.toString());
+ assertThat(actualFileList.toString()).isEqualTo(expectedFileList.toString());
// Then compare each entry.
for (String name : expectedEntries.keySet()) {
ZipEntry expectedEntry = expectedEntries.get(name);
ZipEntry actualEntry = actualEntries.get(name);
- assertEquals("Time differs for " + name, expectedEntry.getTime(), actualEntry.getTime());
- assertArrayEquals("Extraneous content differs for " + name,
- expectedEntry.getExtra(), actualEntry.getExtra());
- assertArrayEquals("Content differs for " + name,
- expectedEntryContents.get(name), actualEntryContents.get(name));
+ assertWithMessage("Time differs for " + name)
+ .that(actualEntry.getTime())
+ .isEqualTo(expectedEntry.getTime());
+ assertWithMessage("Extraneous content differs for " + name)
+ .that(actualEntry.getExtra())
+ .isEqualTo(expectedEntry.getExtra());
+ assertWithMessage("Content differs for " + name)
+ .that(actualEntryContents.get(name))
+ .isEqualTo(expectedEntryContents.get(name));
}
// Finally do a binary array comparison to be sure that test fails if files are different in
// some way we don't test.
- assertArrayEquals(expected, actual);
+ assertThat(actual).isEqualTo(expected);
}
private static void parseZipEntry(ZipInputStream expectedZip, StringBuffer expectedFileList,
diff --git a/src/java_tools/singlejar/javatests/com/google/devtools/build/singlejar/MockSimpleFileSystem.java b/src/java_tools/singlejar/javatests/com/google/devtools/build/singlejar/MockSimpleFileSystem.java
index ce1d3cc4c7..6ebef2001f 100644
--- a/src/java_tools/singlejar/javatests/com/google/devtools/build/singlejar/MockSimpleFileSystem.java
+++ b/src/java_tools/singlejar/javatests/com/google/devtools/build/singlejar/MockSimpleFileSystem.java
@@ -14,10 +14,8 @@
package com.google.devtools.build.singlejar;
+import static com.google.common.truth.Truth.assertThat;
import static java.nio.charset.StandardCharsets.UTF_8;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -61,8 +59,8 @@ public final class MockSimpleFileSystem implements SimpleFileSystem {
@Override
public OutputStream getOutputStream(String filename) {
- assertEquals(outputFileName, filename);
- assertNull(out);
+ assertThat(filename).isEqualTo(outputFileName);
+ assertThat(out).isNull();
out = new ByteArrayOutputStream();
return out;
}
@@ -89,14 +87,14 @@ public final class MockSimpleFileSystem implements SimpleFileSystem {
@Override
public boolean delete(String filename) {
- assertEquals(outputFileName, filename);
- assertNotNull(out);
+ assertThat(filename).isEqualTo(outputFileName);
+ assertThat(out).isNotNull();
out = null;
return true;
}
public byte[] toByteArray() {
- assertNotNull(out);
+ assertThat(out).isNotNull();
return out.toByteArray();
}
}
diff --git a/src/java_tools/singlejar/javatests/com/google/devtools/build/singlejar/OptionFileExpanderTest.java b/src/java_tools/singlejar/javatests/com/google/devtools/build/singlejar/OptionFileExpanderTest.java
index 86e6b375d8..8c380d4e4c 100644
--- a/src/java_tools/singlejar/javatests/com/google/devtools/build/singlejar/OptionFileExpanderTest.java
+++ b/src/java_tools/singlejar/javatests/com/google/devtools/build/singlejar/OptionFileExpanderTest.java
@@ -14,16 +14,11 @@
package com.google.devtools.build.singlejar;
+import static com.google.common.truth.Truth.assertThat;
import static java.nio.charset.StandardCharsets.UTF_8;
-import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import com.google.devtools.build.singlejar.OptionFileExpander.OptionFileProvider;
-
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.JUnit4;
-
import java.io.ByteArrayInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
@@ -31,6 +26,9 @@ import java.io.InputStream;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
/**
* Unit tests for {@link OptionFileExpander}.
@@ -59,8 +57,8 @@ public class OptionFileExpanderTest {
@Test
public void testNoExpansion() throws IOException {
OptionFileExpander expander = new OptionFileExpander(new StoredOptionFileProvider());
- assertEquals(Arrays.asList("--some", "option", "list"),
- expander.expandArguments(Arrays.asList("--some", "option", "list")));
+ assertThat(expander.expandArguments(Arrays.asList("--some", "option", "list")))
+ .isEqualTo(Arrays.asList("--some", "option", "list"));
}
@Test
@@ -68,8 +66,8 @@ public class OptionFileExpanderTest {
StoredOptionFileProvider provider = new StoredOptionFileProvider();
provider.addFile("options", "--some option list");
OptionFileExpander expander = new OptionFileExpander(provider);
- assertEquals(Arrays.asList("--some", "option", "list"),
- expander.expandArguments(Arrays.asList("@options")));
+ assertThat(expander.expandArguments(Arrays.asList("@options")))
+ .isEqualTo(Arrays.asList("--some", "option", "list"));
}
@Test
diff --git a/src/java_tools/singlejar/javatests/com/google/devtools/build/singlejar/PrefixListPathFilterTest.java b/src/java_tools/singlejar/javatests/com/google/devtools/build/singlejar/PrefixListPathFilterTest.java
index 4c588bfd51..030ae277a5 100644
--- a/src/java_tools/singlejar/javatests/com/google/devtools/build/singlejar/PrefixListPathFilterTest.java
+++ b/src/java_tools/singlejar/javatests/com/google/devtools/build/singlejar/PrefixListPathFilterTest.java
@@ -14,12 +14,10 @@
package com.google.devtools.build.singlejar;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import static com.google.common.truth.Truth.assertWithMessage;
import com.google.common.collect.ImmutableList;
import com.google.devtools.build.singlejar.DefaultJarEntryFilter.PathFilter;
-
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
@@ -43,12 +41,14 @@ public class PrefixListPathFilterTest {
}
private void assertExcluded(String path) {
- assertFalse(path + " should have been excluded, but was included",
- filter.allowed(path));
+ assertWithMessage(path + " should have been excluded, but was included")
+ .that(filter.allowed(path))
+ .isFalse();
}
private void assertIncluded(String path) {
- assertTrue(path + " should have been included but was not",
- filter.allowed(path));
+ assertWithMessage(path + " should have been included but was not")
+ .that(filter.allowed(path))
+ .isTrue();
}
}
diff --git a/src/java_tools/singlejar/javatests/com/google/devtools/build/singlejar/SingleJarTest.java b/src/java_tools/singlejar/javatests/com/google/devtools/build/singlejar/SingleJarTest.java
index 4b66d13e51..3e89489b0b 100644
--- a/src/java_tools/singlejar/javatests/com/google/devtools/build/singlejar/SingleJarTest.java
+++ b/src/java_tools/singlejar/javatests/com/google/devtools/build/singlejar/SingleJarTest.java
@@ -16,7 +16,6 @@ package com.google.devtools.build.singlejar;
import static com.google.common.truth.Truth.assertThat;
import static java.nio.charset.StandardCharsets.UTF_8;
-import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import com.google.common.base.Joiner;
@@ -65,8 +64,8 @@ public class SingleJarTest {
Collections.sort(expectedBuildInfos);
String[] actualBuildInfos = actualBuildInfo.split("\n");
Arrays.sort(actualBuildInfos);
- assertEquals(LINEFEED_JOINER.join(expectedBuildInfos),
- LINEFEED_JOINER.join(actualBuildInfos));
+ assertThat(LINEFEED_JOINER.join(actualBuildInfos))
+ .isEqualTo(LINEFEED_JOINER.join(expectedBuildInfos));
}
}
@@ -91,7 +90,8 @@ public class SingleJarTest {
String actualManifest = new String(content, StandardCharsets.UTF_8);
String[] actualManifestLines = actualManifest.trim().split("\r\n");
Arrays.sort(actualManifestLines);
- assertEquals(LINEFEED_JOINER.join(manifestLines), LINEFEED_JOINER.join(actualManifestLines));
+ assertThat(LINEFEED_JOINER.join(actualManifestLines))
+ .isEqualTo(LINEFEED_JOINER.join(manifestLines));
}
}
@@ -145,7 +145,7 @@ public class SingleJarTest {
private void assertStripFirstLine(String expected, String testCase) {
byte[] result = SingleJar.stripFirstLine(testCase.getBytes(StandardCharsets.UTF_8));
- assertEquals(expected, new String(result, UTF_8));
+ assertThat(new String(result, UTF_8)).isEqualTo(expected);
}
@Test
@@ -596,7 +596,7 @@ public class SingleJarTest {
"--resources", "a/b/c", "a/b/c"));
fail();
} catch (IllegalArgumentException e) {
- assertThat(e.getMessage()).contains("already contains a file named 'a/b/c'.");
+ assertThat(e).hasMessageThat().contains("already contains a file named 'a/b/c'.");
}
}
diff --git a/src/java_tools/singlejar/javatests/com/google/devtools/build/singlejar/ZipCombinerTest.java b/src/java_tools/singlejar/javatests/com/google/devtools/build/singlejar/ZipCombinerTest.java
index c1a94e2490..bb287637ea 100644
--- a/src/java_tools/singlejar/javatests/com/google/devtools/build/singlejar/ZipCombinerTest.java
+++ b/src/java_tools/singlejar/javatests/com/google/devtools/build/singlejar/ZipCombinerTest.java
@@ -17,10 +17,6 @@ package com.google.devtools.build.singlejar;
import static com.google.common.truth.Truth.assertThat;
import static java.nio.charset.StandardCharsets.ISO_8859_1;
import static java.nio.charset.StandardCharsets.UTF_8;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import com.google.common.collect.ArrayListMultimap;
@@ -31,14 +27,6 @@ import com.google.devtools.build.zip.ExtraData;
import com.google.devtools.build.zip.ZipFileEntry;
import com.google.devtools.build.zip.ZipReader;
import com.google.devtools.build.zip.ZipUtil;
-
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
-import org.junit.rules.TemporaryFolder;
-import org.junit.runner.RunWith;
-import org.junit.runners.JUnit4;
-
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
@@ -63,6 +51,12 @@ import java.util.zip.ZipEntry;
import java.util.zip.ZipException;
import java.util.zip.ZipInputStream;
import java.util.zip.ZipOutputStream;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.junit.rules.TemporaryFolder;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
/**
* Unit tests for {@link ZipCombiner}.
@@ -113,16 +107,16 @@ public class ZipCombinerTest {
private void assertEntry(ZipInputStream zipInput, String filename, long time, byte[] content)
throws IOException {
ZipEntry zipEntry = zipInput.getNextEntry();
- assertNotNull(zipEntry);
- assertEquals(filename, zipEntry.getName());
- assertEquals(time, zipEntry.getTime());
+ assertThat(zipEntry).isNotNull();
+ assertThat(zipEntry.getName()).isEqualTo(filename);
+ assertThat(zipEntry.getTime()).isEqualTo(time);
ByteArrayOutputStream out = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int bytesCopied;
while ((bytesCopied = zipInput.read(buffer)) != -1) {
out.write(buffer, 0, bytesCopied);
}
- assertTrue(Arrays.equals(content, out.toByteArray()));
+ assertThat(out.toByteArray()).isEqualTo(content);
}
private void assertEntry(ZipInputStream zipInput, String filename, byte[] content)
@@ -209,7 +203,7 @@ public class ZipCombinerTest {
ZipInputStream zipInput = new ZipInputStream(new ByteArrayInputStream(out.toByteArray()));
assertEntry(zipInput, "hello.txt", "Hello World!");
assertEntry(zipInput, "hello2.txt", "Hello World 2!");
- assertNull(zipInput.getNextEntry());
+ assertThat(zipInput.getNextEntry()).isNull();
}
@Test
@@ -221,7 +215,7 @@ public class ZipCombinerTest {
ZipInputStream zipInput = new ZipInputStream(new ByteArrayInputStream(out.toByteArray()));
assertEntry(zipInput, "hello.txt", "Hello World!");
assertEntry(zipInput, "hello2.txt", "Hello World 2!");
- assertNull(zipInput.getNextEntry());
+ assertThat(zipInput.getNextEntry()).isNull();
}
@Test
@@ -234,7 +228,7 @@ public class ZipCombinerTest {
ZipInputStream zipInput = new ZipInputStream(new ByteArrayInputStream(out.toByteArray()));
assertEntry(zipInput, "hello.txt", "Hello World!");
assertEntry(zipInput, "hello2.txt", "Hello World 2!");
- assertNull(zipInput.getNextEntry());
+ assertThat(zipInput.getNextEntry()).isNull();
}
@Test
@@ -246,7 +240,7 @@ public class ZipCombinerTest {
}
ZipInputStream zipInput = new ZipInputStream(new ByteArrayInputStream(out.toByteArray()));
assertEntry(zipInput, "hello.txt", "Hello World!");
- assertNull(zipInput.getNextEntry());
+ assertThat(zipInput.getNextEntry()).isNull();
}
@Test
@@ -258,7 +252,7 @@ public class ZipCombinerTest {
zipCombiner.addZip(writeInputStreamToFile(new ByteArrayInputStream(new byte[] {1, 2, 3, 4})));
}
ZipInputStream zipInput = new ZipInputStream(new ByteArrayInputStream(out.toByteArray()));
- assertNull(zipInput.getNextEntry());
+ assertThat(zipInput.getNextEntry()).isNull();
}
private InputStream asStream(String content) {
@@ -273,7 +267,7 @@ public class ZipCombinerTest {
}
ZipInputStream zipInput = new ZipInputStream(new ByteArrayInputStream(out.toByteArray()));
assertEntry(zipInput, "hello.txt", "Hello World!");
- assertNull(zipInput.getNextEntry());
+ assertThat(zipInput.getNextEntry()).isNull();
}
@Test
@@ -285,7 +279,7 @@ public class ZipCombinerTest {
}
ZipInputStream zipInput = new ZipInputStream(new ByteArrayInputStream(out.toByteArray()));
assertEntry(zipInput, "hello.txt", "Hello World!");
- assertNull(zipInput.getNextEntry());
+ assertThat(zipInput.getNextEntry()).isNull();
}
static final class MergeStrategyPlaceHolder implements CustomMergeStrategy {
@@ -352,7 +346,7 @@ public class ZipCombinerTest {
try (ZipCombiner zipCombiner = new ZipCombiner(mockFilter, out)) {
zipCombiner.addZip(sampleZip());
}
- assertEquals(Arrays.asList("hello.txt"), mockFilter.calls);
+ assertThat(mockFilter.calls).containsExactly("hello.txt");
}
@Test
@@ -363,7 +357,7 @@ public class ZipCombinerTest {
zipCombiner.addZip(sampleZip());
zipCombiner.addZip(sampleZip());
}
- assertEquals(Arrays.asList("hello.txt"), mockFilter.calls);
+ assertThat(mockFilter.calls).containsExactly("hello.txt");
}
@Test
@@ -375,11 +369,11 @@ public class ZipCombinerTest {
zipCombiner.addZip(sampleZip());
zipCombiner.addZip(sampleZipWithTwoEntries());
}
- assertEquals(Arrays.asList("hello.txt", "hello2.txt"), mockFilter.calls);
+ assertThat(mockFilter.calls).containsExactly("hello.txt", "hello2.txt").inOrder();
ZipInputStream zipInput = new ZipInputStream(new ByteArrayInputStream(out.toByteArray()));
assertEntry(zipInput, "hello2.txt", "Hello World 2!");
assertEntry(zipInput, "hello.txt", "Hello World!\nHello World!");
- assertNull(zipInput.getNextEntry());
+ assertThat(zipInput.getNextEntry()).isNull();
}
@Test
@@ -392,10 +386,10 @@ public class ZipCombinerTest {
zipCombiner.addZip(sampleZipWithTwoUncompressedEntries());
zipCombiner.addZip(sampleZipWithTwoUncompressedEntries());
}
- assertEquals(Arrays.asList("hello.txt", "hello2.txt"), mockFilter.calls);
+ assertThat(mockFilter.calls).isEqualTo(Arrays.asList("hello.txt", "hello2.txt"));
ZipInputStream zipInput = new ZipInputStream(new ByteArrayInputStream(out.toByteArray()));
assertEntry(zipInput, "hello.txt", "Hello World!\nHello World!");
- assertNull(zipInput.getNextEntry());
+ assertThat(zipInput.getNextEntry()).isNull();
}
@Test
@@ -407,11 +401,11 @@ public class ZipCombinerTest {
zipCombiner.addZip(sampleZip());
zipCombiner.addZip(sampleZipWithTwoEntries());
}
- assertEquals(Arrays.asList("hello.txt", "hello2.txt"), mockFilter.calls);
+ assertThat(mockFilter.calls).isEqualTo(Arrays.asList("hello.txt", "hello2.txt"));
ZipInputStream zipInput = new ZipInputStream(new ByteArrayInputStream(out.toByteArray()));
assertEntry(zipInput, "hello2.txt", "Hello World 2!");
assertEntry(zipInput, "hello.txt", "Hello World!Hello World!");
- assertNull(zipInput.getNextEntry());
+ assertThat(zipInput.getNextEntry()).isNull();
}
@Test
@@ -424,10 +418,10 @@ public class ZipCombinerTest {
zipCombiner.addZip(sampleZipWithTwoUncompressedEntries());
zipCombiner.addZip(sampleZipWithTwoUncompressedEntries());
}
- assertEquals(Arrays.asList("hello.txt", "hello2.txt"), mockFilter.calls);
+ assertThat(mockFilter.calls).containsExactly("hello.txt", "hello2.txt").inOrder();
ZipInputStream zipInput = new ZipInputStream(new ByteArrayInputStream(out.toByteArray()));
assertEntry(zipInput, "hello.txt", "Hello World!Hello World!");
- assertNull(zipInput.getNextEntry());
+ assertThat(zipInput.getNextEntry()).isNull();
}
private File specialZipWithMinusOne() throws IOException {
@@ -444,29 +438,30 @@ public class ZipCombinerTest {
try (ZipCombiner zipCombiner = new ZipCombiner(mockFilter, out)) {
zipCombiner.addZip(specialZipWithMinusOne());
}
- assertEquals(Arrays.asList("hello.txt"), mockFilter.calls);
+ assertThat(mockFilter.calls).containsExactly("hello.txt");
ZipInputStream zipInput = new ZipInputStream(new ByteArrayInputStream(out.toByteArray()));
assertEntry(zipInput, "hello.txt", new byte[] { -1 });
- assertNull(zipInput.getNextEntry());
+ assertThat(zipInput.getNextEntry()).isNull();
}
@Test
public void testCopyDateHandling() throws IOException {
final Date date = new GregorianCalendar(2009, 8, 2, 0, 0, 0).getTime();
- ZipEntryFilter mockFilter = new ZipEntryFilter() {
- @Override
- public void accept(String filename, StrategyCallback callback) throws IOException {
- assertEquals("hello.txt", filename);
- callback.copy(date);
- }
- };
+ ZipEntryFilter mockFilter =
+ new ZipEntryFilter() {
+ @Override
+ public void accept(String filename, StrategyCallback callback) throws IOException {
+ assertThat(filename).isEqualTo("hello.txt");
+ callback.copy(date);
+ }
+ };
ByteArrayOutputStream out = new ByteArrayOutputStream();
try (ZipCombiner zipCombiner = new ZipCombiner(mockFilter, out)) {
zipCombiner.addZip(sampleZip());
}
ZipInputStream zipInput = new ZipInputStream(new ByteArrayInputStream(out.toByteArray()));
assertEntry(zipInput, "hello.txt", date, "Hello World!");
- assertNull(zipInput.getNextEntry());
+ assertThat(zipInput.getNextEntry()).isNull();
}
@Test
@@ -479,11 +474,11 @@ public class ZipCombinerTest {
zipCombiner.addZip(sampleZip());
zipCombiner.addZip(sampleZipWithTwoEntries());
}
- assertEquals(Arrays.asList("hello.txt", "hello2.txt"), mockFilter.calls);
+ assertThat(mockFilter.calls).containsExactly("hello.txt", "hello2.txt").inOrder();
ZipInputStream zipInput = new ZipInputStream(new ByteArrayInputStream(out.toByteArray()));
assertEntry(zipInput, "hello2.txt", ZipCombiner.DOS_EPOCH, "Hello World 2!");
assertEntry(zipInput, "hello.txt", mockFilter.date, "Hello World!\nHello World!");
- assertNull(zipInput.getNextEntry());
+ assertThat(zipInput.getNextEntry()).isNull();
}
@Test
@@ -543,7 +538,7 @@ public class ZipCombinerTest {
ZipInputStream zipInput = new ZipInputStream(new ByteArrayInputStream(out.toByteArray()));
assertEntry(zipInput, "hello.txt", "Hello World!");
assertEntry(zipInput, "hello2.txt", "Hello World 2!");
- assertNull(zipInput.getNextEntry());
+ assertThat(zipInput.getNextEntry()).isNull();
}
// This test verifies that multiple entries with the same name can be
@@ -568,7 +563,7 @@ public class ZipCombinerTest {
assertEntry(zipInput, "world1.txt", "Hello World 2!");
assertEntry(zipInput, "hello2.txt", "Hello World!");
assertEntry(zipInput, "world2.txt", "Hello World 2!");
- assertNull(zipInput.getNextEntry());
+ assertThat(zipInput.getNextEntry()).isNull();
}
// This tests verifies that an attempt to rename an entry to a
@@ -596,7 +591,7 @@ public class ZipCombinerTest {
assertEntry(zipInput, "hello1.txt", "Hello World!");
assertEntry(zipInput, "hello2.txt", "Hello World 2!");
assertEntry(zipInput, "hello3.txt", "Hello World!");
- assertNull(zipInput.getNextEntry());
+ assertThat(zipInput.getNextEntry()).isNull();
}
// This tests verifies that if an entry has been copied, then
@@ -622,7 +617,7 @@ public class ZipCombinerTest {
assertEntry(zipInput, "hello1.txt", "Hello World!");
assertEntry(zipInput, "hello2.txt", "Hello World 2!");
assertEntry(zipInput, "hello3.txt", "Hello World!");
- assertNull(zipInput.getNextEntry());
+ assertThat(zipInput.getNextEntry()).isNull();
}
// This tests verifies that if an entry has been skipped, then
@@ -647,7 +642,7 @@ public class ZipCombinerTest {
ZipInputStream zipInput = new ZipInputStream(new ByteArrayInputStream(out.toByteArray()));
assertEntry(zipInput, "hello1.txt", "Hello World!");
assertEntry(zipInput, "hello3.txt", "Hello World!");
- assertNull(zipInput.getNextEntry());
+ assertThat(zipInput.getNextEntry()).isNull();
}
// This test verifies that renaming works when input and output
@@ -675,7 +670,7 @@ public class ZipCombinerTest {
assertEntry(zipInput, "hello1.txt", "Hello World!");
assertEntry(zipInput, "hello2.txt", "Hello World 2!");
assertEntry(zipInput, "hello3.txt", "Hello World!");
- assertNull(zipInput.getNextEntry());
+ assertThat(zipInput.getNextEntry()).isNull();
}
// The next two tests check that ZipCombiner can handle a ZIP with an data
@@ -802,7 +797,7 @@ public class ZipCombinerTest {
for (int i = 0; i < fileCount; i++) {
assertEntry(zipInput, "hello" + i, "Hello " + i + "!");
}
- assertNull(zipInput.getNextEntry());
+ assertThat(zipInput.getNextEntry()).isNull();
new ZipTester(out.toByteArray()).validate();
}
}
diff --git a/src/java_tools/singlejar/javatests/com/google/devtools/build/zip/ZipReaderTest.java b/src/java_tools/singlejar/javatests/com/google/devtools/build/zip/ZipReaderTest.java
index 0830b56acb..80f0dc694b 100644
--- a/src/java_tools/singlejar/javatests/com/google/devtools/build/zip/ZipReaderTest.java
+++ b/src/java_tools/singlejar/javatests/com/google/devtools/build/zip/ZipReaderTest.java
@@ -21,15 +21,6 @@ import static org.junit.Assert.fail;
import com.google.common.io.ByteStreams;
import com.google.devtools.build.zip.ZipFileEntry.Compression;
import com.google.devtools.build.zip.ZipFileEntry.Feature;
-
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
-import org.junit.rules.TemporaryFolder;
-import org.junit.runner.RunWith;
-import org.junit.runners.JUnit4;
-
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
@@ -45,6 +36,13 @@ import java.util.zip.Deflater;
import java.util.zip.ZipEntry;
import java.util.zip.ZipException;
import java.util.zip.ZipOutputStream;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.junit.rules.TemporaryFolder;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
@RunWith(JUnit4.class)
public class ZipReaderTest {
@@ -467,7 +465,7 @@ public class ZipReaderTest {
fooIn.read(fooData);
assertThat(fooData).isEqualTo(expectedFooData);
assertThat(fooEntry.getName()).isEqualTo("entry");
- assertThat(fooEntry.getComment()).isEqualTo("");
+ assertThat(fooEntry.getComment()).isEmpty();
assertThat(fooEntry.getMethod()).isEqualTo(Compression.STORED);
assertThat(fooEntry.getVersionNeeded()).isEqualTo(Feature.ZIP64_SIZE.getMinVersion());
assertThat(fooEntry.getSize()).isEqualTo(expectedFooData.length);
diff --git a/src/java_tools/singlejar/javatests/com/google/devtools/build/zip/ZipWriterTest.java b/src/java_tools/singlejar/javatests/com/google/devtools/build/zip/ZipWriterTest.java
index 681d3cec94..05f4797eaf 100644
--- a/src/java_tools/singlejar/javatests/com/google/devtools/build/zip/ZipWriterTest.java
+++ b/src/java_tools/singlejar/javatests/com/google/devtools/build/zip/ZipWriterTest.java
@@ -20,15 +20,6 @@ import static org.junit.Assert.fail;
import com.google.common.primitives.Bytes;
import com.google.devtools.build.zip.ZipFileEntry.Compression;
-
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
-import org.junit.rules.TemporaryFolder;
-import org.junit.runner.RunWith;
-import org.junit.runners.JUnit4;
-
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
@@ -39,6 +30,13 @@ import java.util.zip.Deflater;
import java.util.zip.ZipEntry;
import java.util.zip.ZipException;
import java.util.zip.ZipFile;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.junit.rules.TemporaryFolder;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
@RunWith(JUnit4.class)
public class ZipWriterTest {
@@ -92,8 +90,11 @@ public class ZipWriterTest {
writer.write(new byte[] { 0xf, 0xa, 0xb });
fail("Expected ZipException");
} catch (ZipException e) {
- assertThat(e.getMessage()).contains("Cannot write zip contents without first setting a"
- + " ZipEntry or starting a prefix file.");
+ assertThat(e)
+ .hasMessageThat()
+ .contains(
+ "Cannot write zip contents without first setting a"
+ + " ZipEntry or starting a prefix file.");
}
try (ZipFile zipFile = new ZipFile(test)) {