@Test
public void refreshAccessToken() throws IOException{

  final ServerSocket authSocket = new ServerSocket(0);
  Runnable serverTask =
      new Runnable() {
        @Override
        public void run() {
          try {
            Socket clientSocket = authSocket.accept();
            BufferedReader input =
                new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
            String lines = input.readLine();
            lines += '\n' + input.readLine();
            assertEquals(CloudShellCredential.GET_AUTH_TOKEN_REQUEST, lines);
            PrintWriter out =
                new PrintWriter(clientSocket.getOutputStream(), true);
            out.println("32\n[\"email\", \"project-id\", \"token\", 1234]");
          } catch (Exception reThrown) {
            throw new RuntimeException(reThrown);
          }
        }
      };
  Thread serverThread = new Thread(serverTask);
  serverThread.start();
  GoogleCredential creds = new CloudShellCredential(
      authSocket.getLocalPort(), GsonFactory.getDefaultInstance());
  assertEquals("token", creds.executeRefreshToken().getAccessToken());
}