DialogDescriptorService { public boolean isEnabled(final DialogDescriptor dialogDescriptor) { boolean result = false; DialogDescriptorUsage usage = dialogDescriptor.getAttributes().getUsage(); if (usage == DialogDescriptorUsage.DISABLED) { result = false; } else { boolean notTimedOut = isNotTimedOut(dialogDescriptor, usage); if (!notTimedOut) { dialogDescriptor.getAttributes().setUsage(DialogDescriptorUsage.DISABLED); LOGGER.debug("Dialog descriptor '" + dialogDescriptor.getAttributes().getName() + "' was disabled!"); } result = notTimedOut; } return result; }  void decreaseHitcountWhenUsageIsHitcount(final DialogDescriptor dialogDescriptor); boolean isEnabled(final DialogDescriptor dialogDescriptor);  }
@Test public void testIsEnabledWhenUsageIsAlwaysShouldReturnTrue() { attributes = new DialogDescriptorAttributes("name", DialogDescriptorUsage.ALWAYS); dialogDescriptor = new DialogDescriptor(attributes, null, null); boolean actual = underTest.isEnabled(dialogDescriptor); assertEquals(actual, true); }
@Test public void testIsEnabledWhenUsageIsDisabledShouldReturnFalse() { attributes = new DialogDescriptorAttributes("name", DialogDescriptorUsage.DISABLED); dialogDescriptor = new DialogDescriptor(attributes, null, null); boolean actual = underTest.isEnabled(dialogDescriptor); assertEquals(actual, false); }
@Test public void testIsEnabledWhenUsageIsTimeoutAndCurrentTimeIsLessThanTimeoutShouldReturnTrue() { attributes = new DialogDescriptorAttributes("name", DialogDescriptorUsage.TIMEOUT); attributes.setTimeout(2000L); dialogDescriptor = new DialogDescriptor(attributes, null, null); given(currentDateProvider.getCurrentTimeInMillis()).willReturn(1000L); boolean actual = underTest.isEnabled(dialogDescriptor); assertEquals(actual, true); }
@Test public void testIsEnabledWhenUsageIsTimeoutAndCurrentTimeEqualsTimeoutShouldReturnTrue() { attributes = new DialogDescriptorAttributes("name", DialogDescriptorUsage.TIMEOUT); attributes.setTimeout(2000L); dialogDescriptor = new DialogDescriptor(attributes, null, null); given(currentDateProvider.getCurrentTimeInMillis()).willReturn(2000L); boolean actual = underTest.isEnabled(dialogDescriptor); assertEquals(actual, true); }
@Test public void testIsEnabledWhenUsageIsTimeoutAndCurrentTimeIsGreaterThanTimeoutShouldReturnFalse() { attributes = new DialogDescriptorAttributes("name", DialogDescriptorUsage.TIMEOUT); attributes.setTimeout(1000L); dialogDescriptor = new DialogDescriptor(attributes, null, null); given(currentDateProvider.getCurrentTimeInMillis()).willReturn(2000L); boolean actual = underTest.isEnabled(dialogDescriptor); assertEquals(actual, false); }
@Test public void testIsEnabledWhenUsageIsTimeoutAndCurrentTimeIsGreaterThanTimeoutShouldSetUsageToDisabled() { attributes = new DialogDescriptorAttributes("name", DialogDescriptorUsage.TIMEOUT); attributes.setTimeout(1000L); dialogDescriptor = new DialogDescriptor(attributes, null, null); given(currentDateProvider.getCurrentTimeInMillis()).willReturn(2000L); underTest.isEnabled(dialogDescriptor); assertEquals(dialogDescriptor.getAttributes().getUsage(), DialogDescriptorUsage.DISABLED); }