Source:
public void getDefaultCredentials_envAndWellKnownFile_envPrecedence() throws IOException { final String refreshTokenEnv = "2/Tl6awhpFjkMkSJoj1xsli0H2eL5YsMgU_NKPY2TyGWY"; final String accessTokenEnv = "2/MkSJoj1xsli0AccessToken_NKPY2"; final String refreshTokenWkf = "3/Tl6awhpFjkMkSJoj1xsli0H2eL5YsMgU_NKPY2TyGWY"; final String accessTokenWkf = "3/MkSJoj1xsli0AccessToken_NKPY2"; TestDefaultCredentialsProvider testProvider = new TestDefaultCredentialsProvider(); InputStream envStream = UserCredentialsTest.writeUserStream(USER_CLIENT_ID, USER_CLIENT_SECRET, refreshTokenEnv); File envFile = File.createTempFile("env", ".json"); envFile.deleteOnExit(); String envPath = envFile.getPath(); testProvider.setEnv(DefaultCredentialsProvider.CREDENTIAL_ENV_VAR, envPath); testProvider.addFile(envPath, envStream); File homeDir = getTempDirectory(); File configDir = new File(homeDir, ".config"); File cloudConfigDir = new File(configDir, DefaultCredentialsProvider.CLOUDSDK_CONFIG_DIRECTORY); InputStream wkfStream = UserCredentialsTest.writeUserStream(USER_CLIENT_ID, USER_CLIENT_SECRET, refreshTokenWkf); File wellKnownFile = new File(cloudConfigDir, DefaultCredentialsProvider.WELL_KNOWN_CREDENTIALS_FILE); testProvider.setProperty("os.name", "linux"); testProvider.setProperty("user.home", homeDir.getAbsolutePath()); testProvider.addFile(wellKnownFile.getAbsolutePath(), wkfStream); MockTokenServerTransportFactory transportFactory = new MockTokenServerTransportFactory(); transportFactory.transport.addClient(USER_CLIENT_ID, USER_CLIENT_SECRET); transportFactory.transport.addRefreshToken(refreshTokenWkf, accessTokenWkf); transportFactory.transport.addRefreshToken(refreshTokenEnv, accessTokenEnv); testUserProvidesToken(testProvider, transportFactory, accessTokenEnv); }

Target:
public void getDefaultCredentials_envAndWellKnownFile_envPrecedence() throws IOException { final String refreshTokenEnv = "2/Tl6awhpFjkMkSJoj1xsli0H2eL5YsMgU_NKPY2TyGWY"; final String accessTokenEnv = "2/MkSJoj1xsli0AccessToken_NKPY2"; final String refreshTokenWkf = "3/Tl6awhpFjkMkSJoj1xsli0H2eL5YsMgU_NKPY2TyGWY"; final String accessTokenWkf = "3/MkSJoj1xsli0AccessToken_NKPY2"; TestDefaultCredentialsProvider testProvider = new TestDefaultCredentialsProvider(); InputStream envStream = UserCredentialsTest.writeUserStream(USER_CLIENT_ID, USER_CLIENT_SECRET, refreshTokenEnv); String envPath = tempFilePath("env.json"); testProvider.setEnv(DefaultCredentialsProvider.CREDENTIAL_ENV_VAR, envPath); testProvider.addFile(envPath, envStream); File homeDir = getTempDirectory(); File configDir = new File(homeDir, ".config"); File cloudConfigDir = new File(configDir, DefaultCredentialsProvider.CLOUDSDK_CONFIG_DIRECTORY); InputStream wkfStream = UserCredentialsTest.writeUserStream(USER_CLIENT_ID, USER_CLIENT_SECRET, refreshTokenWkf); File wellKnownFile = new File(cloudConfigDir, DefaultCredentialsProvider.WELL_KNOWN_CREDENTIALS_FILE); testProvider.setProperty("os.name", "linux"); testProvider.setProperty("user.home", homeDir.getAbsolutePath()); testProvider.addFile(wellKnownFile.getAbsolutePath(), wkfStream); MockTokenServerTransportFactory transportFactory = new MockTokenServerTransportFactory(); transportFactory.transport.addClient(USER_CLIENT_ID, USER_CLIENT_SECRET); transportFactory.transport.addRefreshToken(refreshTokenWkf, accessTokenWkf); transportFactory.transport.addRefreshToken(refreshTokenEnv, accessTokenEnv); testUserProvidesToken(testProvider, transportFactory, accessTokenEnv); }