### Question:
Icinga2Result { public Optional<String> getStatusOfFirstElement() { if (results != null) { return results.stream().filter(Objects::nonNull).findFirst().map(e -> e.get("status")); } return Optional.empty(); }  List<Map<String, String>> getResults(); void setResults(List<Map<String, String>> results); Optional<String> getStatusOfFirstElement(); Optional<Integer> getCodeOfFirstElement(); boolean isSuccess(); String getFirstElementAsString();  }### Answer:
@Test public void testGetStatusOfFirstElement() throws Exception { Icinga2Result result = new Icinga2Result(); Map<String, String> map = new HashMap<>(); String msg = "my status"; map.put("status", msg); result.setResults(Collections.singletonList(map)); assertEquals(result.getStatusOfFirstElement().get(), msg); result.setResults(null); assertFalse(result.getStatusOfFirstElement().isPresent()); map.put("status", null); result.setResults(Collections.singletonList(map)); assertFalse(result.getStatusOfFirstElement().isPresent()); result.setResults(Collections.singletonList(new HashMap<>())); assertFalse(result.getStatusOfFirstElement().isPresent()); assertEquals(result.getFirstElementAsString(), "[NULL] - EMPTY MESSAGE"); }