1818import org .mockito .Mockito ;
1919import org .mockito .Spy ;
2020import org .mockito .junit .jupiter .MockitoExtension ;
21+ import jakarta .persistence .EntityManager ;
2122
2223import java .util .Collections ;
2324import java .util .List ;
@@ -42,6 +43,8 @@ public class CreateTemplateCommandTest {
4243 private LicenseServiceBean licenseServiceBeanMock ;
4344 @ Mock
4445 private DataverseFieldTypeInputLevelServiceBean fieldTypeInputLevelServiceBeanMock ;
46+ @ Mock
47+ private EntityManager em ;
4548
4649 @ Spy
4750 private Template templateSpy ;
@@ -53,15 +56,18 @@ public class CreateTemplateCommandTest {
5356 public void setUp () {
5457 dataverseRequestStub = Mockito .mock (DataverseRequest .class );
5558 when (contextMock .templates ()).thenReturn (templateServiceBeanStub );
59+ when (contextMock .em ()).thenReturn (em );
5660 }
5761
5862 @ Test
5963 public void execute_shouldSaveTemplate_noInitialization () throws CommandException {
6064 // Create the command with initialization set to false
6165
6266 CreateTemplateCommand sut = new CreateTemplateCommand (templateSpy , dataverseRequestStub , dataverseMock , false );
63-
67+ Template savedTemplate = mock (Template .class );
68+ when (templateServiceBeanStub .save (templateSpy )).thenReturn (savedTemplate );
6469 // Act
70+
6571
6672 sut .execute (contextMock );
6773
@@ -83,6 +89,9 @@ public void execute_shouldInitializeAndSaveTemplate_withInitialization() throws
8389
8490 when (dataverseMock .getId ()).thenReturn (42L );
8591 when (dataverseMock .isMetadataBlockRoot ()).thenReturn (true );
92+
93+ Template savedTemplate = mock (Template .class );
94+ when (templateServiceBeanStub .save (templateSpy )).thenReturn (savedTemplate );
8695
8796 // Mock system metadata blocks
8897
0 commit comments