17
17
import jakarta .data .constraint .GreaterThan ;
18
18
import jakarta .data .constraint .In ;
19
19
import jakarta .data .constraint .LessThan ;
20
+ import jakarta .data .constraint .NotIn ;
20
21
import jakarta .data .repository .By ;
21
22
import jakarta .data .repository .CrudRepository ;
22
23
import jakarta .data .repository .Find ;
23
24
import jakarta .data .repository .Is ;
24
25
import jakarta .inject .Inject ;
25
26
import org .assertj .core .api .SoftAssertions ;
27
+ import org .eclipse .jnosql .communication .Condition ;
26
28
import org .eclipse .jnosql .communication .semistructured .CriteriaCondition ;
27
29
import org .eclipse .jnosql .communication .semistructured .Element ;
28
30
import org .eclipse .jnosql .communication .semistructured .SelectQuery ;
52
54
import static org .eclipse .jnosql .communication .Condition .GREATER_THAN ;
53
55
import static org .eclipse .jnosql .communication .Condition .IN ;
54
56
import static org .eclipse .jnosql .communication .Condition .LESSER_THAN ;
57
+ import static org .eclipse .jnosql .communication .Condition .NOT ;
55
58
import static org .mockito .Mockito .any ;
56
59
import static org .mockito .Mockito .verify ;
57
60
import static org .mockito .Mockito .when ;
@@ -110,6 +113,28 @@ void shouldEquals() {
110
113
});
111
114
}
112
115
116
+
117
+ @ Test
118
+ void shouldDefaultMethod () {
119
+
120
+ when (template .select (any (SelectQuery .class )))
121
+ .thenReturn (Stream .of (new Product ()));
122
+
123
+ repository .defaultMethod ("Mac" );
124
+ ArgumentCaptor <SelectQuery > captor = ArgumentCaptor .forClass (SelectQuery .class );
125
+ verify (template ).select (captor .capture ());
126
+ SelectQuery query = captor .getValue ();
127
+
128
+ SoftAssertions .assertSoftly (softly -> {
129
+ softly .assertThat (query .name ()).isEqualTo ("Product" );
130
+ softly .assertThat (query .condition ()).isPresent ();
131
+ CriteriaCondition condition = query .condition ().orElseThrow ();
132
+ softly .assertThat (condition ).isInstanceOf (CriteriaCondition .class );
133
+ softly .assertThat (condition .condition ()).isEqualTo (EQUALS );
134
+ softly .assertThat (condition .element ()).isEqualTo (Element .of (_Product .NAME , "Mac" ));
135
+ });
136
+ }
137
+
113
138
@ Test
114
139
void shouldAtLeast () {
115
140
@@ -173,8 +198,35 @@ void shouldIn() {
173
198
});
174
199
}
175
200
201
+ @ Test
202
+ void shouldNotIn () {
203
+
204
+ when (template .select (any (SelectQuery .class )))
205
+ .thenReturn (Stream .of (new Product ()));
206
+
207
+ repository .notIn (List .of ("Mac" , "Iphone" ));
208
+ ArgumentCaptor <SelectQuery > captor = ArgumentCaptor .forClass (SelectQuery .class );
209
+ verify (template ).select (captor .capture ());
210
+ SelectQuery query = captor .getValue ();
211
+
212
+ SoftAssertions .assertSoftly (softly -> {
213
+ softly .assertThat (query .name ()).isEqualTo ("Product" );
214
+ softly .assertThat (query .condition ()).isPresent ();
215
+ CriteriaCondition condition = query .condition ().orElseThrow ();
216
+ softly .assertThat (condition ).isInstanceOf (CriteriaCondition .class );
217
+ softly .assertThat (condition .condition ()).isEqualTo (NOT );
218
+ var criteriaCondition = condition .element ().get (CriteriaCondition .class );
219
+ softly .assertThat (criteriaCondition .condition ()).isEqualTo (IN );
220
+ softly .assertThat (criteriaCondition .element ()).isEqualTo (Element .of (_Product .NAME , List .of ("Mac" , "Iphone" )));
221
+ });
222
+ }
223
+
224
+
176
225
177
226
public interface ProductRepository extends CrudRepository <Product , String > {
227
+ @ Find
228
+ List <Product > defaultMethod (@ By (_Product .NAME ) String name );
229
+
178
230
@ Find
179
231
List <Product > equals (@ By (_Product .NAME ) @ Is String name );
180
232
@@ -186,6 +238,9 @@ public interface ProductRepository extends CrudRepository<Product, String> {
186
238
187
239
@ Find
188
240
List <Product > in (@ By (_Product .NAME ) @ Is (In .class ) List <String > names );
241
+
242
+ @ Find
243
+ List <Product > notIn (@ By (_Product .NAME ) @ Is (NotIn .class ) List <String > names );
189
244
}
190
245
191
246
}
0 commit comments