import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertNull;
import static org.testng.Assert.assertTrue;
import jalview.datamodel.SequenceFeature;
+import jalview.util.MessageManager;
import jalview.util.matcher.Condition;
+import java.util.Locale;
+
import org.testng.annotations.Test;
public class FeatureMatcherTest
@Test
public void testToString()
{
+ Locale.setDefault(Locale.ENGLISH);
+
/*
* toString uses the i18n translation of the enum conditions
*/
* Present / NotPresent omit the value pattern
*/
fm = FeatureMatcher.byAttribute(Condition.Present, "", "AF");
- assertEquals(fm.toString(), "AF Is present");
+ assertEquals(fm.toString(), "AF is present");
fm = FeatureMatcher.byAttribute(Condition.NotPresent, "", "AF");
- assertEquals(fm.toString(), "AF Is not present");
+ assertEquals(fm.toString(), "AF is not present");
+
+ /*
+ * by Label
+ */
+ fm = FeatureMatcher.byLabel(Condition.Matches, "foobar");
+ assertEquals(fm.toString(),
+ MessageManager.getString("label.label") + " matches 'foobar'");
+
+ /*
+ * by Score
+ */
+ fm = FeatureMatcher.byScore(Condition.GE, "12.2");
+ assertEquals(fm.toString(),
+ MessageManager.getString("label.score") + " >= 12.2");
}
@Test
- public void testGetKey()
+ public void testGetAttribute()
{
FeatureMatcherI fm = FeatureMatcher.byAttribute(Condition.GE, "-2",
"AF");
- assertEquals(fm.getKey(), new String[] { "AF" });
+ assertEquals(fm.getAttribute(), new String[] { "AF" });
/*
* compound key (attribute / subattribute)
*/
fm = FeatureMatcher.byAttribute(Condition.GE, "-2F", "CSQ",
"Consequence");
- assertEquals(fm.getKey(), new String[] { "CSQ", "Consequence" });
+ assertEquals(fm.getAttribute(), new String[] { "CSQ", "Consequence" });
+
+ /*
+ * answers null if match is by Label or by Score
+ */
+ assertNull(FeatureMatcher.byLabel(Condition.NotContains, "foo")
+ .getAttribute());
+ assertNull(FeatureMatcher.byScore(Condition.LE, "-1").getAttribute());
+ }
+
+ @Test
+ public void testIsByLabel()
+ {
+ assertTrue(FeatureMatcher.byLabel(Condition.NotContains, "foo")
+ .isByLabel());
+ assertFalse(FeatureMatcher.byScore(Condition.LE, "-1").isByLabel());
+ assertFalse(FeatureMatcher.byAttribute(Condition.LE, "-1", "AC")
+ .isByLabel());
+ }
+
+ @Test
+ public void testIsByScore()
+ {
+ assertFalse(FeatureMatcher.byLabel(Condition.NotContains, "foo")
+ .isByScore());
+ assertTrue(FeatureMatcher.byScore(Condition.LE, "-1").isByScore());
+ assertFalse(FeatureMatcher.byAttribute(Condition.LE, "-1", "AC")
+ .isByScore());
}
@Test