BackendProperties { public long getProjectNumber() { if (isOnAppEngine()) { return PROJECT_NUMBER_UNKNOWN; } else if (envReader.getenv(PROJECT_NUMBER_PROPERTY) != null) { String property = envReader.getenv(PROJECT_NUMBER_PROPERTY); try { return Long.parseLong(property); } catch (NumberFormatException e) { logger.atWarning().log("Project number (%s) is not an int64.", property); return PROJECT_NUMBER_UNKNOWN; } } else { return PROJECT_NUMBER_UNKNOWN; } } BackendProperties(); @VisibleForTesting  BackendProperties(boolean isAppEngine, EnvReader envReader); boolean isOnAppEngine(); long getProjectNumber(); @Nullable String getProjectId(); @Nullable String getApplicationId();  }
@Test public void testGetProjectNumber_appEngine() { assertEquals(BackendProperties.PROJECT_NUMBER_UNKNOWN, appEngineProperties.getProjectNumber()); }
@Test public void testGetProjectNumber_tornado() { assertEquals(PROJECT_NUMBER, properties.getProjectNumber()); }
@Test public void testGetProjectNumber_tornado_notSet() { Mockito.when(envReader.getenv(BackendProperties.PROJECT_NUMBER_PROPERTY)).thenReturn(null); assertEquals(BackendProperties.PROJECT_NUMBER_UNKNOWN, properties.getProjectNumber()); }
@Test public void testGetProjectNumber_tornado_badFormat() { Mockito.when(envReader.getenv(BackendProperties.PROJECT_NUMBER_PROPERTY)).thenReturn("foo"); assertEquals(BackendProperties.PROJECT_NUMBER_UNKNOWN, properties.getProjectNumber()); }