Skip to content

Commit 99d115c

Browse files
Add test for MockingTemplateLoader.TemplateAlreadyDefinedException
Co-authored-by: RoiSoleil <3462260+RoiSoleil@users.noreply.github.com>
1 parent 9330611 commit 99d115c

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

org.moreunit.mock.test/test/org/moreunit/mock/templates/MockingTemplateLoaderTest.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,30 @@ public void should_return_urls_of_templates_that_are_already_defined_with_a_reas
173173
entry(existingDefinition2Url, "A template is already defined with this ID"));
174174
}
175175

176+
@Test
177+
public void should_log_error_when_template_already_defined() throws Exception
178+
{
179+
// given
180+
URL definitionUrl = URI.create("file:/already.defined.url").toURL();
181+
when(resourceLoader.findBundleResources(eq(TEMPLATE_DIRECTORY), anyString())).thenReturn(singleton(definitionUrl));
182+
when(resourceLoader.findWorkspaceStateResources(anyString(), anyString())).thenReturn(noResources);
183+
184+
TemplateAlreadyDefinedException exception = new TemplateAlreadyDefinedException("templateId");
185+
when(templateDefinitionReader.read(definitionUrl)).thenReturn(someTemplates);
186+
doThrow(exception).when(templateStore).store(someTemplates);
187+
188+
// when
189+
LoadingResult result = loader.loadTemplates();
190+
191+
// then
192+
verify(logger).error("Could not load template " + definitionUrl, exception);
193+
194+
assertThat(result.invalidTemplatesFound()).isTrue();
195+
assertThat(result.invalidTemplates()).hasSize(1)
196+
.contains(entry(definitionUrl, "A template is already defined with this ID"));
197+
198+
}
199+
176200
private MockingTemplates someTemplates()
177201
{
178202
return new MockingTemplates(new ArrayList<Category>(), asList(new MockingTemplate("template")));

0 commit comments

Comments
 (0)