Skip to content
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,41 @@ public void not() {
}
}

@Test
public void emptyGroup() {
populateTestRealm(); // create TEST_DATA_SIZE objects
RealmResults<AllTypes> fives = realm.where(AllTypes.class)
.equalTo(AllTypes.FIELD_LONG, 5)
.beginGroup()
.endGroup()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this throw as well?

Copy link
Contributor Author

@rorbech rorbech Dec 4, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No 🤷

.findAll();
// Only on object with value 5
assertEquals(1, fives.size());
}

@Test (expected = UnsupportedOperationException.class)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally, we only reserve this exception to things not implemented. A more appropriate exception would be IllegalStateException

Copy link
Contributor Author

@rorbech rorbech Dec 4, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From documentation of the various RealmQuery methods it seems like invalid queries (syntax errors) are indicated by throwing UnsupportedOperationException.

public void or_emptyGroupThrows() {
populateTestRealm(); // create TEST_DATA_SIZE objects
RealmResults<AllTypes> fives = realm.where(AllTypes.class)
.equalTo(AllTypes.FIELD_LONG, 5)
.or()
.beginGroup()
.endGroup()
.findAll();
}

@Test (expected = UnsupportedOperationException.class)
public void not_emptyGroup_throws() {
populateTestRealm(); // create TEST_DATA_SIZE objects
realm.where(AllTypes.class)
.equalTo(AllTypes.FIELD_LONG, 5)
.or()
.not()
.beginGroup()
.endGroup()
.findAll();
}

@Test (expected = UnsupportedOperationException.class)
public void not_aloneThrows() {
// a not() alone must fail
Expand Down