RepositoryDataSource { public Observable<List<TreeNode>> getContent(final String owner, final String repo, final Branch branch) { return repositoryApi.getContent(owner, repo, branch.getCommit().getSha()) .map(new Func1<GitTree, List<TreeNode>>() { @Override public List<TreeNode> call(GitTree gitTree) { List<GitTree.TreeEntity> treeEntities = gitTree.getTree(); List<TreeNode> treeViewNodes = new ArrayList<>(treeEntities.size()); for (int index = 0; index < treeEntities.size(); ) { GitTree.TreeEntity treeEntity = treeEntities.get(index++); switch (treeEntity.getNodeType()) { case GitTree.DIR: TreeNode<Dir> dirTreeNode = new TreeNode<>(new Dir(treeEntity.getPath(), treeEntity.getPath())); index = findChildNode(treeEntities, index, dirTreeNode, treeEntity.getPath(), owner, repo, branch.getName()); treeViewNodes.add(dirTreeNode); break; case GitTree.FILE: treeViewNodes.add(new TreeNode<>(new File(treeEntity.getPath(), treeEntity.getHtml_url(owner, repo, branch.getName())))); break; } } sortNodeList(treeViewNodes); return treeViewNodes; } }).compose(RxJavaUtils.<List<TreeNode>>applySchedulers()); } RepositoryDataSource(RepositoryService repositoryApi); Observable<RepositoryInfo> getRepoInfo(String owner, String repo); Observable<List<RepositoryInfo>> listForks(String owner, String repo, int page); Observable<List<UserEntity>> listWatchers(String owner, String repo, int page); Observable<List<UserEntity>> listStargazers(String owner, String repo, int page); Observable<List<UserEntity>> listContributors(String owner, String repo, int page); Observable<RepositoryInfo> toFork(String owner, String repo); Observable<Boolean> toStar(String owner, String repo); Observable<Boolean> toWatch(String owner, String repo); Observable<Boolean> unStar(String owner, String repo); Observable<Boolean> unWatch(String owner, String repo); Observable<Boolean> checkStarred(String owner, String repo); Observable<Boolean> checkWatching(String owner, String repo); Observable<Boolean> delete(String owner, String repo); Observable<List<Branch>> listBranches(String owner, String repo); Observable<List<TreeNode>> getContent(final String owner, final String repo, final Branch branch); Observable<SearchResult<RepositoryInfo>> search(String keyWord, String language, int page); Observable<SearchResult<RepositoryInfo>> search(String keyWord, String language, SortType_Repo sort, int page); Observable<ReadMe> getReadMe(String owner, String repo);  }
@Test public void getContent() throws Exception { TestSubscriber<List<Branch>> branchSubscriber = TestSubscriber.create(); repositoryDataSource.listBranches("TellH", "GitClub").subscribe(branchSubscriber); List<Branch> branches = branchSubscriber.getOnNextEvents().get(0); assertNotNull(branches); assertTrue(branches.size() > 0); TestSubscriber<List<TreeNode>> treeNodeSubscriber = TestSubscriber.create(); repositoryDataSource.getContent("TellH", "GitClub", branches.get(0)).subscribe(treeNodeSubscriber); List<TreeNode> treeNodes = treeNodeSubscriber.getOnNextEvents().get(0); assertNotNull(treeNodes); }