Skip to content

Commit

Permalink
Merge pull request #589 from segmentio/spotless
Browse files Browse the repository at this point in the history
replace javafmt with spotless
  • Loading branch information
f2prateek authored Aug 28, 2018
2 parents e55e935 + 0312c0c commit 24a5139
Show file tree
Hide file tree
Showing 30 changed files with 410 additions and 417 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
fi
- run:
name: Build
command: ./gradlew checkFmt build assembleAndroidTest
command: ./gradlew check build assembleAndroidTest
- run:
name: Run E2E Test
command: |
Expand Down
1 change: 0 additions & 1 deletion analytics-samples/analytics-sample/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
apply plugin: 'com.android.application'
apply plugin: 'com.f2prateek.javafmt'

apply from: rootProject.file('gradle/android.gradle')

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package com.segment.analytics;


import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.fail;

import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
import com.segment.analytics.webhook.WebhookService;
import com.segment.analytics.sample.MainActivity;
import com.segment.analytics.sample.test.BuildConfig;
import com.segment.analytics.webhook.WebhookService;
import com.segment.backo.Backo;
import java.io.IOException;
import java.util.List;
Expand All @@ -34,7 +33,8 @@
* connected to the source connected to the source (configured manually via the app) is able to
* receive the data sent by this library.
*
* See https://paper.dropbox.com/doc/Libraries-End-to-End-Tests-ESEakc3LxFrqcHz69AmyN for details.
* <p>See https://paper.dropbox.com/doc/Libraries-End-to-End-Tests-ESEakc3LxFrqcHz69AmyN for
* details.
*/
@RunWith(AndroidJUnit4.class)
public class E2ETest {
Expand All @@ -56,35 +56,40 @@ public class E2ETest {
/** Credentials to retrieve data from the webhook. */
private static final String WEBHOOK_AUTH_USERNAME = BuildConfig.WEBHOOK_AUTH_USERNAME;

private static final Backo BACKO = Backo.builder()
.base(TimeUnit.SECONDS, 1)
.cap(TimeUnit.SECONDS, 5)
.build();
private static final Backo BACKO =
Backo.builder().base(TimeUnit.SECONDS, 1).cap(TimeUnit.SECONDS, 5).build();

private Analytics analytics;
private WebhookService webhookService;

@Before
public void setup() {
analytics = new Analytics.Builder(activityActivityTestRule.getActivity(), SEGMENT_WRITE_KEY)
.build();

webhookService = new Retrofit.Builder()
.baseUrl("https://webhook-e2e.segment.com")
.addConverterFactory(MoshiConverterFactory.create())
.client(new OkHttpClient.Builder()
.addNetworkInterceptor(new Interceptor() {
@Override
public okhttp3.Response intercept(Chain chain) throws IOException {
return chain.proceed(chain.request()
.newBuilder()
.addHeader("Authorization", Credentials.basic(WEBHOOK_AUTH_USERNAME, ""))
.build());
}
})
.build())
.build()
.create(WebhookService.class);
analytics =
new Analytics.Builder(activityActivityTestRule.getActivity(), SEGMENT_WRITE_KEY).build();

webhookService =
new Retrofit.Builder()
.baseUrl("https://webhook-e2e.segment.com")
.addConverterFactory(MoshiConverterFactory.create())
.client(
new OkHttpClient.Builder()
.addNetworkInterceptor(
new Interceptor() {
@Override
public okhttp3.Response intercept(Chain chain) throws IOException {
return chain.proceed(
chain
.request()
.newBuilder()
.addHeader(
"Authorization",
Credentials.basic(WEBHOOK_AUTH_USERNAME, ""))
.build());
}
})
.build())
.build()
.create(WebhookService.class);
}

@After
Expand Down Expand Up @@ -143,14 +148,11 @@ private void assertMessageReceivedByWebhook(String id) {
fail("did not find message with id: " + id);
}

/**
* Returns {@code true} if a message with the provided ID is found in the webhook.
*/
/** Returns {@code true} if a message with the provided ID is found in the webhook. */
@SuppressWarnings("ConstantConditions")
private boolean hasMatchingRequest(String id) throws IOException {
Response<List<String>> messagesResponse = webhookService
.messages(WEBHOOK_BUCKET, 500)
.execute();
Response<List<String>> messagesResponse =
webhookService.messages(WEBHOOK_BUCKET, 500).execute();

assertThat(messagesResponse.code()).isEqualTo(200);

Expand All @@ -164,9 +166,7 @@ private boolean hasMatchingRequest(String id) throws IOException {
return false;
}

/**
* Skips tests if they were supposed to be ignored.
*/
/** Skips tests if they were supposed to be ignored. */
static class EndToEndTestsDisabledRule implements MethodRule {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@
android:id="@+id/user_id"
android:hint="@string/identify_user_id"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
android:layout_height="wrap_content"
android:inputType="text"/>

<Button
android:id="@+id/action_identify"
Expand Down
1 change: 0 additions & 1 deletion analytics-samples/analytics-wear-sample/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
apply plugin: 'com.android.application'
apply plugin: 'com.f2prateek.javafmt'

apply from: rootProject.file('gradle/android.gradle')

Expand Down
1 change: 0 additions & 1 deletion analytics-tests/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
apply plugin: 'com.android.library'
apply plugin: 'com.f2prateek.javafmt'

apply from: rootProject.file('gradle/android.gradle')

Expand Down
1 change: 0 additions & 1 deletion analytics-wear/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
apply plugin: 'com.android.library'
apply plugin: 'com.f2prateek.javafmt'

apply from: rootProject.file('gradle/android.gradle')

Expand Down
2 changes: 0 additions & 2 deletions analytics/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
apply plugin: 'com.android.library'
apply plugin: 'com.vanniktech.android.junit.jacoco'
apply plugin: 'com.f2prateek.javafmt'
apply plugin: 'com.getkeepsafe.dexcount'

apply from: rootProject.file('gradle/android.gradle')
Expand Down
2 changes: 1 addition & 1 deletion analytics/src/main/java/com/segment/analytics/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@

package com.segment.analytics;

import static com.segment.analytics.internal.Utils.readFully;
import static com.segment.analytics.internal.Utils.getInputStream;
import static com.segment.analytics.internal.Utils.readFully;
import static java.net.HttpURLConnection.HTTP_OK;

import android.text.TextUtils;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public static Date toISO8601Date(String date) throws ParseException {
return parseISO8601Date(date);
}

//TODO: Migrate other coercion methods.
// TODO: Migrate other coercion methods.

/**
* Returns the float representation at {@code value} if it exists and is a float or can be coerced
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,13 @@ public void invalidMiddlewareThrowsException() throws Exception {
}

try {
Middleware middleware = new Middleware() {
@Override
public void intercept(Chain chain) {
throw new AssertionError("should not be invoked");
}
};
Middleware middleware =
new Middleware() {
@Override
public void intercept(Chain chain) {
throw new AssertionError("should not be invoked");
}
};
new Builder(context, "foo").middleware(middleware).middleware(middleware);
fail("Registering middleware twice throw exception.");
} catch (IllegalStateException expected) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,10 @@ public void createWithoutDeviceIdCollection() {
context = AnalyticsContext.create(RuntimeEnvironment.application, traits, false);

assertThat(context.getValueMap("device")) //
.containsEntry("id", traits.anonymousId())
.containsEntry("manufacturer", "unknown")
.containsEntry("model", "unknown")
.containsEntry("name", "unknown");
.containsEntry("id", traits.anonymousId())
.containsEntry("manufacturer", "unknown")
.containsEntry("model", "unknown")
.containsEntry("name", "unknown");
}

@Test
Expand Down
97 changes: 48 additions & 49 deletions analytics/src/test/java/com/segment/analytics/AnalyticsTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,29 @@
package com.segment.analytics;

import static android.content.Context.MODE_PRIVATE;
import static com.segment.analytics.Analytics.LogLevel.NONE;
import static com.segment.analytics.Analytics.LogLevel.VERBOSE;
import static com.segment.analytics.TestUtils.SynchronousExecutor;
import static com.segment.analytics.TestUtils.grantPermission;
import static com.segment.analytics.TestUtils.mockApplication;
import static com.segment.analytics.Utils.createContext;
import static com.segment.analytics.internal.Utils.DEFAULT_FLUSH_INTERVAL;
import static com.segment.analytics.internal.Utils.DEFAULT_FLUSH_QUEUE_SIZE;
import static com.segment.analytics.internal.Utils.isNullOrEmpty;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.argThat;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
import static org.mockito.MockitoAnnotations.initMocks;

import android.Manifest;
import android.app.Activity;
import android.app.Application;
Expand All @@ -10,7 +34,6 @@
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Bundle;

import com.segment.analytics.TestUtils.NoDescriptionMatcher;
import com.segment.analytics.integrations.AliasPayload;
import com.segment.analytics.integrations.GroupPayload;
Expand All @@ -20,7 +43,11 @@
import com.segment.analytics.integrations.ScreenPayload;
import com.segment.analytics.integrations.TrackPayload;
import com.segment.analytics.internal.Utils.AnalyticsNetworkExecutorService;

import java.io.IOException;
import java.util.Collections;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.atomic.AtomicReference;
import org.assertj.core.data.MapEntry;
import org.hamcrest.Description;
import org.hamcrest.TypeSafeMatcher;
Expand All @@ -35,36 +62,6 @@
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;

import java.io.IOException;
import java.util.Collections;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.atomic.AtomicReference;

import static android.content.Context.MODE_PRIVATE;
import static com.segment.analytics.Analytics.LogLevel.NONE;
import static com.segment.analytics.Analytics.LogLevel.VERBOSE;
import static com.segment.analytics.TestUtils.SynchronousExecutor;
import static com.segment.analytics.TestUtils.grantPermission;
import static com.segment.analytics.TestUtils.mockApplication;
import static com.segment.analytics.Utils.createContext;
import static com.segment.analytics.internal.Utils.DEFAULT_FLUSH_INTERVAL;
import static com.segment.analytics.internal.Utils.DEFAULT_FLUSH_QUEUE_SIZE;
import static com.segment.analytics.internal.Utils.isNullOrEmpty;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.argThat;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
import static org.mockito.MockitoAnnotations.initMocks;

@RunWith(RobolectricTestRunner.class)
@Config(manifest = Config.NONE)
public class AnalyticsTest {
Expand Down Expand Up @@ -564,8 +561,7 @@ protected boolean matchesSafely(Traits traits) {
}

@Override
public void describeTo(Description description) {
}
public void describeTo(Description description) {}
}));
assertThat(analyticsContext.traits()).hasSize(1).containsKey("anonymousId");
}
Expand Down Expand Up @@ -796,7 +792,8 @@ public void trackApplicationLifecycleEventsUpdated() throws NameNotFoundExceptio
editor.putInt("build", 100);
editor.putString("version", "1.0.0");
editor.apply();
when(application.getSharedPreferences("analytics-android-qaz", MODE_PRIVATE)).thenReturn(sharedPreferences);
when(application.getSharedPreferences("analytics-android-qaz", MODE_PRIVATE))
.thenReturn(sharedPreferences);

PackageManager packageManager = mock(PackageManager.class);
when(packageManager.getPackageInfo("com.foo", 0)).thenReturn(packageInfo);
Expand Down Expand Up @@ -1026,23 +1023,25 @@ public void unregisterActivityLifecycleCallbacks() throws NameNotFoundException
doNothing()
.when(application)
.registerActivityLifecycleCallbacks(
argThat(new NoDescriptionMatcher<Application.ActivityLifecycleCallbacks>() {
@Override
protected boolean matchesSafely(Application.ActivityLifecycleCallbacks item) {
registeredCallback.set(item);
return true;
}
}));
argThat(
new NoDescriptionMatcher<Application.ActivityLifecycleCallbacks>() {
@Override
protected boolean matchesSafely(Application.ActivityLifecycleCallbacks item) {
registeredCallback.set(item);
return true;
}
}));
doNothing()
.when(application)
.unregisterActivityLifecycleCallbacks(
argThat(new NoDescriptionMatcher<Application.ActivityLifecycleCallbacks>() {
@Override
protected boolean matchesSafely(Application.ActivityLifecycleCallbacks item) {
unregisteredCallback.set(item);
return true;
}
}));
argThat(
new NoDescriptionMatcher<Application.ActivityLifecycleCallbacks>() {
@Override
protected boolean matchesSafely(Application.ActivityLifecycleCallbacks item) {
unregisteredCallback.set(item);
return true;
}
}));

analytics =
new Analytics(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ public void decodesArraysWithLists() throws IOException {
@Test
public void encodesArraysWithArrays() throws IOException {
Map<String, Object> map =
ImmutableMap.<String, Object>builder().put("a", new String[]{"b", "c", "d"}).build();
ImmutableMap.<String, Object>builder().put("a", new String[] {"b", "c", "d"}).build();

assertThat(cartographer.toJson(map))
.isEqualTo(
Expand All @@ -250,7 +250,7 @@ public void encodesPrimitiveArrays() throws IOException {
// Exercise a bug where primitive arrays would throw an IOException.
// https://github.com/segmentio/analytics-android/issues/507
Map<String, Object> map =
ImmutableMap.<String, Object>builder().put("a", new int[]{1, 2}).build();
ImmutableMap.<String, Object>builder().put("a", new int[] {1, 2}).build();

assertThat(cartographer.toJson(map))
.isEqualTo("{\n" + " \"a\": [\n" + " 1,\n" + " 2\n" + " ]\n" + "}");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ public void getAdvertisingIdAmazonFireOSLimitAdTracking0() throws Exception {
task.execute(context);
latch.await();

assertThat(analyticsContext.device()).containsEntry("advertisingId", "df07c7dc-cea7-4a89-b328-810ff5acb15d");
assertThat(analyticsContext.device())
.containsEntry("advertisingId", "df07c7dc-cea7-4a89-b328-810ff5acb15d");
assertThat(analyticsContext.device()).containsEntry("adTrackingEnabled", true);
}
}
Loading

0 comments on commit 24a5139

Please sign in to comment.