Skip to content

Commit

Permalink
fix: ignore & warn properties using null key/value (#23)
Browse files Browse the repository at this point in the history
Signed-off-by: Andre Dietisheim <adietish@redhat.com>
  • Loading branch information
adietish committed Sep 3, 2021
1 parent c03d6dd commit 5ed8993
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.intellij.ide.AppLifecycleListener;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.util.messages.MessageBusConnection;
import com.redhat.devtools.intellij.telemetry.core.ITelemetryService;
import com.redhat.devtools.intellij.telemetry.core.util.TimeUtils;
Expand All @@ -31,6 +32,8 @@

public class TelemetryMessageBuilder {

private static final Logger LOGGER = Logger.getInstance(TelemetryMessageBuilder.class);

private final ServiceFacade service;

public TelemetryMessageBuilder(ClassLoader classLoader) {
Expand Down Expand Up @@ -206,7 +209,12 @@ Type getType() {
}

public T property(String key, String value) {
properties.put(key, value);
if (key == null
|| value == null) {
LOGGER.warn("Ignored property with key: " + key + " value: " + value);
} else {
properties.put(key, value);
}
return (T) this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,28 @@ public void property_should_add_property_with_given_key_and_name() {
assertThat(message.getProperty(key)).isEqualTo(value);
}

@Test
public void property_should_ignore_property_with_null_key() {
// given
ActionMessage message = builder.action("smurfette");
int beforeAdding = message.properties().size();
// when
message.property(null, "papa smurf");
// then
assertThat(message.properties().size()).isEqualTo(beforeAdding);
}

@Test
public void property_should_ignore_property_with_null_value() {
// given
ActionMessage message = builder.action("smurfette");
int beforeAdding = message.properties().size();
// when
message.property("likes", null);
// then
assertThat(message.properties().size()).isEqualTo(beforeAdding);
}

@Test
public void send_should_send_message_via_service_facade() {
// given
Expand Down

0 comments on commit 5ed8993

Please sign in to comment.