### Question:
Registrations { public JsonArray allAsJson() { Collector<JsonObject, ?, JsonArrayBuilder> jsonCollector = Collector.of(Json::createArrayBuilder, JsonArrayBuilder::add, (left, right) -> { left.add(right); return left; }); return all().stream().map(this::convert). collect(jsonCollector).build(); }  JsonObject register(Registration request); Registration find(long registrationId); JsonObject findAsJson(int registrationId); List<Registration> all(); JsonArray allAsJson(); static final String CONFIRMATION_ID; }### Answer:
@Test public void convertEmptyListToJson() { mockQuery(Registration.findAll, Collections.EMPTY_LIST); final JsonArray result = this.cut.allAsJson(); assertNotNull(result); assertTrue(result.isEmpty()); }
@Test public void convertFilledListToJson() { List<Registration> registrations = new ArrayList<>(); Registration expected = mock(Registration.class); when(expected.getId()).thenReturn(42l); registrations.add(expected); mockQuery(Registration.findAll, registrations); final JsonArray result = this.cut.allAsJson(); assertNotNull(result); assertThat(result.size(), is(1)); JsonObject actual = result.getJsonObject(0); JsonNumber actualId = actual.getJsonNumber(Registrations.CONFIRMATION_ID); assertThat(expected.getId(), is(actualId.longValue())); }