Browse Source

Adding simple unit tests

master
anthony restaino 8 years ago
parent
commit
6f07c8e7da
  1. 3
      .travis.yml
  2. 1
      app/build.gradle
  3. 19
      app/src/test/java/acr/browser/lightning/utils/PreconditionsTest.java
  4. 41
      app/src/test/java/acr/browser/lightning/utils/SubscriptionUtilsTest.java

3
.travis.yml

@ -18,4 +18,5 @@ before_install:
install: install:
- ./gradlew - ./gradlew
script: script:
- ./gradlew assembleDebug --stacktrace - ./gradlew :app:assembleDebug --stacktrace
- ./gradlew :app:test --stacktrace

1
app/build.gradle

@ -63,6 +63,7 @@ dexcount {
} }
dependencies { dependencies {
testCompile 'junit:junit:4.12'
// support libraries // support libraries
def supportLibVersion = '25.4.0' def supportLibVersion = '25.4.0'

19
app/src/test/java/acr/browser/lightning/utils/PreconditionsTest.java

@ -0,0 +1,19 @@
package acr.browser.lightning.utils;
import org.junit.Test;
/**
* Unit tests for {@link Preconditions}.
*/
public class PreconditionsTest {
@Test(expected = RuntimeException.class)
public void checkNonNull_Null_ThrowsException() {
Preconditions.checkNonNull(null);
}
@Test
public void checkNonNull_NonNull_Succeeds() {
Preconditions.checkNonNull(new Object());
}
}

41
app/src/test/java/acr/browser/lightning/utils/SubscriptionUtilsTest.java

@ -0,0 +1,41 @@
package acr.browser.lightning.utils;
import com.anthonycr.bonsai.Subscription;
import org.junit.Assert;
import org.junit.Test;
/**
* Unit tests for {@link SubscriptionUtils}.
*/
public class SubscriptionUtilsTest {
@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());
}
}
Loading…
Cancel
Save