@Test void generateShouldThrowFormattedMessageWhenUnknownTaskParam() { when(request.queryParams("action")).thenReturn("unknown"); assertThatThrownBy(() -> singleTaskFromRequestRegistry.fromRequest(request)) .isInstanceOf(IllegalArgumentException.class) .hasMessage("Invalid value supplied for query parameter 'action': unknown. Supported values are [task1]"); }
@Override public Task fromRequest(Request request) throws Exception { TaskRegistrationKey registrationKey = parseRegistrationKey(request); return Optional.ofNullable(taskGenerators.get(registrationKey)) .map(Throwing.<TaskFromRequest, Task>function(taskGenerator -> taskGenerator.fromRequest(request)).sneakyThrow()) .orElseThrow(() -> new IllegalArgumentException("Invalid value supplied for query parameter '" + taskParameterName + "': " + registrationKey.asString() + ". " + supportedValueMessage())); }
TaskFromRequestRegistry implements TaskFromRequest { @Override public Task fromRequest(Request request) throws Exception { TaskRegistrationKey registrationKey = parseRegistrationKey(request); return Optional.ofNullable(taskGenerators.get(registrationKey)) .map(Throwing.<TaskFromRequest, Task>function(taskGenerator -> taskGenerator.fromRequest(request)).sneakyThrow()) .orElseThrow(() -> new IllegalArgumentException("Invalid value supplied for query parameter '" + taskParameterName + "': " + registrationKey.asString() + ". " + supportedValueMessage())); } }
TaskFromRequestRegistry implements TaskFromRequest { @Override public Task fromRequest(Request request) throws Exception { TaskRegistrationKey registrationKey = parseRegistrationKey(request); return Optional.ofNullable(taskGenerators.get(registrationKey)) .map(Throwing.<TaskFromRequest, Task>function(taskGenerator -> taskGenerator.fromRequest(request)).sneakyThrow()) .orElseThrow(() -> new IllegalArgumentException("Invalid value supplied for query parameter '" + taskParameterName + "': " + registrationKey.asString() + ". " + supportedValueMessage())); } private  TaskFromRequestRegistry(String taskParameterName, Map<TaskRegistrationKey, TaskFromRequest> taskGenerators); }
TaskFromRequestRegistry implements TaskFromRequest { @Override public Task fromRequest(Request request) throws Exception { TaskRegistrationKey registrationKey = parseRegistrationKey(request); return Optional.ofNullable(taskGenerators.get(registrationKey)) .map(Throwing.<TaskFromRequest, Task>function(taskGenerator -> taskGenerator.fromRequest(request)).sneakyThrow()) .orElseThrow(() -> new IllegalArgumentException("Invalid value supplied for query parameter '" + taskParameterName + "': " + registrationKey.asString() + ". " + supportedValueMessage())); } private  TaskFromRequestRegistry(String taskParameterName, Map<TaskRegistrationKey, TaskFromRequest> taskGenerators); static Builder builder(); static TaskFromRequestRegistry of(TaskRegistrationKey key, TaskFromRequest generator); @Override Task fromRequest(Request request); }
TaskFromRequestRegistry implements TaskFromRequest { @Override public Task fromRequest(Request request) throws Exception { TaskRegistrationKey registrationKey = parseRegistrationKey(request); return Optional.ofNullable(taskGenerators.get(registrationKey)) .map(Throwing.<TaskFromRequest, Task>function(taskGenerator -> taskGenerator.fromRequest(request)).sneakyThrow()) .orElseThrow(() -> new IllegalArgumentException("Invalid value supplied for query parameter '" + taskParameterName + "': " + registrationKey.asString() + ". " + supportedValueMessage())); } private  TaskFromRequestRegistry(String taskParameterName, Map<TaskRegistrationKey, TaskFromRequest> taskGenerators); static Builder builder(); static TaskFromRequestRegistry of(TaskRegistrationKey key, TaskFromRequest generator); @Override Task fromRequest(Request request);  }