Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -341,12 +341,6 @@
<version>0.6</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-library</artifactId>
<version>1.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.cedarsoftware</groupId>
<artifactId>java-util</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package com.google.firebase.auth.internal;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;

import com.google.api.client.auth.openidconnect.IdToken;
import com.google.api.client.googleapis.auth.oauth2.GooglePublicKeysManager;
Expand All @@ -42,7 +42,6 @@
import java.security.spec.InvalidKeySpecException;
import java.security.spec.KeySpec;
import java.security.spec.PKCS8EncodedKeySpec;
import org.hamcrest.collection.IsIterableContainingInOrder;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
Expand Down Expand Up @@ -130,7 +129,7 @@ public void verifyToken() throws Exception {
FACTORY, createToken(createHeader(), createPayload()));

IdToken.Payload payload = (IdToken.Payload) token.getClaims();
assertThat(payload.getAudienceAsList(), IsIterableContainingInOrder.contains(PROJECT_ID));
assertTrue(payload.getAudienceAsList().contains(PROJECT_ID));
assertEquals(ISSUER, payload.getIssuer());

verifier.verifyTokenAndSignature(TestOnlyImplFirebaseAuthTrampolines.getToken(token));
Expand Down
43 changes: 23 additions & 20 deletions src/test/java/com/google/firebase/tasks/TaskImplTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,25 @@

package com.google.firebase.tasks;

import static org.hamcrest.Matchers.instanceOf;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import com.google.firebase.internal.NonNull;
import com.google.firebase.tasks.testing.TestOnCompleteListener;
import com.google.firebase.tasks.testing.TestOnFailureListener;
import com.google.firebase.tasks.testing.TestOnSuccessListener;
import java.rmi.RemoteException;
import org.hamcrest.Matchers;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;

public class TaskImplTest {

private static final Exception EXCEPTION = new RemoteException();
private static final Void NULL_RESULT = null;
private static final String NON_NULL_RESULT = "Success";
@Rule public ExpectedException expectedException = ExpectedException.none();

@Test
public void testIsComplete_notComplete() {
Expand Down Expand Up @@ -133,20 +129,25 @@ public void testGetResult_failure() {
TaskImpl<Void> task = new TaskImpl<>();
task.setException(EXCEPTION);

expectedException.expect(RuntimeExecutionException.class);
expectedException.expectCause(Matchers.is(EXCEPTION));

task.getResult();
try {
task.getResult();
fail("No exception thrown");
} catch (RuntimeExecutionException e) {
assertSame(EXCEPTION, e.getCause());
}
}

@Test
public void testGetResult_exceptionIsSpecifiedType() throws Exception {
TaskImpl<Void> task = new TaskImpl<>();
task.setException(EXCEPTION);

expectedException.expect(Matchers.is(EXCEPTION));

task.getResult(RemoteException.class);
try {
task.getResult(RemoteException.class);
fail("No exception thrown");
} catch (RemoteException e) {
assertSame(EXCEPTION, e);
}
}

@Test
Expand All @@ -155,10 +156,12 @@ public void testGetResult_exceptionIsNotSpecifiedType() throws Exception {
Exception exception = new RuntimeException();
task.setException(exception);

expectedException.expect(RuntimeExecutionException.class);
expectedException.expectCause(Matchers.is(exception));

task.getResult(RemoteException.class);
try {
task.getResult(RemoteException.class);
fail("No exception thrown");
} catch (RuntimeExecutionException e) {
assertSame(exception, e.getCause());
}
}

@Test
Expand Down Expand Up @@ -407,7 +410,7 @@ public Void then(@NonNull Task<Void> task) throws Exception {
}
});
task.setResult(null);
assertThat(task2.getException(), instanceOf(RuntimeExecutionException.class));
assertTrue(task2.getException() instanceof RuntimeExecutionException);
}

@Test
Expand Down Expand Up @@ -507,7 +510,7 @@ public Task<Void> then(@NonNull Task<Void> task) throws Exception {
}
});
task.setResult(null);
assertThat(task2.getException(), instanceOf(RuntimeExecutionException.class));
assertTrue(task2.getException() instanceof RuntimeExecutionException);
}

@Test
Expand Down Expand Up @@ -560,7 +563,7 @@ public Task<Void> then(@NonNull Task<String> task) throws Exception {
}
});
task.setResult(NON_NULL_RESULT);
assertThat(task2.getException(), instanceOf(NullPointerException.class));
assertTrue(task2.getException() instanceof NullPointerException);
}

@Test(expected = IllegalStateException.class)
Expand Down
60 changes: 36 additions & 24 deletions src/test/java/com/google/firebase/tasks/TasksTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import java.rmi.RemoteException;
import java.util.concurrent.Callable;
Expand All @@ -27,10 +30,7 @@
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import org.hamcrest.Matchers;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;

public class TasksTest {

Expand All @@ -39,7 +39,6 @@ public class TasksTest {
private static final int SCHEDULE_DELAY_MS = 50;
private static final int TIMEOUT_MS = 200;
private final ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
@Rule public ExpectedException expectedException = ExpectedException.none();

@Test
public void testForResult() throws Exception {
Expand Down Expand Up @@ -141,42 +140,52 @@ public void testAwait_noTimeout() throws Exception {

@Test
public void testAwait_exception() throws Exception {
expectedException.expect(ExecutionException.class);
expectedException.expectCause(Matchers.is(EXCEPTION));

TaskCompletionSource<Void> completionSource = new TaskCompletionSource<>();
scheduleException(completionSource);

Tasks.await(completionSource.getTask(), TIMEOUT_MS, TimeUnit.MILLISECONDS);
try {
Tasks.await(completionSource.getTask(), TIMEOUT_MS, TimeUnit.MILLISECONDS);
fail("No exception thrown");
} catch (ExecutionException e) {
assertSame(EXCEPTION, e.getCause());
}
}

@Test
public void testAwait_noTimeoutException() throws Exception {
expectedException.expect(ExecutionException.class);
expectedException.expectCause(Matchers.is(EXCEPTION));

TaskCompletionSource<Void> completionSource = new TaskCompletionSource<>();
scheduleException(completionSource);

Tasks.await(completionSource.getTask());
try {
Tasks.await(completionSource.getTask());
fail("No exception thrown");
} catch (ExecutionException e) {
assertSame(EXCEPTION, e.getCause());
}
}

@Test
public void testAwait_alreadyFailed() throws Exception {
expectedException.expect(ExecutionException.class);
expectedException.expectCause(Matchers.is(EXCEPTION));

Task<Object> task = Tasks.forException(EXCEPTION);
Tasks.await(task, TIMEOUT_MS, TimeUnit.MILLISECONDS);

try {
Tasks.await(task, TIMEOUT_MS, TimeUnit.MILLISECONDS);
fail("No exception thrown");
} catch (ExecutionException e) {
assertSame(EXCEPTION, e.getCause());
}
}

@Test
public void testAwait_noTimeoutAlreadyFailed() throws Exception {
expectedException.expect(ExecutionException.class);
expectedException.expectCause(Matchers.is(EXCEPTION));

Task<Object> task = Tasks.forException(EXCEPTION);
Tasks.await(task);

try {
Tasks.await(task);
fail("No exception thrown");
} catch (ExecutionException e) {
assertSame(EXCEPTION, e.getCause());
}
}

@Test
Expand Down Expand Up @@ -229,13 +238,16 @@ public void testWhenAll_partiallyCompleted() throws Exception {

@Test
public void testWhenAll_completedFailure() throws Exception {
expectedException.expect(ExecutionException.class);
expectedException.expectCause(Matchers.any(ExecutionException.class));

Task<Object> task1 = Tasks.forResult(RESULT);
Task<Object> task2 = Tasks.forException(EXCEPTION);
Task<Void> task = Tasks.whenAll(task1, task2);
Tasks.await(task);

try {
Tasks.await(task);
fail("No exception thrown");
} catch (ExecutionException e) {
assertTrue(e.getCause() instanceof ExecutionException);
}
}

@Test
Expand Down