package jalview.util.matcher; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertFalse; import static org.testng.Assert.assertTrue; import org.testng.annotations.Test; public class KeyedMatcherTest { @Test public void testMatches() { /* * a numeric matcher - MatcherTest covers more conditions */ KeyedMatcherI km = new KeyedMatcher("AF", Condition.GE, -2F); assertTrue(km.matches(key -> "-2")); assertTrue(km.matches(key -> "-1")); assertFalse(km.matches(key -> "-3")); assertFalse(km.matches(key -> "")); assertFalse(km.matches(key -> "junk")); assertFalse(km.matches(key -> null)); /* * a string pattern matcher */ km = new KeyedMatcher("AF", Condition.Contains, "Cat"); assertTrue(km.matches(key -> "AF".equals(key) ? "raining cats and dogs" : "showers")); } @Test public void testToString() { /* * toString uses the i18n translation of the enum conditions */ KeyedMatcherI km = new KeyedMatcher("AF", Condition.LT, 1.2f); assertEquals(km.toString(), "AF < 1.2"); } @Test public void testGetKey() { KeyedMatcherI km = new KeyedMatcher("AF", Condition.GE, -2F); assertEquals(km.getKey(), "AF"); } @Test public void testGetMatcher() { KeyedMatcherI km = new KeyedMatcher("AF", Condition.GE, -2F); assertEquals(km.getMatcher().getCondition(), Condition.GE); assertEquals(km.getMatcher().getFloatValue(), -2F); assertEquals(km.getMatcher().getPattern(), "-2.0"); } }