converted IdentityPayloadTest to Kotlin
RENAME
analytics/src/test/java/com/segment/analytics/integrations/IdentifyPayloadTest.java
analytics/src/test/java/com/segment/analytics/integrations/IdentifyPayloadTest.kt
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
-package com.segment.analytics.integrations;
+package com.segment.analytics.integrations
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.Assert.fail;
+import com.nhaarman.mockitokotlin2.any
+import org.assertj.core.api.Assertions.assertThat
+import org.junit.Assert.fail
+import org.junit.Test
-import com.google.common.collect.ImmutableMap;
-import org.junit.Assert;
-import org.junit.Test;
-
-public class IdentifyPayloadTest {
+class IdentifyPayloadTest {
@Test
- public void invalidTraitsThrows() {
+ fun invalidPropertiesThrow() {
try {
- //noinspection CheckResult,ConstantConditions
- new IdentifyPayload.Builder().traits(null);
- Assert.fail();
- } catch (NullPointerException e) {
- assertThat(e).hasMessage("traits == null");
+ IdentifyPayload.Builder().traits(any())
+ fail()
+ } catch (e: NullPointerException) {
+ assertThat(e).hasMessage("traits == null")
}
}
@Test
- public void traits() {
- IdentifyPayload payload =
- new IdentifyPayload.Builder()
+ fun traits() {
+ val payload =
+ IdentifyPayload.Builder()
.userId("user_id")
- .traits(ImmutableMap.of("foo", "bar"))
- .build();
- assertThat(payload.traits()).isEqualTo(ImmutableMap.of("foo", "bar"));
- assertThat(payload)
- .containsEntry(IdentifyPayload.TRAITS_KEY, ImmutableMap.of("foo", "bar"));
+ .traits(mapOf("foo" to "bar"))
+ .build()
+ assertThat(payload.traits()).isEqualTo(mapOf("foo" to "bar"))
+ assertThat(payload).containsEntry("traits", mapOf("foo" to "bar"))
}
@Test
- public void requiresUserIdOrTraits() {
+ fun requiresUserIdOrTraits() {
try {
- //noinspection CheckResult
- new IdentifyPayload.Builder().anonymousId("anonymous_id").build();
- fail();
- } catch (NullPointerException e) {
- assertThat(e).hasMessage("either userId or traits are required");
+ IdentifyPayload.Builder().anonymousId("anonymous_id").build()
+ fail()
+ } catch (e: NullPointerException) {
+ assertThat(e).hasMessage("either userId or traits are required")
}
}
}

converted IdentityPayloadTest to Kotlin (#718)