static String calculateBillingProjectId(Optional<String> configParentProjectId, Optional<Credentials> credentials)
    {
        if (configParentProjectId.isPresent()) {
            return configParentProjectId.get();
        }

        // All other credentials types (User, AppEngine, GCE, CloudShell, etc.) take it from the environment
        if (credentials.isPresent() && credentials.get() instanceof ServiceAccountCredentials) {
            return ((ServiceAccountCredentials) credentials.get()).getProjectId();
        }

        return BigQueryOptions.getDefaultProjectId();
    }
@Test
    public void testBothConfigurationAndCredentials()
            throws Exception
    {
        String projectId = BigQueryConnectorModule.calculateBillingProjectId(Optional.of("pid"), credentials());
        assertThat(projectId).isEqualTo("pid");
    }