From 296588fa9e97c310459f38142ba76171f25ea0bf Mon Sep 17 00:00:00 2001 From: Luciano Balmaceda Date: Thu, 11 Apr 2019 17:28:00 -0300 Subject: [PATCH 1/4] update telemetry format --- src/main/java/com/auth0/net/Telemetry.java | 63 ++++++++++++----- .../java/com/auth0/net/TelemetryTest.java | 67 ++++++++++++++++--- 2 files changed, 103 insertions(+), 27 deletions(-) diff --git a/src/main/java/com/auth0/net/Telemetry.java b/src/main/java/com/auth0/net/Telemetry.java index f77d43aa..38ae7229 100644 --- a/src/main/java/com/auth0/net/Telemetry.java +++ b/src/main/java/com/auth0/net/Telemetry.java @@ -4,6 +4,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import org.apache.commons.codec.binary.Base64; +import java.util.Collections; import java.util.HashMap; import java.util.Map; @@ -13,41 +14,71 @@ class Telemetry { private static final String NAME_KEY = "name"; private static final String VERSION_KEY = "version"; + private static final String CORE_KEY = "core"; + private static final String ENV_KEY = "env"; + private static final String JAVA_KEY = "java"; private final String name; private final String version; + private final String core; + private final Map env; + private final String value; Telemetry(String name, String version) { - this.name = name; - this.version = version; - } - - public String getName() { - return name; + this(name, version, null); } - public String getVersion() { - return version; - } + Telemetry(String name, String version, String core) { + this.name = name; + this.version = version; + this.core = core; - public String getValue() { - Map values = new HashMap<>(); + Map values = new HashMap<>(); if (name != null) { values.put(NAME_KEY, name); } if (version != null) { values.put(VERSION_KEY, version); } - if (values.isEmpty()) { - return null; + + HashMap tmpEnv = new HashMap<>(); + tmpEnv.put(JAVA_KEY, Runtime.class.getPackage().getSpecificationVersion()); + if (core != null) { + tmpEnv.put(CORE_KEY, core); } - String urlSafe = null; + this.env = Collections.unmodifiableMap(tmpEnv); + values.put(ENV_KEY, env); + + String tmpValue; try { String json = new ObjectMapper().writeValueAsString(values); - urlSafe = Base64.encodeBase64URLSafeString(json.getBytes()); + tmpValue = Base64.encodeBase64URLSafeString(json.getBytes()); } catch (JsonProcessingException e) { + tmpValue = null; e.printStackTrace(); } - return urlSafe; + value = tmpValue; + } + + public String getName() { + return name; + } + + public String getVersion() { + return version; + } + + //Visible for testing + String getLibraryVersion() { + return core; + } + + //Visible for testing + Map getEnvironment() { + return env; + } + + public String getValue() { + return value; } } diff --git a/src/test/java/com/auth0/net/TelemetryTest.java b/src/test/java/com/auth0/net/TelemetryTest.java index c447fc7a..dff5fe9c 100644 --- a/src/test/java/com/auth0/net/TelemetryTest.java +++ b/src/test/java/com/auth0/net/TelemetryTest.java @@ -1,39 +1,84 @@ package com.auth0.net; -import org.junit.Before; +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; +import org.apache.commons.codec.binary.Base64; import org.junit.Test; +import java.util.Map; + import static org.hamcrest.Matchers.*; import static org.junit.Assert.assertThat; public class TelemetryTest { - private Telemetry telemetry; + @Test + public void shouldReturnBasicTelemetryBase64Value() throws Exception { + Telemetry telemetry = new Telemetry("auth0-java", "1.0.0"); + String value = telemetry.getValue(); + assertThat(value, is(notNullValue())); + assertThat(value, is("eyJuYW1lIjoiYXV0aDAtamF2YSIsImVudiI6eyJqYXZhIjoiMS44In0sInZlcnNpb24iOiIxLjAuMCJ9")); - @Before - public void setUp() throws Exception { - telemetry = new Telemetry("auth0-java", "1.0.0"); + String completeString = new String(Base64.decodeBase64(value), "UTF-8"); + TypeReference> mapType = new TypeReference>() { + }; + Map complete = new ObjectMapper().readValue(completeString, mapType); + assertThat((String) complete.get("name"), is("auth0-java")); + assertThat((String) complete.get("version"), is("1.0.0")); + Map completeEnv = (Map) complete.get("env"); + assertThat((String) completeEnv.get("core"), is(nullValue())); + assertThat((String) completeEnv.get("java"), is("1.8")); } @Test - public void shouldReturnBase64() throws Exception { - assertThat(telemetry.getValue(), is(notNullValue())); - assertThat(telemetry.getValue(), is("eyJuYW1lIjoiYXV0aDAtamF2YSIsInZlcnNpb24iOiIxLjAuMCJ9")); + public void shouldReturnCompleteTelemetryBase64Value() throws Exception { + Telemetry telemetry = new Telemetry("auth0-java", "1.0.0", "2.1.3"); + String value = telemetry.getValue(); + assertThat(value, is(notNullValue())); + assertThat(value, is("eyJuYW1lIjoiYXV0aDAtamF2YSIsImVudiI6eyJjb3JlIjoiMi4xLjMiLCJqYXZhIjoiMS44In0sInZlcnNpb24iOiIxLjAuMCJ9")); + + String completeString = new String(Base64.decodeBase64(value), "UTF-8"); + TypeReference> mapType = new TypeReference>() { + }; + Map complete = new ObjectMapper().readValue(completeString, mapType); + assertThat((String) complete.get("name"), is("auth0-java")); + assertThat((String) complete.get("version"), is("1.0.0")); + Map completeEnv = (Map) complete.get("env"); + assertThat((String) completeEnv.get("core"), is("2.1.3")); + assertThat((String) completeEnv.get("java"), is("1.8")); } @Test - public void shouldReturnNullWhenNoInfoIsProvided() throws Exception { - telemetry = new Telemetry(null, null); - assertThat(telemetry.getValue(), is(nullValue())); + public void shouldAlwaysIncludeJavaVersion() throws Exception { + Telemetry telemetry = new Telemetry(null, null); + assertThat(telemetry.getValue(), is(notNullValue())); + assertThat(telemetry.getEnvironment(), is(notNullValue())); } @Test public void shouldGetName() throws Exception { + Telemetry telemetry = new Telemetry("auth0-java", "1.0.0"); assertThat(telemetry.getName(), is("auth0-java")); } @Test public void shouldGetVersion() throws Exception { + Telemetry telemetry = new Telemetry("auth0-java", "1.0.0"); assertThat(telemetry.getVersion(), is("1.0.0")); } + + @Test + public void shouldNotIncludeCoreIfNotProvided() throws Exception { + Telemetry telemetry = new Telemetry("auth0-java", "1.0.0"); + assertThat(telemetry.getLibraryVersion(), is(nullValue())); + assertThat(telemetry.getEnvironment().containsKey("core"), is(false)); + } + + @Test + public void shouldGetLibraryVersion() throws Exception { + Telemetry telemetry = new Telemetry("auth0-java", "1.0.0", "2.1.3"); + assertThat(telemetry.getLibraryVersion(), is("2.1.3")); + assertThat(telemetry.getEnvironment().get("core"), is("2.1.3")); + } + } \ No newline at end of file From db49b76340dc93198d4361316cbc7b1948cade26 Mon Sep 17 00:00:00 2001 From: Luciano Balmaceda Date: Thu, 11 Apr 2019 17:28:24 -0300 Subject: [PATCH 2/4] make Telemetry a public class --- src/main/java/com/auth0/net/Telemetry.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/auth0/net/Telemetry.java b/src/main/java/com/auth0/net/Telemetry.java index 38ae7229..6a3a9c95 100644 --- a/src/main/java/com/auth0/net/Telemetry.java +++ b/src/main/java/com/auth0/net/Telemetry.java @@ -9,7 +9,7 @@ import java.util.Map; @SuppressWarnings("WeakerAccess") -class Telemetry { +public class Telemetry { static final String HEADER_NAME = "Auth0-Client"; private static final String NAME_KEY = "name"; @@ -24,11 +24,11 @@ class Telemetry { private final Map env; private final String value; - Telemetry(String name, String version) { + public Telemetry(String name, String version) { this(name, version, null); } - Telemetry(String name, String version, String core) { + public Telemetry(String name, String version, String core) { this.name = name; this.version = version; this.core = core; From f54e185c6d33a7950f366a01c834b21b98956957 Mon Sep 17 00:00:00 2001 From: Luciano Balmaceda Date: Thu, 11 Apr 2019 17:46:46 -0300 Subject: [PATCH 3/4] allow to set a custom Telemetry instance --- .../java/com/auth0/client/auth/AuthAPI.java | 9 +++++ .../com/auth0/client/mgmt/ManagementAPI.java | 10 +++++ .../com/auth0/net/TelemetryInterceptor.java | 8 ++++ .../com/auth0/client/auth/AuthAPITest.java | 39 ++++++++++++++++--- .../auth0/client/mgmt/ManagementAPITest.java | 29 ++++++++++++++ .../auth0/net/TelemetryInterceptorTest.java | 33 ++++++++++++++++ 6 files changed, 122 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/auth0/client/auth/AuthAPI.java b/src/main/java/com/auth0/client/auth/AuthAPI.java index 87215533..0f6c5df8 100644 --- a/src/main/java/com/auth0/client/auth/AuthAPI.java +++ b/src/main/java/com/auth0/client/auth/AuthAPI.java @@ -74,6 +74,15 @@ public void doNotSendTelemetry() { telemetry.setEnabled(false); } + /** + * Setter for the Telemetry to send in every request to Auth0. + * + * @param telemetry to send in every request to Auth0 + */ + public void setTelemetry(Telemetry telemetry) { + this.telemetry.setTelemetry(telemetry); + } + /** * Whether to enable or not the current HTTP Logger for every Request, Response and other sensitive information. * diff --git a/src/main/java/com/auth0/client/mgmt/ManagementAPI.java b/src/main/java/com/auth0/client/mgmt/ManagementAPI.java index 85c8d3ad..53d47f3c 100644 --- a/src/main/java/com/auth0/client/mgmt/ManagementAPI.java +++ b/src/main/java/com/auth0/client/mgmt/ManagementAPI.java @@ -1,5 +1,6 @@ package com.auth0.client.mgmt; +import com.auth0.net.Telemetry; import com.auth0.net.TelemetryInterceptor; import com.auth0.utils.Asserts; import okhttp3.HttpUrl; @@ -65,6 +66,15 @@ public void doNotSendTelemetry() { telemetry.setEnabled(false); } + /** + * Setter for the Telemetry to send in every request to Auth0. + * + * @param telemetry to send in every request to Auth0 + */ + public void setTelemetry(Telemetry telemetry) { + this.telemetry.setTelemetry(telemetry); + } + /** * Whether to enable or not the current HTTP Logger for every Request, Response and other sensitive information. * diff --git a/src/main/java/com/auth0/net/TelemetryInterceptor.java b/src/main/java/com/auth0/net/TelemetryInterceptor.java index 2ac6625b..70b1b35c 100644 --- a/src/main/java/com/auth0/net/TelemetryInterceptor.java +++ b/src/main/java/com/auth0/net/TelemetryInterceptor.java @@ -33,6 +33,14 @@ public Response intercept(Chain chain) throws IOException { return chain.proceed(request); } + public void setTelemetry(Telemetry telemetry) { + this.telemetry = telemetry; + } + + public Telemetry getTelemetry() { + return this.telemetry; + } + public void setEnabled(boolean enabled) { this.enabled = enabled; } diff --git a/src/test/java/com/auth0/client/auth/AuthAPITest.java b/src/test/java/com/auth0/client/auth/AuthAPITest.java index 1fc2c1ae..d0a47031 100644 --- a/src/test/java/com/auth0/client/auth/AuthAPITest.java +++ b/src/test/java/com/auth0/client/auth/AuthAPITest.java @@ -5,10 +5,7 @@ import com.auth0.json.auth.CreatedUser; import com.auth0.json.auth.TokenHolder; import com.auth0.json.auth.UserInfo; -import com.auth0.net.AuthRequest; -import com.auth0.net.Request; -import com.auth0.net.SignUpRequest; -import com.auth0.net.TelemetryInterceptor; +import com.auth0.net.*; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; import okhttp3.Interceptor; @@ -20,6 +17,7 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; +import org.mockito.Mockito; import java.io.FileReader; import java.util.HashMap; @@ -106,6 +104,33 @@ public void shouldThrowWhenClientSecretIsNull() throws Exception { new AuthAPI(DOMAIN, CLIENT_ID, null); } + @Test + public void shouldUseCustomTelemetry() throws Exception { + AuthAPI api = new AuthAPI(DOMAIN, CLIENT_ID, CLIENT_SECRET); + assertThat(api.getClient().interceptors(), hasItem(isA(TelemetryInterceptor.class))); + + Telemetry currentTelemetry = null; + for (Interceptor i : api.getClient().interceptors()) { + if (i instanceof TelemetryInterceptor) { + TelemetryInterceptor interceptor = (TelemetryInterceptor) i; + currentTelemetry = interceptor.getTelemetry(); + } + } + assertThat(currentTelemetry, is(notNullValue())); + + Telemetry newTelemetry = Mockito.mock(Telemetry.class); + api.setTelemetry(newTelemetry); + + Telemetry updatedTelemetry = null; + for (Interceptor i : api.getClient().interceptors()) { + if (i instanceof TelemetryInterceptor) { + TelemetryInterceptor interceptor = (TelemetryInterceptor) i; + updatedTelemetry = interceptor.getTelemetry(); + } + } + assertThat(updatedTelemetry, is(newTelemetry)); + } + @Test public void shouldAddAndEnableTelemetryInterceptor() throws Exception { AuthAPI api = new AuthAPI(DOMAIN, CLIENT_ID, CLIENT_SECRET); @@ -389,7 +414,8 @@ public void shouldThrowOnUsernameSignUpWithNullConnection() throws Exception { public void shouldHaveNotStrongPasswordWithDetailedDescription() throws Exception { ObjectMapper mapper = new ObjectMapper(); FileReader fr = new FileReader(PASSWORD_STRENGTH_ERROR_RESPONSE_NONE); - Map mapPayload = mapper.readValue(fr, new TypeReference>() {}); + Map mapPayload = mapper.readValue(fr, new TypeReference>() { + }); APIException ex = new APIException(mapPayload, 400); assertThat(ex.getError(), is("invalid_password")); String expectedDescription = "At least 10 characters in length; Contain at least 3 of the following 4 types of characters: lower case letters (a-z), upper case letters (A-Z), numbers (i.e. 0-9), special characters (e.g. !@#$%^&*); Should contain: lower case letters (a-z), upper case letters (A-Z), numbers (i.e. 0-9), special characters (e.g. !@#$%^&*); No more than 2 identical characters in a row (e.g., \"aaa\" not allowed)"; @@ -400,7 +426,8 @@ public void shouldHaveNotStrongPasswordWithDetailedDescription() throws Exceptio public void shouldHaveNotStrongPasswordWithShortDetailedDescription() throws Exception { ObjectMapper mapper = new ObjectMapper(); FileReader fr = new FileReader(PASSWORD_STRENGTH_ERROR_RESPONSE_SOME); - Map mapPayload = mapper.readValue(fr, new TypeReference>() {}); + Map mapPayload = mapper.readValue(fr, new TypeReference>() { + }); APIException ex = new APIException(mapPayload, 400); assertThat(ex.getError(), is("invalid_password")); String expectedDescription = "Should contain: lower case letters (a-z), upper case letters (A-Z), numbers (i.e. 0-9), special characters (e.g. !@#$%^&*)"; diff --git a/src/test/java/com/auth0/client/mgmt/ManagementAPITest.java b/src/test/java/com/auth0/client/mgmt/ManagementAPITest.java index 0a311755..50cd655f 100644 --- a/src/test/java/com/auth0/client/mgmt/ManagementAPITest.java +++ b/src/test/java/com/auth0/client/mgmt/ManagementAPITest.java @@ -1,6 +1,7 @@ package com.auth0.client.mgmt; import com.auth0.client.MockServer; +import com.auth0.net.Telemetry; import com.auth0.net.TelemetryInterceptor; import okhttp3.Interceptor; import okhttp3.logging.HttpLoggingInterceptor; @@ -9,6 +10,7 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; +import org.mockito.Mockito; import static com.auth0.client.UrlMatcher.isUrl; import static okhttp3.logging.HttpLoggingInterceptor.Level; @@ -144,6 +146,33 @@ public void shouldAddAndEnableTelemetryInterceptor() throws Exception { } } + @Test + public void shouldUseCustomTelemetry() throws Exception { + ManagementAPI api = new ManagementAPI(DOMAIN, API_TOKEN); + assertThat(api.getClient().interceptors(), hasItem(isA(TelemetryInterceptor.class))); + + Telemetry currentTelemetry = null; + for (Interceptor i : api.getClient().interceptors()) { + if (i instanceof TelemetryInterceptor) { + TelemetryInterceptor interceptor = (TelemetryInterceptor) i; + currentTelemetry = interceptor.getTelemetry(); + } + } + assertThat(currentTelemetry, is(notNullValue())); + + Telemetry newTelemetry = Mockito.mock(Telemetry.class); + api.setTelemetry(newTelemetry); + + Telemetry updatedTelemetry = null; + for (Interceptor i : api.getClient().interceptors()) { + if (i instanceof TelemetryInterceptor) { + TelemetryInterceptor interceptor = (TelemetryInterceptor) i; + updatedTelemetry = interceptor.getTelemetry(); + } + } + assertThat(updatedTelemetry, is(newTelemetry)); + } + @Test public void shouldDisableTelemetryInterceptor() throws Exception { ManagementAPI api = new ManagementAPI(DOMAIN, API_TOKEN); diff --git a/src/test/java/com/auth0/net/TelemetryInterceptorTest.java b/src/test/java/com/auth0/net/TelemetryInterceptorTest.java index a84722c2..27e524fd 100644 --- a/src/test/java/com/auth0/net/TelemetryInterceptorTest.java +++ b/src/test/java/com/auth0/net/TelemetryInterceptorTest.java @@ -43,6 +43,39 @@ public void shouldEnable() throws Exception { assertThat(interceptor.isEnabled(), is(true)); } + @Test + public void shouldGetTelemetry() { + TelemetryInterceptor interceptor = new TelemetryInterceptor(telemetry); + assertThat(interceptor.getTelemetry(), is(telemetry)); + } + + @Test + public void shouldAllowToModifyTelemetryOnceSet() throws Exception { + TelemetryInterceptor interceptor = new TelemetryInterceptor(telemetry); + Telemetry updatedTelemetry = mock(Telemetry.class); + when(updatedTelemetry.getValue()).thenReturn("UpdatedClientInfo"); + interceptor.setTelemetry(updatedTelemetry); + + OkHttpClient client = new OkHttpClient.Builder() + .addInterceptor(interceptor) + .build(); + + MockWebServer server = new MockWebServer(); + server.start(); + server.enqueue(new MockResponse()); + + Request request = new Request.Builder() + .get() + .url(server.url("/")) + .build(); + client.newCall(request).execute(); + + RecordedRequest finalRequest = server.takeRequest(); + assertThat(finalRequest.getHeader("Auth0-Client"), is("UpdatedClientInfo")); + + server.shutdown(); + } + @Test public void shouldAddTelemetryHeaderIfEnabled() throws Exception { TelemetryInterceptor interceptor = new TelemetryInterceptor(telemetry); From cdf8649e42209693cc5cdcd462160796e88ab54c Mon Sep 17 00:00:00 2001 From: Luciano Balmaceda Date: Mon, 15 Apr 2019 15:44:13 -0300 Subject: [PATCH 4/4] update library version key --- src/main/java/com/auth0/net/Telemetry.java | 24 ++++++++++------- .../java/com/auth0/net/TelemetryTest.java | 27 ++++++++++++------- 2 files changed, 31 insertions(+), 20 deletions(-) diff --git a/src/main/java/com/auth0/net/Telemetry.java b/src/main/java/com/auth0/net/Telemetry.java index 6a3a9c95..9d9bc3b4 100644 --- a/src/main/java/com/auth0/net/Telemetry.java +++ b/src/main/java/com/auth0/net/Telemetry.java @@ -14,13 +14,13 @@ public class Telemetry { private static final String NAME_KEY = "name"; private static final String VERSION_KEY = "version"; - private static final String CORE_KEY = "core"; + private static final String LIBRARY_VERSION_KEY = "auth0-java"; private static final String ENV_KEY = "env"; private static final String JAVA_KEY = "java"; private final String name; private final String version; - private final String core; + private final String libraryVersion; private final Map env; private final String value; @@ -28,23 +28,27 @@ public Telemetry(String name, String version) { this(name, version, null); } - public Telemetry(String name, String version, String core) { + public Telemetry(String name, String version, String libraryVersion) { this.name = name; this.version = version; - this.core = core; + this.libraryVersion = libraryVersion; - Map values = new HashMap<>(); - if (name != null) { - values.put(NAME_KEY, name); + if (name == null) { + env = Collections.emptyMap(); + value = null; + return; } + + Map values = new HashMap<>(); + values.put(NAME_KEY, name); if (version != null) { values.put(VERSION_KEY, version); } HashMap tmpEnv = new HashMap<>(); tmpEnv.put(JAVA_KEY, Runtime.class.getPackage().getSpecificationVersion()); - if (core != null) { - tmpEnv.put(CORE_KEY, core); + if (libraryVersion != null) { + tmpEnv.put(LIBRARY_VERSION_KEY, libraryVersion); } this.env = Collections.unmodifiableMap(tmpEnv); values.put(ENV_KEY, env); @@ -70,7 +74,7 @@ public String getVersion() { //Visible for testing String getLibraryVersion() { - return core; + return libraryVersion; } //Visible for testing diff --git a/src/test/java/com/auth0/net/TelemetryTest.java b/src/test/java/com/auth0/net/TelemetryTest.java index dff5fe9c..638261ad 100644 --- a/src/test/java/com/auth0/net/TelemetryTest.java +++ b/src/test/java/com/auth0/net/TelemetryTest.java @@ -26,35 +26,42 @@ public void shouldReturnBasicTelemetryBase64Value() throws Exception { assertThat((String) complete.get("name"), is("auth0-java")); assertThat((String) complete.get("version"), is("1.0.0")); Map completeEnv = (Map) complete.get("env"); - assertThat((String) completeEnv.get("core"), is(nullValue())); + assertThat((String) completeEnv.get("auth0-java"), is(nullValue())); assertThat((String) completeEnv.get("java"), is("1.8")); } @Test public void shouldReturnCompleteTelemetryBase64Value() throws Exception { - Telemetry telemetry = new Telemetry("auth0-java", "1.0.0", "2.1.3"); + Telemetry telemetry = new Telemetry("lock", "1.0.0", "2.1.3"); String value = telemetry.getValue(); assertThat(value, is(notNullValue())); - assertThat(value, is("eyJuYW1lIjoiYXV0aDAtamF2YSIsImVudiI6eyJjb3JlIjoiMi4xLjMiLCJqYXZhIjoiMS44In0sInZlcnNpb24iOiIxLjAuMCJ9")); + assertThat(value, is("eyJuYW1lIjoibG9jayIsImVudiI6eyJqYXZhIjoiMS44IiwiYXV0aDAtamF2YSI6IjIuMS4zIn0sInZlcnNpb24iOiIxLjAuMCJ9")); String completeString = new String(Base64.decodeBase64(value), "UTF-8"); TypeReference> mapType = new TypeReference>() { }; Map complete = new ObjectMapper().readValue(completeString, mapType); - assertThat((String) complete.get("name"), is("auth0-java")); + assertThat((String) complete.get("name"), is("lock")); assertThat((String) complete.get("version"), is("1.0.0")); Map completeEnv = (Map) complete.get("env"); - assertThat((String) completeEnv.get("core"), is("2.1.3")); + assertThat((String) completeEnv.get("auth0-java"), is("2.1.3")); assertThat((String) completeEnv.get("java"), is("1.8")); } @Test - public void shouldAlwaysIncludeJavaVersion() throws Exception { - Telemetry telemetry = new Telemetry(null, null); + public void shouldAcceptNullVersionAlwaysIncludeJavaVersion() throws Exception { + Telemetry telemetry = new Telemetry("auth0-java", null); assertThat(telemetry.getValue(), is(notNullValue())); assertThat(telemetry.getEnvironment(), is(notNullValue())); } + @Test + public void shouldNotAcceptNullName() throws Exception { + Telemetry telemetry = new Telemetry(null, null); + assertThat(telemetry.getValue(), is(nullValue())); + assertThat(telemetry.getEnvironment(), is(notNullValue())); + } + @Test public void shouldGetName() throws Exception { Telemetry telemetry = new Telemetry("auth0-java", "1.0.0"); @@ -68,17 +75,17 @@ public void shouldGetVersion() throws Exception { } @Test - public void shouldNotIncludeCoreIfNotProvided() throws Exception { + public void shouldNotIncludeLibraryVersionIfNotProvided() throws Exception { Telemetry telemetry = new Telemetry("auth0-java", "1.0.0"); assertThat(telemetry.getLibraryVersion(), is(nullValue())); - assertThat(telemetry.getEnvironment().containsKey("core"), is(false)); + assertThat(telemetry.getEnvironment().containsKey("auth0-java"), is(false)); } @Test public void shouldGetLibraryVersion() throws Exception { Telemetry telemetry = new Telemetry("auth0-java", "1.0.0", "2.1.3"); assertThat(telemetry.getLibraryVersion(), is("2.1.3")); - assertThat(telemetry.getEnvironment().get("core"), is("2.1.3")); + assertThat(telemetry.getEnvironment().get("auth0-java"), is("2.1.3")); } } \ No newline at end of file