aboutsummaryrefslogtreecommitdiff
path: root/src/test/java/org/pacien/lemonad/validation/ValidatorTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/java/org/pacien/lemonad/validation/ValidatorTest.java')
-rw-r--r--src/test/java/org/pacien/lemonad/validation/ValidatorTest.java61
1 files changed, 0 insertions, 61 deletions
diff --git a/src/test/java/org/pacien/lemonad/validation/ValidatorTest.java b/src/test/java/org/pacien/lemonad/validation/ValidatorTest.java
deleted file mode 100644
index 55927b5..0000000
--- a/src/test/java/org/pacien/lemonad/validation/ValidatorTest.java
+++ /dev/null
@@ -1,61 +0,0 @@
1/*
2 * lemonad - Some functional sweetness for Java
3 * Copyright (C) 2019 Pacien TRAN-GIRARD
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Affero General Public License as
7 * published by the Free Software Foundation, either version 3 of the
8 * License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Affero General Public License for more details.
14 *
15 * You should have received a copy of the GNU Affero General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 */
18
19package org.pacien.lemonad.validation;
20
21import org.junit.jupiter.api.Test;
22
23import java.util.List;
24
25import static java.util.function.Predicate.not;
26import static org.junit.jupiter.api.Assertions.assertEquals;
27
28/**
29 * @author pacien
30 */
31class ValidatorTest {
32 @Test void testValidatorEnsuringPredicate() {
33 var emptyError = 0;
34 var validator = Validator.ensuringPredicate(not(String::isEmpty), emptyError);
35 assertEquals(List.of(emptyError), validator.validate("").getErrors());
36 assertEquals(List.of(), validator.validate("test").getErrors());
37 }
38
39 @Test void testValidatorValidatingAll() {
40 var emptyError = 0;
41 var tooLongError = 1;
42 var containsBadLetterError = 2;
43
44 var validator = Validator.validatingAll(
45 Validator.ensuringPredicate(not(String::isEmpty), emptyError),
46 Validator.ensuringPredicate((String str) -> str.length() < 10, tooLongError),
47 Validator.ensuringPredicate((String str) -> !str.contains("e"), containsBadLetterError));
48
49 assertEquals(List.of(emptyError), validator.validate("").getErrors());
50 assertEquals(List.of(tooLongError, containsBadLetterError), validator.validate("test test test").getErrors());
51 assertEquals(List.of(), validator.validate("potato").getErrors());
52 }
53
54 @Test void testValidatingField() {
55 var emptyError = 0;
56 var fieldValidator = Validator.ensuringPredicate((Integer len) -> len > 0, emptyError);
57 var validator = Validator.validatingField(String::length, fieldValidator);
58 assertEquals(List.of(emptyError), validator.validate("").getErrors());
59 assertEquals(List.of(), validator.validate("test").getErrors());
60 }
61}