### Question:
FactCreateHandler { public void assertValidFactValue(FactTypeEntity type, String value) throws InvalidArgumentException { Validator validator = validatorFactory.get(type.getValidator(), type.getValidatorParameter()); if (!validator.validate(value)) { throw new InvalidArgumentException() .addValidationError("Fact did not pass validation against FactType.", "fact.not.valid", "value", value); } } @Inject  FactCreateHandler(TiSecurityContext securityContext,
                           SubjectResolver subjectResolver,
                           OrganizationResolver organizationResolver,
                           OriginManager originManager,
                           ValidatorFactory validatorFactory,
                           ObjectFactDao objectFactDao,
                           FactResponseConverter factResponseConverter,
                           TriggerContext triggerContext); Organization resolveOrganization(String idOrName, OriginEntity fallback); OriginEntity resolveOrigin(String idOrName); List<Subject> resolveSubjects(List<String> acl); FactRecord.AccessMode resolveAccessMode(FactRecord referencedFact, AccessMode requestedAccessMode); Fact saveFact(FactRecord fact, String comment, List<UUID> subjectIds); void assertValidFactValue(FactTypeEntity type, String value);  }### Answer:
@Test public void testAssertValidFactValue() { FactTypeEntity factType = new FactTypeEntity().setValidator("SomeValidator").setValidatorParameter("SomeParam"); Validator validator = mock(Validator.class); when(validator.validate(eq("test"))).thenReturn(false); when(validatorFactory.get(factType.getValidator(), factType.getValidatorParameter())).thenReturn(validator); InvalidArgumentException ex = assertThrows(InvalidArgumentException.class, () -> handler.assertValidFactValue(factType, "test")); assertEquals(SetUtils.set("fact.not.valid"), SetUtils.set(ex.getValidationErrors(), InvalidArgumentException.ValidationError::getMessageTemplate)); }