SheetsHelper { public Spreadsheet getSpreadsheet(String spreadsheetId) throws IOException { Spreadsheet spreadsheet = sheetsService.getSpreadsheet(spreadsheetId); String spreadsheetFileName = spreadsheet.getProperties().getTitle(); SpreadsheetProperties sheetProperties = new SpreadsheetProperties() .setTitle(spreadsheetFileName); List<Request> requests = new ArrayList<>(); requests.add( new Request().setUpdateSpreadsheetProperties( new UpdateSpreadsheetPropertiesRequest() .setProperties(sheetProperties) .setFields("title"))); sheetsService.batchUpdate(spreadsheetId, requests); return spreadsheet; } SheetsHelper(GoogleAccountCredential credential, HttpTransport transport, JsonFactory jsonFactory);   SheetsHelper(@NonNull SheetsService sheetsService); void resizeSpreadSheet(String spreadsheetId, int sheetId, int columnSize); void insertRow(String spreadsheetId, String sheetName, ValueRange row); void updateRow(String spreadsheetId, String sheetName, ValueRange row); void addSheet(String spreadsheetId, String sheetName); List<List<Object>> getSheetCells(String spreadsheetId, String sheetName); Spreadsheet getSpreadsheet(String spreadsheetId);  }
@Test public void getSpreadsheetTest() throws IOException { Spreadsheet mockedSpreadsheet = mock(Spreadsheet.class); SpreadsheetProperties mockedProperties = mock(SpreadsheetProperties.class); doReturn("sheet_title").when(mockedProperties).getTitle(); doReturn(mockedProperties).when(mockedSpreadsheet).getProperties(); doReturn(mockedSpreadsheet).when(sheetsService).getSpreadsheet("spreadsheet_id"); Spreadsheet spreadsheet = sheetsHelper.getSpreadsheet("spreadsheet_id"); assertEquals(mockedSpreadsheet, spreadsheet); assertBatchUpdateCalled(1); }