From: gmungoc Date: Thu, 3 Oct 2019 10:16:12 +0000 (+0100) Subject: JAL-3383 tests and fixes for overloaded SequenceFeatures.findFeatures X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=7ee36fb2339f8ac0c374262a4335a7d387e81f76;p=jalview.git JAL-3383 tests and fixes for overloaded SequenceFeatures.findFeatures --- diff --git a/src/jalview/datamodel/features/SequenceFeatures.java b/src/jalview/datamodel/features/SequenceFeatures.java index e747d5f..d283aaa 100644 --- a/src/jalview/datamodel/features/SequenceFeatures.java +++ b/src/jalview/datamodel/features/SequenceFeatures.java @@ -473,6 +473,10 @@ public class SequenceFeatures implements SequenceFeaturesI List list) { FeatureStore fs = featureStore.get(type); + if (fs == null) + { + return list == null ? new ArrayList<>() : list; + } return fs.findOverlappingFeatures(pos, pos, list); } diff --git a/test/jalview/datamodel/features/FeatureStoreTest.java b/test/jalview/datamodel/features/FeatureStoreTest.java index 2eba1c3..8342018 100644 --- a/test/jalview/datamodel/features/FeatureStoreTest.java +++ b/test/jalview/datamodel/features/FeatureStoreTest.java @@ -886,4 +886,28 @@ public class FeatureStoreTest assertFalse(fs.contains(sf1)); assertTrue(fs.contains(sf7)); } + + @Test(groups = "Functional") + public void testFindFeatures_withResultList() + { + FeatureStore fs = newFeatureStore(); + SequenceFeature sf1 = addFeature(fs, 10, 50); + SequenceFeature sf2 = addFeature(fs, 150, 250); + + List overlaps = new ArrayList<>(); + List result = fs.findOverlappingFeatures(200, 200, + overlaps); + assertSame(result, overlaps); + assertEquals(result.size(), 1); + assertTrue(result.contains(sf2)); + assertFalse(result.contains(sf1)); + + /* + * if no list supplied, method creates one + */ + result = fs.findOverlappingFeatures(200, 200, null); + assertEquals(result.size(), 1); + assertTrue(result.contains(sf2)); + assertFalse(result.contains(sf1)); + } } diff --git a/test/jalview/datamodel/features/SequenceFeaturesTest.java b/test/jalview/datamodel/features/SequenceFeaturesTest.java index 29e76bb..923a5fe 100644 --- a/test/jalview/datamodel/features/SequenceFeaturesTest.java +++ b/test/jalview/datamodel/features/SequenceFeaturesTest.java @@ -1275,4 +1275,60 @@ public class SequenceFeaturesTest store.deleteAll(); assertFalse(store.hasFeatures()); } + + @Test(groups = "Functional") + public void testFindFeatures_withResultList() + { + SequenceFeaturesI sf = new SequenceFeatures(); + SequenceFeature sf1 = addFeature(sf, "Pfam", 10, 50); + SequenceFeature sf2 = addFeature(sf, "Pfam", 150, 250); + + /* + * findFeatures with result list to append to + */ + List overlaps = new ArrayList<>(); + List result = sf.findFeatures(200, "Pfam", overlaps); + assertSame(result, overlaps); + assertEquals(result.size(), 1); + assertTrue(result.contains(sf2)); + assertFalse(result.contains(sf1)); + + /* + * with no result list - method creates one + */ + result = sf.findFeatures(200, "Pfam", null); + assertEquals(result.size(), 1); + assertTrue(result.contains(sf2)); + assertFalse(result.contains(sf1)); + + /* + * verify the created list is extendable (is not immutable) + * notice it may contain duplicates + */ + result = sf.findFeatures(220, "Pfam", result); + assertEquals(result.size(), 2); + assertSame(result.get(0), sf2); // in input list + assertSame(result.get(1), sf2); // duplicate added + + /* + * no feature of requested type - with result list + */ + overlaps.clear(); + result = sf.findFeatures(200, "Rfam", overlaps); + assertTrue(result.isEmpty()); + + /* + * no feature of requested type - with no result list + */ + result = sf.findFeatures(200, "Rfam", null); + assertTrue(result.isEmpty()); + + /* + * verify the created list is extendable (is not immutable) + */ + result = sf.findFeatures(210, "Pfam", result); + assertEquals(result.size(), 1); + assertTrue(result.contains(sf2)); + assertFalse(result.contains(sf1)); + } }