6868import org .mockito .Mock ;
6969import org .mockito .MockedStatic ;
7070import org .mockito .Mockito ;
71+ import org .mockito .Spy ;
7172import org .mockito .junit .MockitoJUnitRunner ;
7273
7374import javax .naming .ConfigurationException ;
8687import static org .mockito .ArgumentMatchers .anyLong ;
8788import static org .mockito .ArgumentMatchers .anyString ;
8889import static org .mockito .ArgumentMatchers .eq ;
90+ import static org .mockito .Mockito .doReturn ;
8991import static org .mockito .Mockito .mock ;
9092import static org .mockito .Mockito .never ;
9193import static org .mockito .Mockito .times ;
@@ -176,6 +178,7 @@ public class GpuServiceImplTest {
176178 private ResourceManager resourceManager ;
177179
178180 @ InjectMocks
181+ @ Spy
179182 private GpuServiceImpl gpuService ;
180183
181184 @ Mock
@@ -650,10 +653,14 @@ public void testDisableGpuDevice_Success() {
650653 when (device .getId ()).thenReturn (GPU_DEVICE_ID_LONG );
651654 when (device .getManagedState ()).thenReturn (GpuDevice .ManagedState .Managed );
652655 when (device .getVmId ()).thenReturn (null );
656+ when (device .getHostId ()).thenReturn (HOST_ID );
653657
654658 when (gpuDeviceDao .findById (GPU_DEVICE_ID_LONG )).thenReturn (device );
655659 when (gpuDeviceDao .update (eq (GPU_DEVICE_ID_LONG ), any (GpuDeviceVO .class ))).thenReturn (true );
656660
661+ when (hostDao .findById (HOST_ID )).thenReturn (mockHost );
662+ doReturn (null ).when (gpuService ).getGpuGroupDetailsFromGpuDevicesOnHost (any ());
663+
657664 boolean result = gpuService .disableGpuDevice (cmd );
658665
659666 assertTrue (result );
@@ -669,10 +676,14 @@ public void testEnableGpuDevice_Success() {
669676 when (device .getId ()).thenReturn (GPU_DEVICE_ID_LONG );
670677 when (device .getManagedState ()).thenReturn (GpuDevice .ManagedState .Unmanaged );
671678 when (device .getVmId ()).thenReturn (null );
679+ when (device .getHostId ()).thenReturn (HOST_ID );
672680
673681 when (gpuDeviceDao .findById (GPU_DEVICE_ID_LONG )).thenReturn (device );
674682 when (gpuDeviceDao .update (eq (GPU_DEVICE_ID_LONG ), any (GpuDeviceVO .class ))).thenReturn (true );
675683
684+ when (hostDao .findById (HOST_ID )).thenReturn (mockHost );
685+ doReturn (null ).when (gpuService ).getGpuGroupDetailsFromGpuDevicesOnHost (any ());
686+
676687 boolean result = gpuService .enableGpuDevice (cmd );
677688
678689 assertTrue (result );
0 commit comments