public void testBlockSize() {
    Assert.expect(
        IllegalArgumentException.class,
        new CodeBlock() {
          public void run() throws Throwable {
            db().configure().blockSize(-1);
          }
        });

    Assert.expect(
        IllegalArgumentException.class,
        new CodeBlock() {
          public void run() throws Throwable {
            db().configure().blockSize(128);
          }
        });

    Assert.expect(
        GlobalOnlyConfigException.class,
        new CodeBlock() {
          public void run() throws Throwable {
            db().configure().blockSize(12);
          }
        });
  }
 public void test() {
   final EmbeddedConfiguration embeddedConfiguration = Db4oEmbedded.newConfiguration();
   Assert.expect(
       IllegalArgumentException.class,
       new CodeBlock() {
         public void run() throws Throwable {
           embeddedConfiguration.common().objectClass(Object.class);
         }
       });
 }
예제 #3
0
  private void assertStoredField(
      Class objectClass,
      String fieldName,
      final Object expectedFieldValue,
      Class expectedFieldType,
      boolean hasIndex,
      boolean isArray) {
    StoredClass storedClass = storedClass(objectClass);
    StoredField[] storedFields = storedClass.getStoredFields();
    Assert.areEqual(1, storedFields.length);
    final StoredField storedField = storedFields[0];
    Assert.areEqual(fieldName, storedField.getName());
    StoredField storedFieldByName = storedClass.storedField(fieldName, expectedFieldType);
    Assert.areEqual(storedField, storedFieldByName);

    Object item = retrieveOnlyInstance(objectClass);
    Assert.areEqual(expectedFieldValue, storedField.get(item));
    ReflectClass fieldType = storedField.getStoredType();
    Assert.areEqual(reflector().forClass(expectedFieldType), fieldType);
    Assert.areEqual(isArray, storedField.isArray());

    if (isMultiSession()) {
      return;
    }

    Assert.areEqual(hasIndex, storedField.hasIndex());

    // FIXME: test rename

    if (!hasIndex) {
      Assert.expect(
          RuntimeException.class,
          new CodeBlock() {
            public void run() throws Throwable {
              storedField.traverseValues(
                  new Visitor4() {
                    public void visit(Object obj) {}
                  });
            }
          });
    } else {
      final IntByRef count = new IntByRef();
      storedField.traverseValues(
          new Visitor4() {
            public void visit(Object obj) {
              count.value++;
              Assert.areEqual(expectedFieldValue, obj);
            }
          });
      Assert.areEqual(1, count.value);
    }
  }
예제 #4
0
 private void expectFailure(CodeBlock block) {
   Assert.expect(AssertionException.class, block);
 }