### Question:
RequiredOptionsUtil { public static void checkIfRequiredOptionsAreInitialized(final Object... objects) { final Set<String> missingOptions = new LinkedHashSet<>(); for (Object object : objects) { for (Field field : getAllFields(object.getClass())) { field.setAccessible(true); if (field.isAnnotationPresent(RequiredOption.class) && field.isAnnotationPresent(CommandLine.Option.class)) { final Object value; try { value = field.get(object); } catch (final IllegalAccessException e) { throw new InitializationException("Error parsing options: " + e.getMessage(), e); } if (value == null) { final CommandLine.Option optionAnnotation = field.getDeclaredAnnotation(CommandLine.Option.class); final String[] names = optionAnnotation.names(); missingOptions.add(longestName(names)); } } } } if (!missingOptions.isEmpty()) { throw new InvalidCommandLineOptionsException( "Missing required option(s): " + String.join(",", missingOptions)); } }  static void checkIfRequiredOptionsAreInitialized(final Object... objects);  }### Answer:
@Test void exceptionIsThrownIfRequiredOptionsAreNotInitialized() { final DemoCommand demoCommand = new DemoCommand(); assertThatExceptionOfType(InvalidCommandLineOptionsException.class) .isThrownBy( () -> { RequiredOptionsUtil.checkIfRequiredOptionsAreInitialized(demoCommand); }) .withMessageContaining("Missing required option(s): --x,--y"); }
@Test void noExceptionIsThrownIfRequiredOptionsAreInitialized() { final DemoCommand demoCommand = new DemoCommand(); demoCommand.x = 10; demoCommand.y = 20; RequiredOptionsUtil.checkIfRequiredOptionsAreInitialized(demoCommand); }