Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ private String getStringProperty(String key) {
}
}

public String getUseragent(String id) {
public String getUseragent(String clientId) {
String userAgent = null;
String version = getVersion();
String useragentPattern = getUseragentPattern();
if (!StringUtils.isEmpty(id)
&& !StringUtils.isEmpty(version)
&& !StringUtils.isEmpty(useragentPattern)) {
userAgent = MessageFormat.format(useragentPattern, version, id);
if (!StringUtils.isEmpty(useragentPattern)) {
userAgent = MessageFormat.format(useragentPattern,
StringUtils.nullToEmptyString(version),
StringUtils.nullToEmptyString(clientId));
}
return userAgent;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,11 @@ public static String prependIfNonEmpty(String prefix, String string) {
return new StringBuilder(prefix).append(string).toString();
}

public static String nullToEmptyString(String string) {
if (string == null) {
return "";
}
return string;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,18 @@ public void shouldReturnClientIdAndVersion() {
String[] clientIdAndVersion = userAgent.split(" ");
assertThat(clientIdAndVersion).isNotNull().hasSize(2).containsOnly(clientId, VERSION);
}

@Test
public void shouldReturnUserAgentEvenIfClientIdIsNull() {
// pre-conditions

// operation
String userAgent = serviceProperties.getUseragent(null);

// verification
assertThat(userAgent).isNotEmpty();
// length of version + space, no client-id
assertThat(userAgent).hasSize(VERSION.length() + 1);
}

}