Exemplo n.º 1
0
 public boolean methodWrongThread(final Method method)
     throws ExecutionException, InterruptedException {
   final RealmResults<AllTypes> allTypeses = testRealm.where(AllTypes.class).findAll();
   testRealm.beginTransaction();
   ExecutorService executorService = Executors.newSingleThreadExecutor();
   Future<Boolean> future =
       executorService.submit(
           new Callable<Boolean>() {
             @Override
             public Boolean call() throws Exception {
               try {
                 switch (method) {
                   case METHOD_MIN:
                     allTypeses.min(FIELD_FLOAT);
                     break;
                   case METHOD_MAX:
                     allTypeses.max(FIELD_FLOAT);
                     break;
                   case METHOD_SUM:
                     allTypeses.sum(FIELD_FLOAT);
                     break;
                   case METHOD_AVG:
                     allTypeses.average(FIELD_FLOAT);
                     break;
                   case METHOD_SORT:
                     allTypeses.sort(FIELD_FLOAT);
                     break;
                   case METHOD_WHERE:
                     allTypeses.where();
                     break;
                   case METHOD_REMOVE:
                     allTypeses.remove(0);
                     break;
                   case METHOD_REMOVE_LAST:
                     allTypeses.removeLast();
                     break;
                   case METHOD_CLEAR:
                     allTypeses.clear();
                     break;
                 }
                 return false;
               } catch (IllegalStateException ignored) {
                 return true;
               }
             }
           });
   Boolean result = future.get();
   testRealm.cancelTransaction();
   return result;
 }
Exemplo n.º 2
0
  // Setting a not-nullable field to null is an error
  public void testNullFieldNotNullableField() {
    TestHelper.populateTestRealmForNullTests(testRealm);
    RealmResults<NullTypes> list = testRealm.allObjects(NullTypes.class);

    // 1 String
    try {
      testRealm.beginTransaction();
      list.first().setFieldStringNotNull(null);
      fail();
    } catch (IllegalArgumentException ignored) {
    } finally {
      testRealm.cancelTransaction();
    }

    // 2 Bytes
    try {
      testRealm.beginTransaction();
      list.first().setFieldBytesNotNull(null);
      fail();
    } catch (IllegalArgumentException ignored) {
    } finally {
      testRealm.cancelTransaction();
    }

    // 3 Boolean
    try {
      testRealm.beginTransaction();
      list.first().setFieldBooleanNotNull(null);
      fail();
    } catch (IllegalArgumentException ignored) {
    } finally {
      testRealm.cancelTransaction();
    }

    // 4 Byte
    try {
      testRealm.beginTransaction();
      list.first().setFieldBytesNotNull(null);
      fail();
    } catch (IllegalArgumentException ignored) {
    } finally {
      testRealm.cancelTransaction();
    }

    // 5 Short 6 Integer 7 Long are skipped for this case, same with Bytes

    // 8 Float
    try {
      testRealm.beginTransaction();
      list.first().setFieldFloatNotNull(null);
      fail();
    } catch (IllegalArgumentException ignored) {
    } finally {
      testRealm.cancelTransaction();
    }

    // 9 Double
    try {
      testRealm.beginTransaction();
      list.first().setFieldDoubleNotNull(null);
      fail();
    } catch (IllegalArgumentException ignored) {
    } finally {
      testRealm.cancelTransaction();
    }

    // 10 Date
    try {
      testRealm.beginTransaction();
      list.first().setFieldDateNotNull(null);
      fail();
    } catch (IllegalArgumentException ignored) {
    } finally {
      testRealm.cancelTransaction();
    }
  }