Retrofit rx (#2519)
* Retrofit with RxJava * Correct spelling mistake * Use spaces for indentation instead of tabs in pom.xml * Use spaces for indentation instead of tabs in pom.xml * Add Retrofit integration with RxJava to libraries module * Remove standalone project for Retrofit integration with RxJava * remove retrofit-rxjava module * Fixed error in pom.xml caused by an issue while merging * Retrofit integration with RxJava * Fix test cases * Fix merge issues * BAEL-1016 Merging master
This commit is contained in:
committed by
Predrag Maric
parent
b49ad4ea59
commit
fd37ffb7c2
@@ -0,0 +1,65 @@
|
||||
package com.baeldung.retrofit.basic;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.baeldung.retrofit.basic.GitHubBasicApi;
|
||||
import com.baeldung.retrofit.models.Contributor;
|
||||
import com.baeldung.retrofit.models.Repository;
|
||||
|
||||
import retrofit2.Retrofit;
|
||||
import retrofit2.converter.gson.GsonConverterFactory;
|
||||
|
||||
public class GitHubBasicApiTest {
|
||||
|
||||
GitHubBasicApi gitHub;
|
||||
|
||||
@Before
|
||||
public void init() {
|
||||
Retrofit retrofit = new Retrofit.Builder()
|
||||
.baseUrl("https://api.github.com/")
|
||||
.addConverterFactory(GsonConverterFactory.create())
|
||||
.build();
|
||||
|
||||
gitHub = retrofit.create(GitHubBasicApi.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenListRepos_thenExpectReposThatContainTutorials() {
|
||||
try {
|
||||
List<Repository> repos = gitHub
|
||||
.listRepos("eugenp")
|
||||
.execute()
|
||||
.body();
|
||||
|
||||
assertThat(repos)
|
||||
.isNotEmpty()
|
||||
.extracting(Repository::getName).contains("tutorials");
|
||||
} catch (IOException e) {
|
||||
fail("Can not communicate with GitHub API");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenListRepoContributers_thenExpectContributorsThatContainEugenp() {
|
||||
try {
|
||||
List<Contributor> contributors = gitHub
|
||||
.listRepoContributors("eugenp", "tutorials")
|
||||
.execute()
|
||||
.body();
|
||||
|
||||
assertThat(contributors)
|
||||
.isNotEmpty()
|
||||
.extracting(Contributor::getName).contains("eugenp");
|
||||
} catch (IOException e) {
|
||||
fail("Can not communicate with GitHub API");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package com.baeldung.retrofit.rx;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.baeldung.retrofit.models.Contributor;
|
||||
import com.baeldung.retrofit.models.Repository;
|
||||
import com.baeldung.retrofit.rx.GitHubRxApi;
|
||||
|
||||
import retrofit2.Retrofit;
|
||||
import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory;
|
||||
import retrofit2.converter.gson.GsonConverterFactory;
|
||||
|
||||
public class GitHubRxApiTest {
|
||||
|
||||
GitHubRxApi gitHub;
|
||||
|
||||
@Before
|
||||
public void init() {
|
||||
Retrofit retrofit = new Retrofit.Builder()
|
||||
.baseUrl("https://api.github.com/")
|
||||
.addConverterFactory(GsonConverterFactory.create())
|
||||
.addCallAdapterFactory(RxJavaCallAdapterFactory.create())
|
||||
.build();
|
||||
|
||||
gitHub = retrofit.create(GitHubRxApi.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenListRepos_thenExpectReposThatContainTutorials() {
|
||||
gitHub
|
||||
.listRepos("eugenp")
|
||||
.subscribe( repos -> {
|
||||
assertThat(repos)
|
||||
.isNotEmpty()
|
||||
.extracting(Repository::getName).contains("tutorials");
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenListRepoContributers_thenExpectContributorsThatContainEugenp() {
|
||||
gitHub
|
||||
.listRepoContributors("eugenp", "tutorials")
|
||||
.subscribe(contributors -> {
|
||||
assertThat(contributors)
|
||||
.isNotEmpty()
|
||||
.extracting(Contributor::getName).contains("eugenp");
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user