DeviceHelper { public String getUserAgent() { String httpAgent = mPropertySource.getHttpAgent(); if (httpAgent == null || httpAgent.startsWith("Apache-HttpClient/UNAVAILABLE (java")) { String dalvik = mPropertySource.getJVMVersion(); if (dalvik == null) dalvik = "0.0.0"; String android = mBuildInfo.getRelease(); String model = mBuildInfo.getModel(); String build = mBuildInfo.getBuildId(); httpAgent = String.format(Locale.US, "Dalvik/%s (Linux; U; Android %s; %s Build/%s)", dalvik, android, model, build ); } return httpAgent; } DeviceHelper(Context context, PropertySource propertySource, BuildInfo buildInfo); String getUserLanguage(); String getUserAgent(); @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1) int[] getResolution();  }
@Test public void testGetHttpAgent_normal() { when(mPropertySource.getHttpAgent()).thenReturn("testagent"); assertEquals("testagent", mDeviceHelper.getUserAgent()); }
@Test public void testGetHttpAgent_badAgent() { when(mPropertySource.getHttpAgent()).thenReturn("Apache-HttpClient/UNAVAILABLE (java 1.4)"); assertEquals("Dalvik/2.2.0 (Linux; U; Android 8.0.0; UnitTest Build/ABCDEF)", mDeviceHelper.getUserAgent()); verify(mBuildInfo).getBuildId(); verify(mBuildInfo).getModel(); verify(mBuildInfo).getRelease(); verify(mPropertySource).getJVMVersion(); when(mPropertySource.getJVMVersion()).thenReturn(null); assertEquals("Dalvik/0.0.0 (Linux; U; Android 8.0.0; UnitTest Build/ABCDEF)", mDeviceHelper.getUserAgent()); }