App { @Nullable public static String getPhotoUrl(@Nullable Session session) { String photoUrl = null; if (session != null) { List<Speaker> speakers = session.getSpeakers(); if (speakers != null && !speakers.isEmpty()) { photoUrl = speakers.get(0).getPhoto(); } } return photoUrl; } private  App(); static boolean isCompatible(int apiLevel); static String getVersion(); static void setExactAlarm(AlarmManager alarmManager, long triggerAtMillis, PendingIntent operation); @Nullable static String getPhotoUrl(@Nullable Session session);  }
@Test public void should_return_null_photourl_when_giving_invalid_data() { Session session1 = null; Session session2 = new Session(3, "room1", null, "title", "description", null, null); Session session3 = new Session(3, "room1", new ArrayList<>(), "title", "description", null, null); String result1 = App.getPhotoUrl(session1); String result2 = App.getPhotoUrl(session2); String result3 = App.getPhotoUrl(session3); assertThat(result1).isNull(); assertThat(result2).isNull(); assertThat(result3).isNull(); }
@Test public void should_return_photo_url_of_first_speaker() { Speaker speaker1 = new Speaker(1, null, null, null, null, null, null, "photo1"); Speaker speaker2 = new Speaker(2, null, null, null, null, null, null, "photo2"); Session session = new Session(1, null, Arrays.asList(speaker1, speaker2), null, null, null, null); String photoUrl = App.getPhotoUrl(session); assertThat(photoUrl).isEqualTo("photo1"); }