SubscriptionUtils { public static void safeUnsubscribe(@Nullable Subscription subscription) { if (subscription != null) { subscription.unsubscribe(); } } private  SubscriptionUtils(); static void safeUnsubscribe(@Nullable Subscription subscription);  }
@Test public void safeUnsubscribe_NullSubscription_Succeeds() { SubscriptionUtils.safeUnsubscribe(null); }
@Test public void safeUnsubscribe_NonNullSubscription_SuccessfullyUnsubscribes() { Subscription subscription = new Subscription() { boolean isUnsubscribed = false; @Override public void unsubscribe() { isUnsubscribed = true; } @Override public boolean isUnsubscribed() { return isUnsubscribed; } }; Assert.assertFalse(subscription.isUnsubscribed()); SubscriptionUtils.safeUnsubscribe(subscription); Assert.assertTrue(subscription.isUnsubscribed()); }