DialogDescriptorAttributeParser { public DialogDescriptorAttributes getAttributes(final Element el) { String name = el.getAttribute("name"); DialogDescriptorUsage usage = getUsage(el.getAttribute("usage")); long validityValue = getValidityValue(el.getAttribute("validityValue"), name, usage); String comment = el.getAttribute("comment"); DialogDescriptorAttributes attributes = createAttributes(name, usage, validityValue, comment); return attributes; }  DialogDescriptorAttributes getAttributes(final Element el);  }
@Test public void testParseShouldReturnDialogDescriptorName() { getAttributeMocks(); DialogDescriptorAttributes actual = underTest.getAttributes(dialogDescriptor); assertEquals(actual.getName(), "name"); }
@Test public void testParseShouldReturnEmptyValidityValueWhenItIsNotGiven() { given(dialogDescriptor.getAttribute("name")).willReturn("name"); given(dialogDescriptor.getAttribute("usage")).willReturn("always"); DialogDescriptorAttributes actual = underTest.getAttributes(dialogDescriptor); assertEquals(actual.getHitcount(), 0); assertEquals(actual.getTimeout(), 0); }
@Test public void testParseShouldReturnEmptyValidityValueWhenItIsEmpty() { given(dialogDescriptor.getAttribute("name")).willReturn("name"); given(dialogDescriptor.getAttribute("usage")).willReturn("always"); given(dialogDescriptor.getAttribute("validityValue")).willReturn(""); DialogDescriptorAttributes actual = underTest.getAttributes(dialogDescriptor); assertEquals(actual.getHitcount(), 0); assertEquals(actual.getTimeout(), 0); }
@Test public void testParseShouldReturnHitcountWhenUsageIsHitcount() { given(dialogDescriptor.getAttribute("name")).willReturn("name"); given(dialogDescriptor.getAttribute("usage")).willReturn("hitcount"); given(dialogDescriptor.getAttribute("validityValue")).willReturn("2"); DialogDescriptorAttributes actual = underTest.getAttributes(dialogDescriptor); assertEquals(actual.getHitcount(), 2); }
@Test public void testParseShouldReturnTheMomentOfTimeoutWhenUsageIsTimeout() { given(dialogDescriptor.getAttribute("name")).willReturn("name"); given(dialogDescriptor.getAttribute("usage")).willReturn("timeout"); given(dialogDescriptor.getAttribute("validityValue")).willReturn("1"); given(currentDateProvider.getCurrentTimeInMillis()).willReturn(1000L); DialogDescriptorAttributes actual = underTest.getAttributes(dialogDescriptor); assertEquals(actual.getTimeout(), 61000L); }
@Test(expectedExceptions = DescriptorValidationFailedException.class) public void testParseWhenUsageIsHitcountAndValidityValueNotSetShouldThrowException() { given(dialogDescriptor.getAttribute("name")).willReturn("name"); given(dialogDescriptor.getAttribute("usage")).willReturn("hitcount"); underTest.getAttributes(dialogDescriptor); }
@Test(expectedExceptions = DescriptorValidationFailedException.class) public void testParseWhenUsageIsTimeoutAndValidityValueNotSetShouldThrowException() { given(dialogDescriptor.getAttribute("name")).willReturn("name"); given(dialogDescriptor.getAttribute("usage")).willReturn("timeout"); underTest.getAttributes(dialogDescriptor); }