diff --git a/mailhandler/src/main/java/org/eclipse/angus/mail/util/logging/DurationFilter.java b/mailhandler/src/main/java/org/eclipse/angus/mail/util/logging/DurationFilter.java index d2eef80..67007c0 100644 --- a/mailhandler/src/main/java/org/eclipse/angus/mail/util/logging/DurationFilter.java +++ b/mailhandler/src/main/java/org/eclipse/angus/mail/util/logging/DurationFilter.java @@ -349,7 +349,7 @@ private synchronized boolean accept(final long millis) { } //Under the rate if the count has not been reached. - if (count != records) { + if ((records - count) > 0L) { ++count; allow = true; } else { diff --git a/mailhandler/src/main/java/org/eclipse/angus/mail/util/logging/MailHandler.java b/mailhandler/src/main/java/org/eclipse/angus/mail/util/logging/MailHandler.java index b8ae12d..973f523 100644 --- a/mailhandler/src/main/java/org/eclipse/angus/mail/util/logging/MailHandler.java +++ b/mailhandler/src/main/java/org/eclipse/angus/mail/util/logging/MailHandler.java @@ -593,9 +593,6 @@ public MailHandler() { public MailHandler(final int capacity) { init((Properties) null); sealed = true; - if (capacity <=0 ) { - throw new IllegalArgumentException(); - } setCapacity0(capacity); } @@ -605,15 +602,11 @@ public MailHandler(final int capacity) { * documentation. This Handler will also search the * LogManager for defaults if needed. * - * @param props a non null properties object. - * @throws NullPointerException if props is null. + * @param props a properties object or null. * @throws SecurityException if a security manager exists and the * caller does not have LoggingPermission("control"). */ - public MailHandler(final Properties props) { - if (props == null) { - throw new NullPointerException(); - } + public MailHandler(Properties props) { init(props); sealed = true; setMailProperties0(props); diff --git a/providers/angus-mail/src/test/java/org/eclipse/angus/mail/util/logging/DurationFilterTest.java b/providers/angus-mail/src/test/java/org/eclipse/angus/mail/util/logging/DurationFilterTest.java index e29d728..3e085f8 100644 --- a/providers/angus-mail/src/test/java/org/eclipse/angus/mail/util/logging/DurationFilterTest.java +++ b/providers/angus-mail/src/test/java/org/eclipse/angus/mail/util/logging/DurationFilterTest.java @@ -649,6 +649,19 @@ public void testRecords() { assertEquals(records, one.getRecords()); } + @Test + public void testCountExceedsRecords() { + DurationFilter one = new DurationFilter(10L, 15L * 60L * 1000L); + LogRecord r = new LogRecord(Level.INFO, ""); + final long now = r.getMillis(); + for (long i = 1L; i <= one.getRecords() / 2L; ++i) { + assertTrue(one.isLoggable(r)); + setEpochMilli(r, now + i); + } + one.setRecords(1L); + assertFalse(one.isLoggable(r)); + } + @Test public void testDurationMillis() { DurationFilter one = new DurationFilter(); diff --git a/providers/angus-mail/src/test/java/org/eclipse/angus/mail/util/logging/MailHandlerTest.java b/providers/angus-mail/src/test/java/org/eclipse/angus/mail/util/logging/MailHandlerTest.java index e320ae8..34e8b16 100644 --- a/providers/angus-mail/src/test/java/org/eclipse/angus/mail/util/logging/MailHandlerTest.java +++ b/providers/angus-mail/src/test/java/org/eclipse/angus/mail/util/logging/MailHandlerTest.java @@ -3639,30 +3639,22 @@ public void testComparator() { @Test public void testCapacity() { - try { - MailHandler h = new MailHandler(-1); - h.getCapacity(); - fail("Negative capacity was allowed."); - } catch (IllegalArgumentException pass) { - } catch (RuntimeException RE) { - fail(RE.toString()); - } + MailHandler h = new MailHandler(-1); + assertEquals(1000, h.getCapacity()); - try { - MailHandler h = new MailHandler(0); - h.getCapacity(); - fail("Zero capacity was allowed."); - } catch (IllegalArgumentException pass) { - } catch (RuntimeException RE) { - fail(RE.toString()); - } + h = new MailHandler(0); + assertEquals(1000, h.getCapacity()); - try { - MailHandler h = new MailHandler(1); - h.getCapacity(); - } catch (RuntimeException RE) { - fail(RE.toString()); - } + h = new MailHandler(1); + assertEquals(1, h.getCapacity()); + + h.setCapacity(10); + assertEquals(10, h.getCapacity()); + h.close(); + assertEquals(10, h.getCapacity()); + + h.setCapacity(1000); + assertEquals(1000, h.getCapacity()); final int expResult = 20; MailHandler instance = new MailHandler(20);