Skip to content

Commit

Permalink
refactor: only use deliverycompat when old API called
Browse files Browse the repository at this point in the history
  • Loading branch information
fractalwrench committed May 8, 2018
1 parent 1582bd0 commit ae74ec1
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public void testSetSendThreads() throws Exception {

@Test
public void testDefaultClientDelivery() {
assertTrue(client.config.getDelivery() instanceof DeliveryCompat);
assertFalse(client.config.getDelivery() instanceof DeliveryCompat);
}

@Test
Expand All @@ -107,11 +107,6 @@ public void deliver(Report report,
};
config.setDelivery(customDelivery);
client = new Client(context, config);

Delivery delivery = client.config.getDelivery();
assertTrue(client.config.getDelivery() instanceof DeliveryCompat);

DeliveryCompat compat = (DeliveryCompat) delivery;
assertEquals(customDelivery, compat.delivery);
assertEquals(customDelivery, client.config.getDelivery());
}
}
19 changes: 16 additions & 3 deletions sdk/src/main/java/com/bugsnag/android/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,9 @@ public Client(@NonNull Context androidContext, @NonNull Configuration configurat
ConnectivityManager cm =
(ConnectivityManager) appContext.getSystemService(Context.CONNECTIVITY_SERVICE);

//noinspection ConstantConditions
if (configuration.getDelivery() == null) {
configuration.setDelivery(new DeliveryCompat(new DefaultDelivery(cm)));
configuration.setDelivery(new DefaultDelivery(cm));
}

sessionTracker =
Expand Down Expand Up @@ -628,13 +629,25 @@ void setUserName(String name, boolean notify) {
}
}

DeliveryCompat getAndSetDeliveryCompat() {
Delivery current = config.getDelivery();

if (current instanceof DeliveryCompat) {
return (DeliveryCompat)current;
} else {
DeliveryCompat compat = new DeliveryCompat();
config.setDelivery(compat);
return compat;
}
}

@SuppressWarnings("ConstantConditions")
@Deprecated
void setErrorReportApiClient(@NonNull ErrorReportApiClient errorReportApiClient) {
if (errorReportApiClient == null) {
throw new IllegalArgumentException("ErrorReportApiClient cannot be null.");
}
DeliveryCompat compat = (DeliveryCompat) config.getDelivery();
DeliveryCompat compat = getAndSetDeliveryCompat();
compat.errorReportApiClient = errorReportApiClient;
}

Expand All @@ -644,7 +657,7 @@ void setSessionTrackingApiClient(@NonNull SessionTrackingApiClient apiClient) {
if (apiClient == null) {
throw new IllegalArgumentException("SessionTrackingApiClient cannot be null.");
}
DeliveryCompat compat = (DeliveryCompat) config.getDelivery();
DeliveryCompat compat = getAndSetDeliveryCompat();
compat.sessionTrackingApiClient = apiClient;
}

Expand Down
7 changes: 1 addition & 6 deletions sdk/src/main/java/com/bugsnag/android/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Observable;
Expand Down Expand Up @@ -523,11 +522,7 @@ public void setDelivery(@NonNull Delivery delivery) {
if (delivery == null) {
throw new IllegalArgumentException("Delivery cannot be null");
}
if (delivery instanceof DeliveryCompat) {
this.delivery = delivery;
} else {
this.delivery = new DeliveryCompat(delivery);
}
this.delivery = delivery;
}

/**
Expand Down
9 changes: 0 additions & 9 deletions sdk/src/main/java/com/bugsnag/android/DeliveryCompat.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,9 @@
*/
class DeliveryCompat implements Delivery {

final Delivery delivery;
volatile ErrorReportApiClient errorReportApiClient;
volatile SessionTrackingApiClient sessionTrackingApiClient;

DeliveryCompat(Delivery delivery) {
this.delivery = delivery;
}

@Override
public void deliver(SessionTrackingPayload payload,
Configuration config) throws DeliveryFailureException {
Expand All @@ -29,8 +24,6 @@ public void deliver(SessionTrackingPayload payload,
} catch (NetworkException | BadResponseException exception) {
throw convertException(exception);
}
} else {
delivery.deliver(payload, config);
}
}

Expand All @@ -43,8 +36,6 @@ public void deliver(Report report, Configuration config) throws DeliveryFailureE
} catch (NetworkException | BadResponseException exception) {
throw convertException(exception);
}
} else {
delivery.deliver(report, config);
}
}

Expand Down

0 comments on commit ae74ec1

Please sign in to comment.