1+ /*
2+ * Table Wrapper API
3+ * Copyright (C) 2022 Spacious Team <spacious-team@ya.ru>
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+
19+ package org .spacious_team .table_wrapper .api ;
20+
21+ import nl .jqno .equalsverifier .EqualsVerifier ;
22+ import org .junit .jupiter .api .Test ;
23+ import org .junit .jupiter .params .ParameterizedTest ;
24+ import org .junit .jupiter .params .provider .MethodSource ;
25+ import org .spacious_team .table_wrapper .api .StringPrefixPredicate .IgnoreCaseStringPrefixPredicate ;
26+ import org .spacious_team .table_wrapper .api .StringPrefixPredicate .PredicateOnObjectWrapper ;
27+
28+ import static org .junit .jupiter .api .Assertions .*;
29+ import static org .spacious_team .table_wrapper .api .StringPrefixPredicate .ignoreCaseStringPrefixPredicate ;
30+ import static org .spacious_team .table_wrapper .api .StringPrefixPredicate .ignoreCaseStringPrefixPredicateOnObject ;
31+
32+ class StringPrefixPredicateTest {
33+
34+ static Object [][] prefixAndMatchingString () {
35+ return new Object [][]{
36+ {"First" , "First second" },
37+ {"First" , "first second" },
38+ {"first" , "First second" },
39+ {"first" , "first second" },
40+ {"FIRST" , "first second" },
41+ {" FIRST" , "first second" },
42+ {" FIRST" , " first second" },
43+ {"\t first\n " , "\n first \t second" },
44+ {"first" , "\t \n first\n \t second" },
45+ {"\n first\n " , "\t \n \r first\r \n \t second" },
46+ };
47+ }
48+
49+ static Object [][] prefixAndNotMatchingSting () {
50+ return new Object [][]{
51+ {"First" , "One two" },
52+ {"first" , "fir st two" },
53+ {"first" , "zero first" },
54+ {"first" , "zero first second" },
55+ };
56+ }
57+
58+ static Object [][] prefixAndObject () {
59+ return new Object [][]{
60+ {"First" , 1 },
61+ {"First" , 1.1 },
62+ {"First" , new Object ()},
63+ };
64+ }
65+
66+ // ignoreCaseStringPrefixPredicateOnObject(CharSequence) tests
67+
68+ @ ParameterizedTest
69+ @ MethodSource ("prefixAndMatchingString" )
70+ void ignoreCaseStringPrefixPredicateOnObject_matched (String prefix , String testingString ) {
71+ assertTrue (ignoreCaseStringPrefixPredicateOnObject (prefix ).test (testingString ));
72+ }
73+
74+ @ ParameterizedTest
75+ @ MethodSource ("prefixAndNotMatchingSting" )
76+ void ignoreCaseStringPrefixPredicateOnObject_notMatchedString (String prefix , String testingString ) {
77+ assertFalse (ignoreCaseStringPrefixPredicateOnObject (prefix ).test (testingString ));
78+ }
79+
80+ @ ParameterizedTest
81+ @ MethodSource ("prefixAndObject" )
82+ void ignoreCaseStringPrefixPredicateOnObject_object (String prefix , Object testingObject ) {
83+ assertFalse (ignoreCaseStringPrefixPredicateOnObject (prefix ).test (testingObject ));
84+ }
85+
86+ @ Test
87+ void ignoreCaseStringPrefixPredicateOnObject_null () {
88+ assertFalse (ignoreCaseStringPrefixPredicateOnObject ("any" ).test (null ));
89+ }
90+
91+
92+ // ignoreCaseStringPrefixPredicate(CharSequence) tests
93+
94+ @ ParameterizedTest
95+ @ MethodSource ("prefixAndMatchingString" )
96+ void ignoreCaseStringPrefixPredicate_matched (String prefix , String testingString ) {
97+ assertTrue (ignoreCaseStringPrefixPredicate (prefix ).test (testingString ));
98+ }
99+
100+ @ ParameterizedTest
101+ @ MethodSource ("prefixAndNotMatchingSting" )
102+ void ignoreCaseStringPrefixPredicate_notMatchedString (String prefix , String testingString ) {
103+ assertFalse (ignoreCaseStringPrefixPredicate (prefix ).test (testingString ));
104+ }
105+
106+ @ Test
107+ @ SuppressWarnings ("DataFlowIssue" )
108+ void ignoreCaseStringPrefixPredicate_null () {
109+ assertThrows (NullPointerException .class , () -> ignoreCaseStringPrefixPredicate ("any" ).test (null ));
110+ }
111+
112+ @ Test
113+ void testEqualsAndHashCode () {
114+ EqualsVerifier
115+ .forClass (IgnoreCaseStringPrefixPredicate .class )
116+ .verify ();
117+ EqualsVerifier
118+ .forClass (PredicateOnObjectWrapper .class )
119+ .verify ();
120+ }
121+
122+ @ Test
123+ void testToString () {
124+ assertEquals (
125+ "StringPrefixPredicate.PredicateOnObjectWrapper(predicate=StringPrefixPredicate.IgnoreCaseStringPrefixPredicate(prefix=First))" ,
126+ ignoreCaseStringPrefixPredicateOnObject ("First" ).toString ());
127+ assertEquals (
128+ "StringPrefixPredicate.IgnoreCaseStringPrefixPredicate(prefix=First)" ,
129+ ignoreCaseStringPrefixPredicate ("First" ).toString ());
130+ }
131+ }
0 commit comments