ModelVerifier implements Logging { void verify(CommandHandlers handlers) { ClassSet classSet = new ClassSet(projectClassLoader, handlers.getCommandHandlingTypeList()); reportNotFoundIfAny(classSet); DuplicateHandlerCheck.newInstance() .check(classSet.elements()); } ModelVerifier(Project project);   }
@Test @DisplayName("verify model from classpath") void verifyModel() { ModelVerifier verifier = new ModelVerifier(project); String commandHandlerTypeName = UploadCommandHandler.class.getName(); String aggregateTypeName = EditAggregate.class.getName(); String procManTypeName = RenameProcMan.class.getName(); CommandHandlers spineModel = CommandHandlers .newBuilder() .addCommandHandlingType(commandHandlerTypeName) .addCommandHandlingType(aggregateTypeName) .addCommandHandlingType(procManTypeName) .build(); verifier.verify(spineModel); }
@Test @DisplayName("fail on duplicate command handlers") void failOnDuplicateHandlers() { ModelVerifier verifier = new ModelVerifier(project); String firstType = UploadCommandHandler.class.getName(); String secondType = DuplicateCommandHandler.class.getName(); CommandHandlers spineModel = CommandHandlers .newBuilder() .addCommandHandlingType(firstType) .addCommandHandlingType(secondType) .build(); assertThrows(DuplicateCommandHandlerError.class, () -> verifier.verify(spineModel)); }
@Test @DisplayName("fail on command receiving methods marked as external") void failOnExternalCommandReceivers() { ModelVerifier verifier = new ModelVerifier(project); String invalidProcman = InvalidCommander.class.getName(); CommandHandlers spineModel = CommandHandlers .newBuilder() .addCommandHandlingType(invalidProcman) .build(); assertThrows(ExternalCommandReceiverMethodError.class, () -> verifier.verify(spineModel)); }
@Test @MuteLogging @DisplayName("ignore invalid class names") void ignoreInvalidClassNames() { String invalidClassname = "non.existing.class.Name"; CommandHandlers spineModel = CommandHandlers .newBuilder() .addCommandHandlingType(invalidClassname) .build(); new ModelVerifier(project).verify(spineModel); }
@Test @DisplayName("not accept non-CommandHandler types") void rejectNonHandlerTypes() { String invalidClassname = ModelVerifierTest.class.getName(); CommandHandlers spineModel = CommandHandlers .newBuilder() .addCommandHandlingType(invalidClassname) .build(); assertThrows(IllegalArgumentException.class, () -> new ModelVerifier(project).verify(spineModel)); }