JAL-2480 remove redundant method, further test coverage
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Mon, 5 Jun 2017 13:00:08 +0000 (14:00 +0100)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Mon, 5 Jun 2017 13:00:08 +0000 (14:00 +0100)
src/jalview/datamodel/features/FeatureStore.java
test/jalview/datamodel/features/SequenceFeaturesTest.java

index 1b6277c..3e80966 100644 (file)
@@ -820,27 +820,6 @@ public class FeatureStore
   }
 
   /**
-   * Scans all positional features to check whether the given feature group is
-   * found, and returns true if found, else false
-   * 
-   * @param featureGroup
-   * @return
-   */
-  protected boolean findFeatureGroup(String featureGroup)
-  {
-    for (SequenceFeature sf : getPositionalFeatures())
-    {
-      String group = sf.getFeatureGroup();
-      if (group == featureGroup
-              || (group != null && group.equals(featureGroup)))
-      {
-        return true;
-      }
-    }
-    return false;
-  }
-
-  /**
    * Answers true if this store has no features, else false
    * 
    * @return
index f4ec05b..b7b52a7 100644 (file)
@@ -17,6 +17,37 @@ import org.testng.annotations.Test;
 public class SequenceFeaturesTest
 {
   @Test(groups = "Functional")
+  public void testConstructor()
+  {
+    SequenceFeaturesI store = new SequenceFeatures();
+    assertFalse(store.hasFeatures());
+
+    store = new SequenceFeatures((List<SequenceFeature>) null);
+    assertFalse(store.hasFeatures());
+
+    List<SequenceFeature> features = new ArrayList<>();
+    store = new SequenceFeatures(features);
+    assertFalse(store.hasFeatures());
+
+    SequenceFeature sf1 = new SequenceFeature("Metal", "desc", 10, 20,
+            Float.NaN, null);
+    features.add(sf1);
+    SequenceFeature sf2 = new SequenceFeature("Metal", "desc", 15, 18,
+            Float.NaN, null);
+    features.add(sf2); // nested
+    SequenceFeature sf3 = new SequenceFeature("Pfam", "desc2", 0, 0,
+            Float.NaN, null); // non-positional
+    features.add(sf3);
+    store = new SequenceFeatures(features);
+    assertTrue(store.hasFeatures());
+    assertEquals(2, store.getFeatureCount(true)); // positional
+    assertEquals(1, store.getFeatureCount(false)); // non-positional
+    assertFalse(store.add(sf1)); // already contained
+    assertFalse(store.add(sf2)); // already contained
+    assertFalse(store.add(sf3)); // already contained
+  }
+
+  @Test(groups = "Functional")
   public void testGetPositionalFeatures()
   {
     SequenceFeaturesI store = new SequenceFeatures();
@@ -334,6 +365,11 @@ public class SequenceFeaturesTest
     groups = sf.getFeatureGroups(false); // for non-positional
     assertEquals(groups.size(), 1);
     assertTrue(groups.contains("AGroup"));
+    groups = sf.getFeatureGroups(false, "AType");
+    assertEquals(groups.size(), 1);
+    assertTrue(groups.contains("AGroup"));
+    groups = sf.getFeatureGroups(true, "AnotherType");
+    assertTrue(groups.isEmpty());
 
     /*
      * add, then delete, more non-positional features of different types
@@ -730,6 +766,8 @@ public class SequenceFeaturesTest
             Float.NaN, null);
     assertTrue(store.add(sf1));
     assertEquals(store.getTotalFeatureLength(), 11);
+    assertEquals(store.getTotalFeatureLength("Metal"), 11);
+    assertEquals(store.getTotalFeatureLength("Plastic"), 0);
 
     // re-add does nothing!
     assertFalse(store.add(sf1));
@@ -1163,4 +1201,17 @@ public class SequenceFeaturesTest
     assertEquals(pos.get(1).getEnd(), 22);
     assertEquals(pos.get(1).getType(), "Disulfide bond");
   }
+
+  @Test(groups = "Functional")
+  public void testIsOntologyTerm()
+  {
+    SequenceFeatures store = new SequenceFeatures();
+    assertTrue(store.isOntologyTerm("gobbledygook"));
+    assertTrue(store.isOntologyTerm("transcript", "transcript"));
+    assertTrue(store.isOntologyTerm("mRNA", "transcript"));
+    assertFalse(store.isOntologyTerm("transcript", "mRNA"));
+    assertTrue(store.isOntologyTerm("junk", "transcript", "junk"));
+    assertTrue(store.isOntologyTerm("junk", new String[] {}));
+    assertTrue(store.isOntologyTerm("junk", (String[]) null));
+  }
 }