@Test public void testNullEvent() { when(mDatafeed.fetchEvent(EVENT_KEY)).thenReturn(Observable.just(null)); ListItem item = mRenderer.renderFromKey(EVENT_KEY, ModelType.EVENT, null); verifyZeroInteractions(mEventRenderer); assertNotNull(item); assertTrue(item instanceof ModelListElement); assertEquals(((ModelListElement)item).getText(), "2015cthar"); assertEquals(((ModelListElement)item).getKey(), EVENT_KEY); assertEquals(((ModelListElement)item).getType(), ModelType.EVENT); }
@WorkerThread @Override public @Nullable ListElement renderFromKey(String key, ModelType type, Void args) { String text; switch (type) { case EVENT: Event event = mDatafeed.fetchEvent(key).toBlocking().first(); if (event == null) { return new ModelListElement(key, key, type); } return mEventRenderer.renderFromModel(event, true); case TEAM: Team team = mDatafeed.fetchTeam(key).toBlocking().first(); if (team == null) { return new ModelListElement(key, key, type); } return mTeamRenderer.renderFromModel(team, TeamRenderer.RENDER_MYTBA_DETAILS); case MATCH: Match match = mDatafeed.fetchMatch(key).toBlocking().first(); if (match == null) { return new ModelListElement(key, key, type); } return mMatchRenderer.renderFromModel(match, MatchRenderer.RENDER_DEFAULT); case EVENTTEAM: String teamKey = EventTeamHelper.getTeamKey(key); String eventKey = EventTeamHelper.getEventKey(key); Team eTeam = mDatafeed.fetchTeam(teamKey).toBlocking().first(); Event eEvent = mDatafeed.fetchEvent(eventKey).toBlocking().first(); if (eTeam == null || eEvent == null) { text = String.format("%1$s @ %2$s", teamKey, eventKey); return new ModelListElement(text, key, type); } text = String.format("%1$s @ %2$d %3$s", eTeam.getNickname(), eEvent.getYear(), eEvent.getShortName()); return new ModelListElement(text, key, type); case DISTRICT: DistrictListElement element = mDistrictRenderer.renderFromKey( key, ModelType.DISTRICT, new DistrictRenderer.RenderArgs(0, true)); if (element == null) { return new ModelListElement(key, key, type); } return element; default: return null; } }
MyTbaModelRenderer implements ModelRenderer<Void, Void> { @WorkerThread @Override public @Nullable ListElement renderFromKey(String key, ModelType type, Void args) { String text; switch (type) { case EVENT: Event event = mDatafeed.fetchEvent(key).toBlocking().first(); if (event == null) { return new ModelListElement(key, key, type); } return mEventRenderer.renderFromModel(event, true); case TEAM: Team team = mDatafeed.fetchTeam(key).toBlocking().first(); if (team == null) { return new ModelListElement(key, key, type); } return mTeamRenderer.renderFromModel(team, TeamRenderer.RENDER_MYTBA_DETAILS); case MATCH: Match match = mDatafeed.fetchMatch(key).toBlocking().first(); if (match == null) { return new ModelListElement(key, key, type); } return mMatchRenderer.renderFromModel(match, MatchRenderer.RENDER_DEFAULT); case EVENTTEAM: String teamKey = EventTeamHelper.getTeamKey(key); String eventKey = EventTeamHelper.getEventKey(key); Team eTeam = mDatafeed.fetchTeam(teamKey).toBlocking().first(); Event eEvent = mDatafeed.fetchEvent(eventKey).toBlocking().first(); if (eTeam == null || eEvent == null) { text = String.format("%1$s @ %2$s", teamKey, eventKey); return new ModelListElement(text, key, type); } text = String.format("%1$s @ %2$d %3$s", eTeam.getNickname(), eEvent.getYear(), eEvent.getShortName()); return new ModelListElement(text, key, type); case DISTRICT: DistrictListElement element = mDistrictRenderer.renderFromKey( key, ModelType.DISTRICT, new DistrictRenderer.RenderArgs(0, true)); if (element == null) { return new ModelListElement(key, key, type); } return element; default: return null; } } }
MyTbaModelRenderer implements ModelRenderer<Void, Void> { @WorkerThread @Override public @Nullable ListElement renderFromKey(String key, ModelType type, Void args) { String text; switch (type) { case EVENT: Event event = mDatafeed.fetchEvent(key).toBlocking().first(); if (event == null) { return new ModelListElement(key, key, type); } return mEventRenderer.renderFromModel(event, true); case TEAM: Team team = mDatafeed.fetchTeam(key).toBlocking().first(); if (team == null) { return new ModelListElement(key, key, type); } return mTeamRenderer.renderFromModel(team, TeamRenderer.RENDER_MYTBA_DETAILS); case MATCH: Match match = mDatafeed.fetchMatch(key).toBlocking().first(); if (match == null) { return new ModelListElement(key, key, type); } return mMatchRenderer.renderFromModel(match, MatchRenderer.RENDER_DEFAULT); case EVENTTEAM: String teamKey = EventTeamHelper.getTeamKey(key); String eventKey = EventTeamHelper.getEventKey(key); Team eTeam = mDatafeed.fetchTeam(teamKey).toBlocking().first(); Event eEvent = mDatafeed.fetchEvent(eventKey).toBlocking().first(); if (eTeam == null || eEvent == null) { text = String.format("%1$s @ %2$s", teamKey, eventKey); return new ModelListElement(text, key, type); } text = String.format("%1$s @ %2$d %3$s", eTeam.getNickname(), eEvent.getYear(), eEvent.getShortName()); return new ModelListElement(text, key, type); case DISTRICT: DistrictListElement element = mDistrictRenderer.renderFromKey( key, ModelType.DISTRICT, new DistrictRenderer.RenderArgs(0, true)); if (element == null) { return new ModelListElement(key, key, type); } return element; default: return null; } } @Inject  MyTbaModelRenderer(
      APICache datafeed,
      EventRenderer eventRenderer,
      TeamRenderer teamRenderer,
      MatchRenderer matchRenderer,
      DistrictRenderer districtRenderer); }
MyTbaModelRenderer implements ModelRenderer<Void, Void> { @WorkerThread @Override public @Nullable ListElement renderFromKey(String key, ModelType type, Void args) { String text; switch (type) { case EVENT: Event event = mDatafeed.fetchEvent(key).toBlocking().first(); if (event == null) { return new ModelListElement(key, key, type); } return mEventRenderer.renderFromModel(event, true); case TEAM: Team team = mDatafeed.fetchTeam(key).toBlocking().first(); if (team == null) { return new ModelListElement(key, key, type); } return mTeamRenderer.renderFromModel(team, TeamRenderer.RENDER_MYTBA_DETAILS); case MATCH: Match match = mDatafeed.fetchMatch(key).toBlocking().first(); if (match == null) { return new ModelListElement(key, key, type); } return mMatchRenderer.renderFromModel(match, MatchRenderer.RENDER_DEFAULT); case EVENTTEAM: String teamKey = EventTeamHelper.getTeamKey(key); String eventKey = EventTeamHelper.getEventKey(key); Team eTeam = mDatafeed.fetchTeam(teamKey).toBlocking().first(); Event eEvent = mDatafeed.fetchEvent(eventKey).toBlocking().first(); if (eTeam == null || eEvent == null) { text = String.format("%1$s @ %2$s", teamKey, eventKey); return new ModelListElement(text, key, type); } text = String.format("%1$s @ %2$d %3$s", eTeam.getNickname(), eEvent.getYear(), eEvent.getShortName()); return new ModelListElement(text, key, type); case DISTRICT: DistrictListElement element = mDistrictRenderer.renderFromKey( key, ModelType.DISTRICT, new DistrictRenderer.RenderArgs(0, true)); if (element == null) { return new ModelListElement(key, key, type); } return element; default: return null; } } @Inject  MyTbaModelRenderer(
      APICache datafeed,
      EventRenderer eventRenderer,
      TeamRenderer teamRenderer,
      MatchRenderer matchRenderer,
      DistrictRenderer districtRenderer); @WorkerThread @Override @Nullable ListElement renderFromKey(String key, ModelType type, Void args); @Override @Nullable ListElement renderFromModel(Void aVoid, Void a2void); }
MyTbaModelRenderer implements ModelRenderer<Void, Void> { @WorkerThread @Override public @Nullable ListElement renderFromKey(String key, ModelType type, Void args) { String text; switch (type) { case EVENT: Event event = mDatafeed.fetchEvent(key).toBlocking().first(); if (event == null) { return new ModelListElement(key, key, type); } return mEventRenderer.renderFromModel(event, true); case TEAM: Team team = mDatafeed.fetchTeam(key).toBlocking().first(); if (team == null) { return new ModelListElement(key, key, type); } return mTeamRenderer.renderFromModel(team, TeamRenderer.RENDER_MYTBA_DETAILS); case MATCH: Match match = mDatafeed.fetchMatch(key).toBlocking().first(); if (match == null) { return new ModelListElement(key, key, type); } return mMatchRenderer.renderFromModel(match, MatchRenderer.RENDER_DEFAULT); case EVENTTEAM: String teamKey = EventTeamHelper.getTeamKey(key); String eventKey = EventTeamHelper.getEventKey(key); Team eTeam = mDatafeed.fetchTeam(teamKey).toBlocking().first(); Event eEvent = mDatafeed.fetchEvent(eventKey).toBlocking().first(); if (eTeam == null || eEvent == null) { text = String.format("%1$s @ %2$s", teamKey, eventKey); return new ModelListElement(text, key, type); } text = String.format("%1$s @ %2$d %3$s", eTeam.getNickname(), eEvent.getYear(), eEvent.getShortName()); return new ModelListElement(text, key, type); case DISTRICT: DistrictListElement element = mDistrictRenderer.renderFromKey( key, ModelType.DISTRICT, new DistrictRenderer.RenderArgs(0, true)); if (element == null) { return new ModelListElement(key, key, type); } return element; default: return null; } } @Inject  MyTbaModelRenderer(
      APICache datafeed,
      EventRenderer eventRenderer,
      TeamRenderer teamRenderer,
      MatchRenderer matchRenderer,
      DistrictRenderer districtRenderer); @WorkerThread @Override @Nullable ListElement renderFromKey(String key, ModelType type, Void args); @Override @Nullable ListElement renderFromModel(Void aVoid, Void a2void);  }