public void useModules(String... names) {
        checkNotNull(names, "names cannot be null");
        Set<String> deduplicateNames = new HashSet<>();
        for (String name : names) {
            if (!loadedModules.containsKey(name)) {
                throw new ValidationException(
                        String.format("No module with name '%s' exists", name));
            }
            if (!deduplicateNames.add(name)) {
                throw new ValidationException(
                        String.format("Module '%s' appears more than once", name));
            }
        }
        usedModules.clear();
        usedModules.addAll(Arrays.asList(names));
    }
@Test
    void testUseModules() {
        ModuleMock x = new ModuleMock("x");
        ModuleMock y = new ModuleMock("y");
        ModuleMock z = new ModuleMock("z");
        manager.loadModule(x.getType(), x);
        manager.loadModule(y.getType(), y);
        manager.loadModule(z.getType(), z);

        assertThat(manager.getUsedModules())
                .containsSequence(CoreModuleFactory.IDENTIFIER, "x", "y", "z");

        // test order for used modules
        manager.useModules("z", CoreModuleFactory.IDENTIFIER);
        assertThat(manager.getUsedModules()).containsSequence("z", CoreModuleFactory.IDENTIFIER);

        // test unmentioned modules are still loaded
        Map<String, Module> expectedLoadedModules = new HashMap<>();
        expectedLoadedModules.put(CoreModuleFactory.IDENTIFIER, CoreModule.INSTANCE);
        expectedLoadedModules.put("x", x);
        expectedLoadedModules.put("y", y);
        expectedLoadedModules.put("z", z);
        assertThat(manager.getLoadedModules()).isEqualTo(expectedLoadedModules);
    }