Fix SingleJar's tests.
--
MOS_MIGRATED_REVID=85882741
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 0156cbc..7cd69a4 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
@@ -21,7 +21,6 @@
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
-import com.google.common.base.Receiver;
import com.google.devtools.build.singlejar.SingleJarTest.EntryMode;
import java.io.ByteArrayInputStream;
@@ -42,6 +41,17 @@
*/
public final class FakeZipFile {
+ /**
+ * Validates an input provided as a byte array.
+ */
+ public static interface ByteValidator {
+ /**
+ * Check if {@code object} is the expected input. If {@code object} does not match the expected
+ * pattern, an assertion should fails with the necessary message.
+ */
+ void validate(byte[] object);
+ }
+
private static void assertSameByteArray(byte[] expected, byte[] actual) {
if (expected == null) {
assertNull(actual);
@@ -60,7 +70,7 @@
return out.toByteArray();
}
- private static final class PlainByteValidator implements Receiver<byte[]> {
+ private static final class PlainByteValidator implements ByteValidator {
private final byte[] expected;
private PlainByteValidator(String expected) {
@@ -68,7 +78,7 @@
}
@Override
- public void accept(byte[] object) {
+ public void validate(byte[] object) {
assertSameByteArray(expected, object);
}
@@ -77,7 +87,7 @@
private static final class FakeZipEntry {
private final String name;
- private final Receiver<byte[]> content;
+ private final ByteValidator content;
private final Date date;
private final byte[] extra;
private final EntryMode mode;
@@ -90,7 +100,7 @@
this.mode = mode;
}
- private FakeZipEntry(String name, Date date, Receiver<byte[]> content, byte[] extra,
+ private FakeZipEntry(String name, Date date, ByteValidator content, byte[] extra,
EntryMode mode) {
this.name = name;
this.date = date;
@@ -118,7 +128,7 @@
assertEquals(date.getTime(), zipEntry.getTime());
}
assertSameByteArray(extra, zipEntry.getExtra());
- content.accept(readZipEntryContent(zipInput));
+ content.validate(readZipEntryContent(zipInput));
}
}
@@ -146,23 +156,23 @@
return this;
}
- public FakeZipFile addEntry(String name, Receiver<byte[]> content) {
+ public FakeZipFile addEntry(String name, ByteValidator content) {
entries.add(new FakeZipEntry(name, null, content, null, EntryMode.DONT_CARE));
return this;
}
- public FakeZipFile addEntry(String name, Receiver<byte[]> content, boolean compressed) {
+ public FakeZipFile addEntry(String name, ByteValidator content, boolean compressed) {
entries.add(new FakeZipEntry(name, null, content, null,
compressed ? EntryMode.EXPECT_DEFLATE : EntryMode.EXPECT_STORED));
return this;
}
- public FakeZipFile addEntry(String name, Date date, Receiver<byte[]> content) {
+ public FakeZipFile addEntry(String name, Date date, ByteValidator content) {
entries.add(new FakeZipEntry(name, date, content, null, EntryMode.DONT_CARE));
return this;
}
- public FakeZipFile addEntry(String name, Date date, Receiver<byte[]> content,
+ public FakeZipFile addEntry(String name, Date date, ByteValidator content,
boolean compressed) {
entries.add(new FakeZipEntry(name, date, content, null,
compressed ? EntryMode.EXPECT_DEFLATE : EntryMode.EXPECT_STORED));
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 dbff155..0c67b61 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
@@ -19,8 +19,8 @@
import static org.junit.Assert.fail;
import com.google.common.base.Joiner;
-import com.google.common.base.Receiver;
import com.google.common.collect.ImmutableList;
+import com.google.devtools.build.singlejar.FakeZipFile.ByteValidator;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -49,7 +49,7 @@
DONT_CARE, EXPECT_DEFLATE, EXPECT_STORED;
}
- public static final class BuildInfoValidator implements Receiver<byte[]> {
+ public static final class BuildInfoValidator implements ByteValidator {
private final List<String> buildInfoLines;
public BuildInfoValidator(List<String> buildInfoLines) {
@@ -57,7 +57,7 @@
}
@Override
- public void accept(byte[] content) {
+ public void validate(byte[] content) {
String actualBuildInfo = new String(content, StandardCharsets.UTF_8);
List<String> expectedBuildInfos = new ArrayList<>();
for (String line : buildInfoLines) { // the character : is escaped
@@ -74,7 +74,7 @@
// Manifest file line ordering is dependent of the ordering in HashMap (Attributes class) so
// we do a sorted comparison for Manifest.
- public static final class ManifestValidator implements Receiver<byte[]> {
+ public static final class ManifestValidator implements ByteValidator {
private final List<String> manifestLines;
public ManifestValidator(List<String> manifestLines) {
@@ -88,7 +88,7 @@
}
@Override
- public void accept(byte[] content) {
+ public void validate(byte[] content) {
String actualManifest = new String(content, StandardCharsets.UTF_8);
String[] actualManifestLines = actualManifest.trim().split("\r\n");
Arrays.sort(actualManifestLines);