[updater] compares update source paths in tests

This commit is contained in:
Roman Shevchenko
2017-03-07 12:42:31 +01:00
parent 1e4414796e
commit 2f9f49599c
4 changed files with 46 additions and 23 deletions
@@ -20,6 +20,7 @@ import ie.wombat.jbdiff.JBDiff;
import ie.wombat.jbdiff.JBPatch;
import java.io.*;
import java.util.Objects;
import java.util.zip.ZipOutputStream;
/**
@@ -176,4 +177,25 @@ public abstract class BaseUpdateAction extends PatchAction {
}
return text;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!super.equals(o)) return false;
BaseUpdateAction that = (BaseUpdateAction)o;
if (myIsMove != that.myIsMove) return false;
if (!Objects.equals(mySource, that.mySource)) return false;
return true;
}
@Override
public int hashCode() {
int result = super.hashCode();
result = 31 * result + (myIsMove ? 1 : 0);
result = 31 * result + Objects.hashCode(mySource);
return result;
}
}
@@ -21,6 +21,7 @@ import java.nio.channels.FileLock;
import java.nio.channels.OverlappingFileLockException;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
import java.util.zip.ZipFile;
import java.util.zip.ZipOutputStream;
@@ -227,14 +228,14 @@ public abstract class PatchAction {
if (myFlags != that.myFlags) return false;
if (myChecksum != that.myChecksum) return false;
if (myPath != null ? !myPath.equals(that.myPath) : that.myPath != null) return false;
if (!Objects.equals(myPath, that.myPath)) return false;
return true;
}
@Override
public int hashCode() {
int result = myPath != null ? myPath.hashCode() : 0;
int result = Objects.hashCode(myPath);
result = 31 * result + (int)(myChecksum ^ (myChecksum >>> 32));
result = 31 * result + myFlags;
return result;
@@ -30,18 +30,6 @@ public class UpdateZipAction extends BaseUpdateAction {
super(patch, path, source, checksum, false);
}
// test support
public UpdateZipAction(Patch patch, String path,
Collection<String> filesToCreate,
Collection<String> filesToUpdate,
Collection<String> filesToDelete,
long checksum) {
super(patch, path, path, checksum, false);
myFilesToCreate = new HashSet<>(filesToCreate);
myFilesToUpdate = new HashSet<>(filesToUpdate);
myFilesToDelete = new HashSet<>(filesToDelete);
}
public UpdateZipAction(Patch patch, DataInputStream in) throws IOException {
super(patch, in);
@@ -64,6 +52,19 @@ public class UpdateZipAction extends BaseUpdateAction {
}
}
/* for tests */
UpdateZipAction(Patch patch, String path, Collection<String> toCreate, Collection<String> toUpdate, Collection<String> toDelete, long checksum) {
this(patch, path, path, toCreate, toUpdate, toDelete, checksum);
}
/* for tests */
UpdateZipAction(Patch patch, String path, String source, Collection<String> toCreate, Collection<String> toUpdate, Collection<String> toDelete, long checksum) {
super(patch, path, source, checksum, false);
myFilesToCreate = new HashSet<>(toCreate);
myFilesToUpdate = new HashSet<>(toUpdate);
myFilesToDelete = new HashSet<>(toDelete);
}
@Override
public void write(DataOutputStream out) throws IOException {
super.write(out);
@@ -201,14 +202,13 @@ public class UpdateZipAction extends BaseUpdateAction {
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (!super.equals(o)) return false;
UpdateZipAction that = (UpdateZipAction)o;
if (myFilesToCreate != null ? !myFilesToCreate.equals(that.myFilesToCreate) : that.myFilesToCreate != null) return false;
if (myFilesToUpdate != null ? !myFilesToUpdate.equals(that.myFilesToUpdate) : that.myFilesToUpdate != null) return false;
if (myFilesToDelete != null ? !myFilesToDelete.equals(that.myFilesToDelete) : that.myFilesToDelete != null) return false;
if (!Objects.equals(myFilesToCreate, that.myFilesToCreate)) return false;
if (!Objects.equals(myFilesToUpdate, that.myFilesToUpdate)) return false;
if (!Objects.equals(myFilesToDelete, that.myFilesToDelete)) return false;
return true;
}
@@ -216,9 +216,9 @@ public class UpdateZipAction extends BaseUpdateAction {
@Override
public int hashCode() {
int result = super.hashCode();
result = 31 * result + (myFilesToCreate != null ? myFilesToCreate.hashCode() : 0);
result = 31 * result + (myFilesToUpdate != null ? myFilesToUpdate.hashCode() : 0);
result = 31 * result + (myFilesToDelete != null ? myFilesToDelete.hashCode() : 0);
result = 31 * result + Objects.hashCode(myFilesToCreate);
result = 31 * result + Objects.hashCode(myFilesToDelete);
result = 31 * result + Objects.hashCode(myFilesToUpdate);
return result;
}
}
@@ -204,7 +204,7 @@ public class PatchTest extends PatchTestCase {
assertThat(sortActions(patch.getActions())).containsExactly(
new DeleteAction(patch, "lib/annotations.jar", CHECKSUMS.ANNOTATIONS_JAR),
new CreateAction(patch, "lib/redist/"),
new UpdateAction(patch, "lib/redist/annotations.jar", CHECKSUMS.ANNOTATIONS_JAR));
new UpdateAction(patch, "lib/redist/annotations.jar", "lib/annotations.jar", CHECKSUMS.ANNOTATIONS_JAR, true));
}
@Test
@@ -218,7 +218,7 @@ public class PatchTest extends PatchTestCase {
assertThat(sortActions(patch.getActions())).containsExactly(
new DeleteAction(patch, "lib/annotations.jar", CHECKSUMS.ANNOTATIONS_JAR),
new CreateAction(patch, "lib/redist/"),
new UpdateZipAction(patch, "lib/redist/annotations.jar",
new UpdateZipAction(patch, "lib/redist/annotations.jar", "lib/annotations.jar",
Collections.singletonList("org/jetbrains/annotations/NewClass.class"),
Collections.singletonList("org/jetbrains/annotations/Nullable.class"),
Collections.singletonList("org/jetbrains/annotations/TestOnly.class"),