1616
1717package tpu ;
1818
19+ import static com .google .common .truth .Truth .assertThat ;
1920import static org .mockito .Mockito .any ;
2021import static org .mockito .Mockito .mock ;
2122import static org .mockito .Mockito .mockStatic ;
2223import static org .mockito .Mockito .times ;
2324import static org .mockito .Mockito .verify ;
2425import static org .mockito .Mockito .when ;
2526
27+ import com .google .cloud .tpu .v2 .ListNodesRequest ;
2628import com .google .cloud .tpu .v2 .Node ;
27- import com .google .cloud .tpu .v2 .NodeName ;
2829import com .google .cloud .tpu .v2 .TpuClient ;
2930import java .io .IOException ;
30- import org .junit .jupiter .api .Test ;
31+ import java .util .Arrays ;
32+ import java .util .List ;
33+ import org .junit .Test ;
3134import org .junit .jupiter .api .Timeout ;
3235import org .junit .runner .RunWith ;
3336import org .junit .runners .JUnit4 ;
3437import org .mockito .MockedStatic ;
3538
3639@ RunWith (JUnit4 .class )
37- @ Timeout (value = 5 )
38- public class GetTpuVmIT {
40+ @ Timeout (value = 3 )
41+ public class ListTpuVmsIT {
3942 private static final String PROJECT_ID = "project-id" ;
4043 private static final String ZONE = "asia-east1-c" ;
41- private static final String NODE_NAME = "test-tpu" ;
4244
4345 @ Test
44- public void testGetTpuVm () throws IOException {
46+ public void testListTpuVm () throws IOException {
4547 try (MockedStatic <TpuClient > mockedTpuClient = mockStatic (TpuClient .class )) {
46- Node mockNode = mock (Node .class );
47- mockedTpuClient .when (TpuClient ::create ).thenReturn (mock (TpuClient .class ));
48- when (mock (TpuClient .class ).getNode (any (NodeName .class ))).thenReturn (mockNode );
49- GetTpuVm mockGetTpuVm = mock (GetTpuVm .class );
48+ Node mockNode1 = mock (Node .class );
49+ Node mockNode2 = mock (Node .class );
50+ List <Node > mockListNodes = Arrays .asList (mockNode1 , mockNode2 );
5051
51- GetTpuVm .getTpuVm (PROJECT_ID , ZONE , NODE_NAME );
52+ TpuClient mockTpuClient = mock (TpuClient .class );
53+ mockedTpuClient .when (TpuClient ::create ).thenReturn (mockTpuClient );
54+ TpuClient .ListNodesPagedResponse mockListNodesResponse =
55+ mock (TpuClient .ListNodesPagedResponse .class );
56+ when (mockTpuClient .listNodes (any (ListNodesRequest .class ))).thenReturn (mockListNodesResponse );
57+ TpuClient .ListNodesPage mockListNodesPage = mock (TpuClient .ListNodesPage .class );
58+ when (mockListNodesResponse .getPage ()).thenReturn (mockListNodesPage );
59+ when (mockListNodesPage .getValues ()).thenReturn (mockListNodes );
5260
53- verify (mockGetTpuVm , times (1 )).getTpuVm (PROJECT_ID , ZONE , NODE_NAME );
61+ TpuClient .ListNodesPage returnedListNodes = ListTpuVms .listTpuVms (PROJECT_ID , ZONE );
62+
63+ assertThat (returnedListNodes .getValues ()).isEqualTo (mockListNodes );
64+ verify (mockTpuClient , times (1 )).listNodes (any (ListNodesRequest .class ));
5465 }
5566 }
56- }
67+ }
68+
0 commit comments