RMP { public Observable<Professor> getProfessor(final Parameter params) { Observable<Professor> professorFromClient = mRMPClient.findProfessor(params) .onErrorResumeNext(Observable.<Professor>empty()) .subscribeOn(Schedulers.io()); Observable<Professor> professorFromScraper = mRMPScraper.findBestProfessor(params) .subscribeOn(Schedulers.io()); return Observable.concat(professorFromClient, professorFromScraper) .takeFirst(new Func1<Professor, Boolean>() { @Override public Boolean call(Professor professor) { return true; } }) .filter(new Func1<Professor, Boolean>() { @Override public Boolean call(Professor professor) { return professor != null; } }); } RMP(RMPClient mRMPClient, RMPScraper mRMPScraper); Observable<Professor> getProfessor(final Parameter params); static final String RMP_BASE_URL; }
@Test public void testProfessorWithoutFirstName() throws Exception { String expected = "John"; Parameter params = new Parameter("rutgers", "Mathematics", "Newark", "101", "", "Randall"); Professor result = rmp.getProfessor(params).toBlocking().lastOrDefault(null); assertEquals(expected, result.getFirstName()); }
@Test public void testProfessorWithFirstName() throws Exception { String expected = "John"; Parameter params = new Parameter("rutgers", "Mathematics", "Newark", "101", "J", "Randall"); Professor result = rmp.getProfessor(params).toBlocking().lastOrDefault(null); assertEquals(expected, result.getFirstName()); }
@Test public void testEmptyUniversity() throws Exception { String expected = "John"; Parameter params = new Parameter("", "Mathematics", "Newark", "101", "J", "Randall"); Professor result = rmp.getProfessor(params).toBlocking().lastOrDefault(null); assertEquals(expected, result.getFirstName()); }
@Test public void testNJITprofessor() throws Exception { String expected = "Lay"; Parameter params = new Parameter("rutgers", "Computer Science", "Newark", "101", "L", "Lay"); Professor result = rmp.getProfessor(params).toBlocking().lastOrDefault(null); assertEquals(expected, result.getLastName()); }
@Test public void testStaff() throws Exception { Parameter params = new Parameter("rutgers", "Computer Science", "Newark", "101", "", "STAFF"); Professor result = rmp.getProfessor(params).toBlocking().lastOrDefault(null); assertNull(result); }
@Test public void testNoProfessor() throws Exception { Parameter params = new Parameter("rutgers", "Computer Science", "Newark", "101", "", "NOPROFESSOR"); Professor result = rmp.getProfessor(params).toBlocking().lastOrDefault(null); assertNull(result); }