Skip to content

Commit cb4f498

Browse files
🧪 Test: Add coverage for loadTemplates in MockingTemplateLoader
Added explicitly missing tests for `loadTemplates()` in `MockingTemplateLoaderTest.java`: - Test that the template store is cleared before loading. - Test loading templates from both the bundle and workspace state locations simultaneously. - Increased test specificity for when no valid template definitions are found. Co-authored-by: RoiSoleil <3462260+RoiSoleil@users.noreply.github.com>
1 parent 0daf53a commit cb4f498

1 file changed

Lines changed: 43 additions & 1 deletion

File tree

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

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,18 +44,60 @@ public class MockingTemplateLoaderTest
4444
MockingTemplateException someException = new MockingTemplateException("test exception");
4545
MockingTemplates someTemplates = someTemplates();
4646

47+
@Test
48+
public void should_clear_template_store_before_loading() throws Exception
49+
{
50+
// given
51+
when(resourceLoader.findBundleResources(anyString(), anyString())).thenReturn(noResources);
52+
when(resourceLoader.findWorkspaceStateResources(anyString(), anyString())).thenReturn(noResources);
53+
54+
// when
55+
loader.loadTemplates();
56+
57+
// then
58+
verify(templateStore).clear();
59+
}
60+
61+
@Test
62+
public void should_load_from_both_bundle_and_workspace_state() throws Exception
63+
{
64+
// given
65+
URL bundleUrl = URI.create("file:/bundle.url").toURL();
66+
URL workspaceUrl = URI.create("file:/workspace.url").toURL();
67+
68+
when(resourceLoader.findBundleResources(eq(TEMPLATE_DIRECTORY), anyString())).thenReturn(singleton(bundleUrl));
69+
when(resourceLoader.findWorkspaceStateResources(eq(TEMPLATE_DIRECTORY), anyString())).thenReturn(singleton(workspaceUrl));
70+
71+
MockingTemplates bundleTemplates = someTemplates();
72+
MockingTemplates workspaceTemplates = someTemplates();
73+
74+
when(templateDefinitionReader.read(bundleUrl)).thenReturn(bundleTemplates);
75+
when(templateDefinitionReader.read(workspaceUrl)).thenReturn(workspaceTemplates);
76+
77+
// when
78+
LoadingResult result = loader.loadTemplates();
79+
80+
// then
81+
verify(templateStore).store(bundleTemplates);
82+
verify(templateStore).store(workspaceTemplates);
83+
84+
assertThat(result.invalidTemplatesFound()).isFalse();
85+
assertThat(result.invalidTemplates()).isEmpty();
86+
}
87+
4788
@Test
4889
public void should_log_error_when_template_definition_resource_is_not_found() throws Exception
4990
{
5091
// given
5192
when(resourceLoader.findBundleResources(anyString(), anyString())).thenReturn(noResources);
5293
when(resourceLoader.findWorkspaceStateResources(anyString(), anyString())).thenReturn(noResources);
94+
when(templateStore.getCategories()).thenReturn(new ArrayList<Category>());
5395

5496
// when
5597
loader.loadTemplates();
5698

5799
// then
58-
verify(logger, atLeastOnce()).error(anyString());
100+
verify(logger).error("Failed to find valid templates.");
59101
}
60102

61103
@Test

0 commit comments

Comments
 (0)