From b5bcea4506b034975de3363a12efb7d56caa9f01 Mon Sep 17 00:00:00 2001 From: Christoph Date: Tue, 3 Nov 2020 19:54:54 +0100 Subject: [PATCH] Fix Shared Database Tests (#7040) * Fix Shared Database Tests Fix FieldChangeEvent Delta computation * Use length directly foir comparision * upgrade postgres to 13 rename delta to majorCharacterChange * revert unrelated change --- .github/workflows/tests.yml | 2 +- .../jabref/logic/util/CoarseChangeFilter.java | 2 +- .../model/entry/event/FieldChangedEvent.java | 20 ++++++++++--------- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 8272f44b43f..fe57e60d3d0 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -91,7 +91,7 @@ jobs: runs-on: ubuntu-latest services: postgres: - image: postgres:10.8 + image: postgres:13-alpine env: POSTGRES_USER: postgres POSTGRES_PASSWORD: postgres diff --git a/src/main/java/org/jabref/logic/util/CoarseChangeFilter.java b/src/main/java/org/jabref/logic/util/CoarseChangeFilter.java index ead72efe4d5..ed3ef873aaa 100644 --- a/src/main/java/org/jabref/logic/util/CoarseChangeFilter.java +++ b/src/main/java/org/jabref/logic/util/CoarseChangeFilter.java @@ -46,7 +46,7 @@ public synchronized void listen(BibDatabaseContextChangedEvent event) { boolean isChangedEntry = lastEntryChanged.filter(e -> !e.equals(fieldChange.getBibEntry())).isPresent(); boolean isEditChanged = !isNewEdit && (isChangedField || isChangedEntry); // Only deltas of 1 when typing in manually, major change means pasting something (more than one character) - boolean isMajorChange = fieldChange.getDelta() > 1; + boolean isMajorChange = fieldChange.getMajorCharacterChange() > 1; fieldChange.setFilteredOut(!(isEditChanged || isMajorChange)); // Post each FieldChangedEvent - even the ones being marked as "filtered" diff --git a/src/main/java/org/jabref/model/entry/event/FieldChangedEvent.java b/src/main/java/org/jabref/model/entry/event/FieldChangedEvent.java index 45d9ae2ec1d..3f4eda3838e 100644 --- a/src/main/java/org/jabref/model/entry/event/FieldChangedEvent.java +++ b/src/main/java/org/jabref/model/entry/event/FieldChangedEvent.java @@ -12,7 +12,7 @@ public class FieldChangedEvent extends EntryChangedEvent { private final Field field; private final String newValue; private final String oldValue; - private int delta = 0; + private int majorCharacterChange = 0; /** * @param bibEntry Affected BibEntry object @@ -27,7 +27,7 @@ public FieldChangedEvent(BibEntry bibEntry, Field field, String newValue, String this.field = field; this.newValue = newValue; this.oldValue = oldValue; - this.delta = computeDelta(oldValue, newValue); + this.majorCharacterChange = computeMajorCharacterChange(oldValue, newValue); } /** @@ -40,7 +40,7 @@ public FieldChangedEvent(BibEntry bibEntry, Field field, String newValue, String this.field = field; this.newValue = newValue; this.oldValue = oldValue; - this.delta = computeDelta(oldValue, newValue); + this.majorCharacterChange = computeMajorCharacterChange(oldValue, newValue); } /** @@ -51,20 +51,22 @@ public FieldChangedEvent(FieldChange fieldChange, EntriesEventSource location) { this.field = fieldChange.getField(); this.newValue = fieldChange.getNewValue(); this.oldValue = fieldChange.getOldValue(); - this.delta = computeDelta(oldValue, newValue); + this.majorCharacterChange = computeMajorCharacterChange(oldValue, newValue); } public FieldChangedEvent(FieldChange fieldChange) { this(fieldChange, EntriesEventSource.LOCAL); } - private int computeDelta(String oldValue, String newValue) { + private int computeMajorCharacterChange(String oldValue, String newValue) { if (oldValue == newValue) { return 0; - } else if (oldValue == null && newValue != null) { + } else if ((oldValue == null) && (newValue != null)) { return newValue.length(); - } else if (newValue == null && oldValue != null) { + } else if ((newValue == null) && (oldValue != null)) { return oldValue.length(); + } else if ((oldValue.length() == newValue.length()) && !oldValue.equals(newValue)) { + return newValue.length(); } else { return Math.abs(newValue.length() - oldValue.length()); } @@ -82,7 +84,7 @@ public String getOldValue() { return oldValue; } - public int getDelta() { - return delta; + public int getMajorCharacterChange() { + return majorCharacterChange; } }