Last active
September 25, 2016 12:38
-
-
Save dherges/3fdc0b177b0a036f29e370f101f9eaac to your computer and use it in GitHub Desktop.
ok-testing-reloaded-medium
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Representation of a Tweet object transferred from/to Twitter REST API in JSON format. | |
| */ | |
| public class Tweet { | |
| public long id; | |
| public String text; | |
| public User user; | |
| @Json(name="created_at") public Date createdAt; | |
| public boolean favorited; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Retrofit interface for Twitter REST API | |
| */ | |
| public interface TwitterApi { | |
| @GET("statuses/home_timeline.json") | |
| Call<List<Tweet>> homeTimeline(); | |
| @GET("statuses/show/{id}") | |
| Call<Tweet> show(@Path("id") String id); | |
| @POST("statuses/update") | |
| Call<Tweet> tweet(@Query("status") String status); | |
| class Builder { | |
| /* ... */ | |
| public TwitterApi build() { | |
| return new Retrofit.Builder() | |
| .baseUrl(baseUrl) | |
| .addConverterFactory(MoshiConverterFactory.create( | |
| new Moshi.Builder() | |
| .add(Date.class, new DateJsonAdapter("EEE MMM dd kk:mm:ss z yyyy")) | |
| .build() | |
| )) | |
| .build() | |
| .create(TwitterApi.class); | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class TwitterApiTest { | |
| @Test | |
| public void homeTimeline() throws IOException, InterruptedException { | |
| /* ... */ | |
| // execute request | |
| final Response<List<Tweet>> response = twitterApi.homeTimeline().execute(); | |
| // assert response | |
| assertThat(response.body().get(0).createdAt).isEqualTo("2012-08-28T23:16:23.000"); | |
| assertThat(response.body().get(0).user.name).isEqualTo("OAuth Dancer"); | |
| /* ... */ | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Representation of an User object transferred from/to Twitter REST API in JSON format. | |
| */ | |
| public class User { | |
| public String name; | |
| @Json(name = "created_at") public Date createdAt; | |
| public String location; | |
| public String url; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment