From fee38a58dc3d254eeee0406364c0ee350799e38f Mon Sep 17 00:00:00 2001 From: kiramt Date: Fri, 12 May 2017 09:35:52 +0100 Subject: [PATCH] JAL-2491 Unit test updates --- src/jalview/viewmodel/ViewportRanges.java | 12 ++++---- test/jalview/viewmodel/ViewportRangesTest.java | 39 ++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 6 deletions(-) diff --git a/src/jalview/viewmodel/ViewportRanges.java b/src/jalview/viewmodel/ViewportRanges.java index d77baf5..267b50e 100644 --- a/src/jalview/viewmodel/ViewportRanges.java +++ b/src/jalview/viewmodel/ViewportRanges.java @@ -128,12 +128,12 @@ public class ViewportRanges extends ViewportProperties endRes = end; } - changeSupport.firePropertyChange("startres", oldstartres, start); - if (oldstartres == start) + changeSupport.firePropertyChange("startres", oldstartres, startRes); + if (oldstartres == startRes) { // event won't be fired if start positions are same // fire an event for the end positions in case they changed - changeSupport.firePropertyChange("endres", oldendres, end); + changeSupport.firePropertyChange("endres", oldendres, endRes); } } @@ -202,12 +202,12 @@ public class ViewportRanges extends ViewportProperties endSeq = end; } - changeSupport.firePropertyChange("startseq", oldstartseq, start); - if (oldstartseq == start) + changeSupport.firePropertyChange("startseq", oldstartseq, startSeq); + if (oldstartseq == startSeq) { // event won't be fired if start positions are the same // fire in case the end positions changed - changeSupport.firePropertyChange("endseq", oldendseq, end); + changeSupport.firePropertyChange("endseq", oldendseq, endSeq); } } diff --git a/test/jalview/viewmodel/ViewportRangesTest.java b/test/jalview/viewmodel/ViewportRangesTest.java index 2465c4d..4e15b80 100644 --- a/test/jalview/viewmodel/ViewportRangesTest.java +++ b/test/jalview/viewmodel/ViewportRangesTest.java @@ -341,6 +341,16 @@ public class ViewportRangesTest { assertTrue(l.verify(0, emptylist)); l.reset(); + // check new value fired by event is corrected startres + vr.setStartEndRes(-1, 5); + assertTrue(l.verify(1, Arrays.asList("startres"), Arrays.asList(0))); + l.reset(); + + // check new value fired by event is corrected endres + vr.setStartEndRes(0, -1); + assertTrue(l.verify(1, Arrays.asList("endres"), Arrays.asList(0))); + l.reset(); + vr.setStartEndSeq(2, 15); assertTrue(l.verify(1, Arrays.asList("startseq"))); l.reset(); @@ -349,6 +359,24 @@ public class ViewportRangesTest { assertTrue(l.verify(0, emptylist)); l.reset(); + vr.setStartEndRes(2, 2); // so seq and res values should be different, in + // case of transposing in code + l.reset(); + + // check new value fired by event is corrected startseq + vr.setStartEndSeq(-1, 5); + assertTrue(l.verify(1, Arrays.asList("startseq"), Arrays.asList(0))); + l.reset(); + + // check new value fired by event is corrected endseq + vr.setStartEndSeq(0, -1); + assertTrue(l.verify(1, Arrays.asList("endseq"), Arrays.asList(0))); + l.reset(); + + // reset for later tests + vr.setStartEndSeq(2, 15); + l.reset(); + // test viewport height and width setting triggers event vr.setViewportHeight(10); assertTrue(l.verify(1, Arrays.asList("endseq"))); @@ -412,6 +440,8 @@ class MockPropChangeListener implements ViewportListenerI private List events = new ArrayList(); + private List newvalues = new ArrayList(); + public MockPropChangeListener(ViewportRanges vr) { vr.addPropertyChangeListener(this); @@ -422,6 +452,14 @@ class MockPropChangeListener implements ViewportListenerI { firecount++; events.add(evt.getPropertyName()); + newvalues.add((Integer) evt.getNewValue()); + } + + public boolean verify(int count, List eventslist, + List valueslist) + { + return (count == firecount) && events.equals(eventslist) + && newvalues.equals(valueslist); } public boolean verify(int count, List eventslist) @@ -433,5 +471,6 @@ class MockPropChangeListener implements ViewportListenerI { firecount = 0; events.clear(); + newvalues.clear(); } } -- 1.7.10.2