Search in sources :

Example 16 with RealmFieldType

use of io.realm.RealmFieldType in project realm-java by realm.

the class SortDescriptorTests method getInstanceForSort.

@Test
public void getInstanceForSort() {
    for (RealmFieldType type : SortDescriptor.validFieldTypesForSort) {
        table.addColumn(type, type.name());
    }
    long i = 0;
    for (RealmFieldType type : SortDescriptor.validFieldTypesForSort) {
        SortDescriptor sortDescriptor = SortDescriptor.getInstanceForSort(table, type.name(), Sort.DESCENDING);
        assertEquals(1, sortDescriptor.getColumnIndices()[0].length);
        assertEquals(i, sortDescriptor.getColumnIndices()[0][0]);
        assertFalse(sortDescriptor.getAscendings()[0]);
        i++;
    }
}
Also used : RealmFieldType(io.realm.RealmFieldType) Test(org.junit.Test)

Example 17 with RealmFieldType

use of io.realm.RealmFieldType in project realm-java by realm.

the class SortDescriptorTests method getInstanceForDistinct.

@Test
public void getInstanceForDistinct() {
    for (RealmFieldType type : SortDescriptor.validFieldTypesForDistinct) {
        long column = table.addColumn(type, type.name());
        table.addSearchIndex(column);
    }
    long i = 0;
    for (RealmFieldType type : SortDescriptor.validFieldTypesForDistinct) {
        SortDescriptor sortDescriptor = SortDescriptor.getInstanceForDistinct(table, type.name());
        assertEquals(1, sortDescriptor.getColumnIndices()[0].length);
        assertEquals(i, sortDescriptor.getColumnIndices()[0][0]);
        assertNull(sortDescriptor.getAscendings());
        i++;
    }
}
Also used : RealmFieldType(io.realm.RealmFieldType) Test(org.junit.Test)

Example 18 with RealmFieldType

use of io.realm.RealmFieldType in project realm-java by realm.

the class SortDescriptorTests method getInstanceForSort_shouldThrowOnLinkListField.

@Test
public void getInstanceForSort_shouldThrowOnLinkListField() {
    RealmFieldType type = RealmFieldType.STRING;
    RealmFieldType listType = RealmFieldType.LIST;
    table.addColumn(type, type.name());
    table.addColumnLink(listType, listType.name(), table);
    thrown.expect(IllegalArgumentException.class);
    thrown.expectMessage("is not a supported link field");
    SortDescriptor.getInstanceForSort(table, String.format("%s.%s", listType.name(), type.name()), Sort.ASCENDING);
}
Also used : RealmFieldType(io.realm.RealmFieldType) Test(org.junit.Test)

Aggregations

RealmFieldType (io.realm.RealmFieldType)18 Test (org.junit.Test)16 Date (java.util.Date)5 Pair (android.util.Pair)3 ArrayList (java.util.ArrayList)2 RealmException (io.realm.exceptions.RealmException)1