@@ -74,4 +74,62 @@ public void should_retrieve_template_from_preferences_for_test_case_project() th
7474 // then
7575 verify (templateStore ).get ("test-template-id" );
7676 }
77+
78+ @ Test
79+ public void should_abort_when_template_is_null () throws Exception
80+ {
81+ // given
82+ when (dependencies .isEmpty ()).thenReturn (false );
83+ when (classUnderTest .getJavaProject ()).thenReturn (project );
84+ when (preferences .getMockingTemplate (project )).thenReturn ("test-template-id" );
85+ when (templateStore .get ("test-template-id" )).thenReturn (null );
86+
87+ // when
88+ dependencyMocker .mockDependencies (dependencies , classUnderTest , testCase , SOME_TEST_TYPE );
89+
90+ // then
91+ verify (logger ).error ("Template not found: test-template-id" );
92+ verifyNoInteractions (templateApplicator );
93+ }
94+
95+ @ Test
96+ public void should_apply_template_when_found () throws Exception
97+ {
98+ // given
99+ when (dependencies .isEmpty ()).thenReturn (false );
100+ when (classUnderTest .getJavaProject ()).thenReturn (project );
101+ when (preferences .getMockingTemplate (project )).thenReturn ("test-template-id" );
102+
103+ org .moreunit .mock .model .MockingTemplate template = new org .moreunit .mock .model .MockingTemplate ("test-template-id" );
104+ when (templateStore .get ("test-template-id" )).thenReturn (template );
105+
106+ // when
107+ dependencyMocker .mockDependencies (dependencies , classUnderTest , testCase , SOME_TEST_TYPE );
108+
109+ // then
110+ verify (templateApplicator ).applyTemplate (template , dependencies , classUnderTest , testCase , SOME_TEST_TYPE );
111+ }
112+
113+ @ Test
114+ public void should_log_error_when_template_application_fails () throws Exception
115+ {
116+ // given
117+ when (dependencies .isEmpty ()).thenReturn (false );
118+ when (classUnderTest .getJavaProject ()).thenReturn (project );
119+ when (preferences .getMockingTemplate (project )).thenReturn ("test-template-id" );
120+
121+ org .moreunit .mock .model .MockingTemplate template = new org .moreunit .mock .model .MockingTemplate ("test-template-id" );
122+ when (templateStore .get ("test-template-id" )).thenReturn (template );
123+
124+ when (testCase .getElementName ()).thenReturn ("MyTest" );
125+
126+ org .moreunit .mock .templates .MockingTemplateException exception = new org .moreunit .mock .templates .MockingTemplateException ("error" );
127+ doThrow (exception ).when (templateApplicator ).applyTemplate (template , dependencies , classUnderTest , testCase , SOME_TEST_TYPE );
128+
129+ // when
130+ dependencyMocker .mockDependencies (dependencies , classUnderTest , testCase , SOME_TEST_TYPE );
131+
132+ // then
133+ verify (logger ).error ("Could not apply MockingTemplate [id=test-template-id, category=null] to MyTest" , exception );
134+ }
77135}
0 commit comments