@Test void testHasViolations() throws Exception { Vtor vtor = new Vtor(); assertFalse(vtor.hasViolations(), "method must return false when violations list is empty"); vtor.addViolation(mock(Violation.class)); assertTrue(vtor.hasViolations(), "method must return true when add some violation"); }
@Test void testTime() { Vtor vtor = new Vtor(); vtor.validate(new Tad()); assertTrue(vtor.hasViolations()); List<Violation> v = vtor.getViolations(); assertEquals(3, v.size()); assertEquals(TimeAfterConstraint.class, v.get(0).getConstraint().getClass()); } }
@Test void testManualConfig() { ValidationContext vctx = new ValidationContext(); vctx.add(new Check("string", new MinLengthConstraint(2))); Vtor vtor = new Vtor(); vtor.validate(vctx, new Foo()); assertTrue(vtor.hasViolations()); List<Violation> vlist = vtor.getViolations(); assertFalse(vlist.isEmpty()); assertEquals(1, vlist.size()); Violation v = vlist.get(0); assertEquals("string", v.getName()); assertEquals("1", v.getInvalidValue()); assertEquals("string", v.getCheck().getName()); assertNull(v.getCheck().getMessage()); assertEquals(MinLengthConstraint.class, v.getConstraint().getClass()); // new context that contains previous ValidationContext vctx2 = new ValidationContext(); vctx2.add(new Check("foo", new AssertValidConstraint(vctx))); vtor = new Vtor(); vtor.validate(vctx2, new Boo()); vlist = vtor.getViolations(); assertFalse(vlist.isEmpty()); assertEquals(1, vlist.size()); v = vlist.get(0); assertEquals("foo.string", v.getName()); assertEquals("1", v.getInvalidValue()); assertEquals("string", v.getCheck().getName()); assertEquals(MinLengthConstraint.class, v.getConstraint().getClass()); }