DeliveryErrors { public static Builder newBuilder() { return new Builder(); } private  DeliveryErrors(Builder builder); static Builder newBuilder();  }
@Test @DisplayName(NOT_ACCEPT_NULLS) void nulls() { DeliveryErrors.Builder builder = DeliveryErrors.newBuilder(); new NullPointerTester() .testInstanceMethods(builder, PACKAGE); }
@Test @DisplayName("accept model errors") void acceptErrors() { DeliveryErrors.Builder builder = DeliveryErrors.newBuilder(); ModelError mockError = new ModelError("boo!"); builder.addError(mockError); DeliveryErrors errors = builder.build(); ModelError error = assertThrows(ModelError.class, errors::throwIfAny); assertThat(error) .isEqualTo(mockError); }
@Test @DisplayName("accept runtime exceptions") void acceptExceptions() { DeliveryErrors.Builder builder = DeliveryErrors.newBuilder(); RuntimeException mockException = new IllegalArgumentException("42"); builder.addException(mockException); DeliveryErrors errors = builder.build(); IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, errors::throwIfAny); assertThat(exception) .isEqualTo(mockException); }
@Test @DisplayName("throw exceptions with suppressed throwables") void throwWithSuppressed() { DeliveryErrors.Builder builder = DeliveryErrors.newBuilder(); ModelError mockError = new ModelError("model is wrong"); ModelError anotherMockError = new ModelError("completely"); RuntimeException mockException = new IllegalArgumentException("3.14"); builder.addError(mockError); builder.addError(anotherMockError); builder.addException(mockException); DeliveryErrors errors = builder.build(); ModelError error = assertThrows(ModelError.class, errors::throwIfAny); assertThat(error) .isEqualTo(mockError); assertThat(error.getSuppressed()) .asList() .containsExactly(anotherMockError, mockException); }