ApiCallHelper { public static String getHeaderUserAgent(@Nullable String clientAppName) { String osName = System.getProperty("os.name"); String osVersion = System.getProperty("os.version"); String osArch = System.getProperty("os.arch"); if (TextUtils.isEmpty(osName) || TextUtils.isEmpty(osVersion) || TextUtils.isEmpty(osArch)) { return Constants.HEADER_USER_AGENT; } else { return getHeaderUserAgent(clientAppName, osName, osVersion, osArch); } } private  ApiCallHelper(); static String getHeaderUserAgent(@Nullable String clientAppName); static String getHeaderUserAgent(@Nullable String clientAppName,
                                           @NonNull String osName,
                                          @NonNull String osVersion,
                                          @NonNull String osArch);  }
@Test public void getHeaderUserAgent_formatsStringCorrectly() throws Exception { assertTrue(ApiCallHelper.getHeaderUserAgent( null).startsWith(Constants.HEADER_USER_AGENT)); assertTrue(ApiCallHelper.getHeaderUserAgent( "AppName").startsWith("AppName")); }
@Test public void getHeaderUserAgent_nonAsciiCharsRemoved() { String osName = "os.name"; String osVersion = "os.version"; String osArch = "os.arch"; String userAgent = String.format( Locale.US, "%s %s/%s (%s)", Constants.HEADER_USER_AGENT, osName, osVersion, osArch); String userAgentWithExtraChars = ApiCallHelper.getHeaderUserAgent(null, osName + '\u00A9', osVersion + '\u00AE', osArch + '\u2122'); Assert.assertEquals(userAgent, userAgentWithExtraChars); }