Skip to content

Commit

Permalink
Use AssertJ in tests (#4713)
Browse files Browse the repository at this point in the history
  • Loading branch information
oldergod authored and swankjesse committed Mar 14, 2019
1 parent a217a39 commit 6c4855a
Show file tree
Hide file tree
Showing 92 changed files with 4,940 additions and 4,622 deletions.
5 changes: 5 additions & 0 deletions mockwebserver/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import org.junit.After;
import org.junit.Test;

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

public class CustomDispatcherTest {
private MockWebServer mockWebServer = new MockWebServer();
Expand All @@ -44,13 +44,13 @@ public MockResponse dispatch(RecordedRequest request) {
return new MockResponse();
}
};
assertEquals(0, requestsMade.size());
assertThat(requestsMade.size()).isEqualTo(0);
mockWebServer.setDispatcher(dispatcher);
final URL url = mockWebServer.url("/").url();
final HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.getResponseCode(); // Force the connection to hit the "server".
// Make sure our dispatcher got the request.
assertEquals(1, requestsMade.size());
assertThat(requestsMade.size()).isEqualTo(1);
}

@Test public void outOfOrderResponses() throws Exception {
Expand All @@ -75,12 +75,16 @@ public MockResponse dispatch(RecordedRequest request) throws InterruptedExceptio
final Thread endsFirst = buildRequestThread(secondRequest, secondResponseCode);
endsFirst.start();
endsFirst.join();
assertEquals(0, firstResponseCode.get()); // First response is still waiting.
assertEquals(200, secondResponseCode.get()); // Second response is done.
// First response is still waiting.
assertThat(firstResponseCode.get()).isEqualTo(0);
// Second response is done.
assertThat(secondResponseCode.get()).isEqualTo(200);
latch.countDown();
startsFirst.join();
assertEquals(200, firstResponseCode.get()); // And now it's done!
assertEquals(200, secondResponseCode.get()); // (Still done).
// And now it's done!
assertThat(firstResponseCode.get()).isEqualTo(200);
// (Still done).
assertThat(secondResponseCode.get()).isEqualTo(200);
}

private Thread buildRequestThread(String path, AtomicInteger responseCode) {
Expand Down
Loading

0 comments on commit 6c4855a

Please sign in to comment.