@Test public void testAttachmentNameLifecycle$unknownAttachment() { Name<String> owner = name("test"); NameProvider sut = NameProvider.create(owner); assertThat(sut.pendingAttachmentNames("attachment"),hasSize(0)); try { sut.nextAttachmentName("attachment"); fail("Should not provide attachment names if not available"); } catch (ApplicationRuntimeException e) { assertThat(e.getMessage(),equalTo("No more attachment <<attachment>> names available for resource 'test'")); } }
@SuppressWarnings("unchecked") @Test public void testAttachmentNameLifecycle() { Name<String> owner = name("test"); NameProvider sut = NameProvider.create(owner); sut.addAttachmentName("attachment",name("m1")); sut.addAttachmentName("attachment",name("m2")); assertThat(sut.pendingAttachmentNames("attachment"),contains(name("m1"),name("m2"))); assertThat(sut.nextAttachmentName("attachment"),equalTo(name("m1"))); assertThat(sut.pendingAttachmentNames("attachment"),contains(name("m2"))); assertThat(sut.nextAttachmentName("attachment"),equalTo(name("m2"))); assertThat(sut.pendingAttachmentNames("attachment"),hasSize(0)); try { sut.nextAttachmentName("attachment"); fail("Should not provide attachment names if not available"); } catch (ApplicationRuntimeException e) { assertThat(e.getMessage(),equalTo("No more attachment <<attachment>> names available for resource 'test'")); } }