DialogDescriptorService { public void decreaseHitcountWhenUsageIsHitcount(final DialogDescriptor dialogDescriptor) { if (dialogDescriptor.getAttributes().getUsage() == DialogDescriptorUsage.HITCOUNT) { long validityValue = dialogDescriptor.getAttributes().decreaseHitcount(); LOGGER.debug("Hitcount was decreased to " + validityValue + " in dialog descriptor '" + dialogDescriptor.getAttributes().getName() + "'!"); if (validityValue == 0) { dialogDescriptor.getAttributes().setUsage(DialogDescriptorUsage.DISABLED); LOGGER.debug("Dialog descriptor '" + dialogDescriptor.getAttributes().getName() + "' was disabled!"); } } }  void decreaseHitcountWhenUsageIsHitcount(final DialogDescriptor dialogDescriptor); boolean isEnabled(final DialogDescriptor dialogDescriptor);  }
@Test public void testDecreaseWhenUsageIsHitcountShouldDecreaseHitcount() { attributes = new DialogDescriptorAttributes("name", DialogDescriptorUsage.HITCOUNT); attributes.setHitcount(2); dialogDescriptor = new DialogDescriptor(attributes, null, null); underTest.decreaseHitcountWhenUsageIsHitcount(dialogDescriptor); assertEquals(dialogDescriptor.getAttributes().getHitcount(), 1); }
@Test public void testDecreaseWhenUsageIsHitcountAndValValueIsOneShouldDisableDD() { attributes = new DialogDescriptorAttributes("name", DialogDescriptorUsage.HITCOUNT); attributes.setHitcount(1); dialogDescriptor = new DialogDescriptor(attributes, null, null); underTest.decreaseHitcountWhenUsageIsHitcount(dialogDescriptor); assertEquals(dialogDescriptor.getAttributes().getUsage(), DialogDescriptorUsage.DISABLED); }
@Test public void testDecreaseWhenUsageIsNotHitcountShouldDoNothing() { attributes = new DialogDescriptorAttributes("name", DialogDescriptorUsage.ALWAYS); dialogDescriptor = new DialogDescriptor(attributes, null, null); underTest.decreaseHitcountWhenUsageIsHitcount(dialogDescriptor); assertEquals(dialogDescriptor.getAttributes().getUsage(), DialogDescriptorUsage.ALWAYS); }