@@ -104,14 +104,16 @@ public void useAfterQueryClose_fails() {
104
104
assertThrowsQueryIsClosed (query ::count );
105
105
assertThrowsQueryIsClosed (query ::describe );
106
106
assertThrowsQueryIsClosed (query ::describeParameters );
107
+ assertThrowsQueryIsClosed (query ::findFirst );
108
+ assertThrowsQueryIsClosed (query ::findUnique );
107
109
assertThrowsQueryIsClosed (query ::find );
108
110
assertThrowsQueryIsClosed (() -> query .find (0 , 1 ));
109
- assertThrowsQueryIsClosed (query ::findFirst );
111
+ assertThrowsQueryIsClosed (query ::findFirstId );
112
+ assertThrowsQueryIsClosed (query ::findUniqueId );
110
113
assertThrowsQueryIsClosed (query ::findIds );
111
114
assertThrowsQueryIsClosed (() -> query .findIds (0 , 1 ));
112
115
assertThrowsQueryIsClosed (query ::findLazy );
113
116
assertThrowsQueryIsClosed (query ::findLazyCached );
114
- assertThrowsQueryIsClosed (query ::findUnique );
115
117
assertThrowsQueryIsClosed (query ::remove );
116
118
117
119
// For setParameter(s) the native method is not actually called, so fine to use incorrect alias and property.
@@ -162,14 +164,16 @@ public void useAfterStoreClose_failsIfUsingStore() {
162
164
163
165
// All methods accessing the store throw.
164
166
assertThrowsStoreIsClosed (query ::count );
167
+ assertThrowsStoreIsClosed (query ::findFirst );
168
+ assertThrowsStoreIsClosed (query ::findUnique );
165
169
assertThrowsStoreIsClosed (query ::find );
166
170
assertThrowsStoreIsClosed (() -> query .find (0 , 1 ));
167
- assertThrowsStoreIsClosed (query ::findFirst );
171
+ assertThrowsStoreIsClosed (query ::findFirstId );
172
+ assertThrowsStoreIsClosed (query ::findUniqueId );
168
173
assertThrowsStoreIsClosed (query ::findIds );
169
174
assertThrowsStoreIsClosed (() -> query .findIds (0 , 1 ));
170
175
assertThrowsStoreIsClosed (query ::findLazy );
171
176
assertThrowsStoreIsClosed (query ::findLazyCached );
172
- assertThrowsStoreIsClosed (query ::findUnique );
173
177
assertThrowsStoreIsClosed (query ::remove );
174
178
assertThrowsStoreIsClosed (() -> query .subscribe ().observer (data -> {
175
179
}));
@@ -915,6 +919,35 @@ public void testRemove() {
915
919
assertEquals (4 , box .count ());
916
920
}
917
921
922
+ @ Test
923
+ public void findFirstId () {
924
+ putTestEntitiesScalars ();
925
+ try (Query <TestEntity > query = box .query (simpleInt .greater (2006 )).build ()) {
926
+ assertEquals (8 , query .findFirstId ());
927
+ }
928
+ // No result.
929
+ try (Query <TestEntity > query = box .query (simpleInt .equal (-1 )).build ()) {
930
+ assertEquals (0 , query .findFirstId ());
931
+ }
932
+ }
933
+
934
+ @ Test
935
+ public void findUniqueId () {
936
+ putTestEntitiesScalars ();
937
+ try (Query <TestEntity > query = box .query (simpleInt .equal (2006 )).build ()) {
938
+ assertEquals (7 , query .findUniqueId ());
939
+ }
940
+ // No result.
941
+ try (Query <TestEntity > query = box .query (simpleInt .equal (-1 )).build ()) {
942
+ assertEquals (0 , query .findUniqueId ());
943
+ }
944
+ // More than one result.
945
+ try (Query <TestEntity > query = box .query (simpleInt .greater (2006 )).build ()) {
946
+ NonUniqueResultException e = assertThrows (NonUniqueResultException .class , query ::findUniqueId );
947
+ assertEquals ("Query does not have a unique result (more than one result): 3" , e .getMessage ());
948
+ }
949
+ }
950
+
918
951
@ Test
919
952
public void testFindIds () {
920
953
putTestEntitiesScalars ();
0 commit comments