HockeyApp extends ServiceImpl implements CrashReportingService { protected String getAppIDFromResponse(HockeyAppsDTO appsList) { final String applicationPackageName = utils.getApplicationPackageName(context); String hockeyAppApplicationId = null; if (appsList != null && appsList.apps != null && !appsList.apps.isEmpty()) { for (HockeyAppDTO app : appsList.apps) { if (app.bundle_identifier != null && app.public_identifier != null) { if ("Android".equalsIgnoreCase(app.platform)) { if (app.bundle_identifier.equals(applicationPackageName)) { hockeyAppApplicationId = app.public_identifier; break; } } } } } return hockeyAppApplicationId; } HockeyApp(Context context); @Override void enable(String apiKey); @Override boolean isEnabled(); @Override ServiceType getServiceType(); void logEvent(final StoredException storedException, final Callback<Object> deleteStoredExceptionCallback); HockeyAppService createService();  }
@Test public void testGetAppIDFromResponseSimple() { HockeyApp hockeyApp = new HockeyApp(null); hockeyApp.utils = UnitTestUtils.mockUtils(); HockeyApp.HockeyAppsDTO apps = hockeyApp.new HockeyAppsDTO(); apps.apps = new ArrayList<>(); apps.apps.add(createTestHockeyAppDTO("Android", "com.percolate.foam.unit.testing", "abc123")); String response = hockeyApp.getAppIDFromResponse(apps); assertEquals("abc123", response); }
@Test public void testGetAppIDFromResponseComplex() { HockeyApp hockeyApp = new HockeyApp(null); hockeyApp.utils = UnitTestUtils.mockUtils(); HockeyApp.HockeyAppsDTO apps = hockeyApp.new HockeyAppsDTO(); apps.apps = new ArrayList<>(); apps.apps.add(createTestHockeyAppDTO("Android", "com.percolate.foam.wrong.identifier", "abc123")); apps.apps.add(createTestHockeyAppDTO("iOS", "com.percolate.foam.unit.testing", "def456")); apps.apps.add(createTestHockeyAppDTO("Android", "com.percolate.foam.unit.testing", "ghi789")); String response = hockeyApp.getAppIDFromResponse(apps); assertEquals("ghi789", response); }
@Test public void testGetAppIDFromResponseNull() { HockeyApp hockeyApp = new HockeyApp(null); hockeyApp.utils = UnitTestUtils.mockUtils(); assertNull(hockeyApp.getAppIDFromResponse(null)); assertNull(hockeyApp.getAppIDFromResponse(hockeyApp.new HockeyAppsDTO())); }
@Test public void testGetAppIDFromResponseFail() { HockeyApp hockeyApp = new HockeyApp(null); hockeyApp.utils = UnitTestUtils.mockUtils(); HockeyApp.HockeyAppsDTO apps = hockeyApp.new HockeyAppsDTO(); apps.apps = new ArrayList<>(); apps.apps.add(createTestHockeyAppDTO("Android", "com.percolate.foam.wrong.identifier", "abc123")); apps.apps.add(createTestHockeyAppDTO("iOS", "com.percolate.foam.unit.testing", "def456")); String response = hockeyApp.getAppIDFromResponse(apps); assertNull(response); }