LevelInequalityRule { public static Rule getRule(final String inequalitySymbol, final String value) { Level thisLevel; if (levelList.contains(value.toUpperCase())) { thisLevel = Level.parse(value.toUpperCase()); } else { throw new IllegalArgumentException("Invalid level inequality rule - " + value + " is not a supported level"); } if ("<".equals(inequalitySymbol)) { return new LessThanRule(thisLevel); } if (">".equals(inequalitySymbol)) { return new GreaterThanRule(thisLevel); } if ("<=".equals(inequalitySymbol)) { return new LessThanEqualsRule(thisLevel); } if (">=".equals(inequalitySymbol)) { return new GreaterThanEqualsRule(thisLevel); } return null; } private  LevelInequalityRule(); static Rule getRule(final String inequalitySymbol, final String value);  }
@Test public void test1() { try { LevelInequalityRule.getRule(">", "emergency"); Assert.fail("Expected IllegalArgumentException"); } catch (IllegalArgumentException ignored) { } }
@Test public void test2() { Rule rule = LevelInequalityRule.getRule("~", "iNfO"); AssertJUnit.assertNull(rule); }
@Test public void test3() throws IOException, ClassNotFoundException { Rule rule = (Rule) SerializationTestHelper.serializeClone(LevelInequalityRule.getRule(">=", "info")); LoggingEvent event = new LoggingEvent("org.apache.log4j.Logger", Logger.getRootLogger(), System.currentTimeMillis(), Level.INFO, "Hello, World", null); AssertJUnit.assertTrue(rule.evaluate(Log4jUtil.translateLog4j(event), null)); }
@Test public void test4() throws IOException, ClassNotFoundException { Rule rule = (Rule) SerializationTestHelper.serializeClone(LevelInequalityRule.getRule("<", "info")); LoggingEvent event = new LoggingEvent("org.apache.log4j.Logger", Logger.getRootLogger(), System.currentTimeMillis(), Level.INFO, "Hello, World", null); AssertJUnit.assertFalse(rule.evaluate(Log4jUtil.translateLog4j(event), null)); }