private void withCache(final Procedure4<ClientSlotCache> procedure) { ClientSlotCache clientSlotCache = null; try { clientSlotCache = (ClientSlotCache) Reflection4.getFieldValue(container(), "_clientSlotCache"); } catch (ReflectException e) { Assert.fail("Can't get field _clientSlotCache on container. " + e.toString()); } procedure.apply(clientSlotCache); }
public void run() { Assert.areEqual(_idx, _counter.value); _counter.value++; if (_fail) { Assert.fail(); } }
public void testAllThere() throws Exception { for (int i = 0; i < FOOS.length; i++) { Query q = createQuery(FOOS[i]); ObjectSet objectSet = q.execute(); Assert.areEqual(1, objectSet.size()); FieldIndexItem fii = (FieldIndexItem) objectSet.next(); Assert.areEqual(FOOS[i], fii.foo); } }
public static void areEqual(Iterator expected, Iterator actual) { if (null == expected) { Assert.isNull(actual); return; } Assert.isNotNull(actual); while (expected.hasNext()) { Assert.isTrue(actual.hasNext()); Assert.areEqual(expected.next(), actual.next()); } Assert.isFalse(actual.hasNext()); }
public void testGetStoredFields() { assertStoredField(Item.class, FIELD_NAME, ITEM_NAME, String.class, true, false); assertStoredField(ItemParent.class, "_array", null, String.class, false, true); StoredClass itemStoredClass = itemStoredClass(); StoredField storedField = itemStoredClass.storedField(FIELD_NAME, null); StoredField sameStoredField = itemStoredClass.getStoredFields()[0]; StoredField otherStoredField = storedClass(ItemParent.class).getStoredFields()[0]; Assert.equalsAndHashcode(storedField, sameStoredField, otherStoredField); Assert.isNull(itemStoredClass.storedField("", null)); }
public static void runTestAndExpect( final Iterable4 tests, int expFailures, boolean checkException) { final TestResult result = new TestResult(); new TestRunner(tests).run(result); if (expFailures != result.failures().size()) { Assert.fail(result.failures().toString()); } if (checkException) { for (Iterator4 iter = result.failures().iterator(); iter.moveNext(); ) { TestFailure failure = (TestFailure) iter.current(); Assert.areEqual(EXCEPTION, failure.reason()); } } }
private void assertTestRuns(int... failingIndices) { IntByRef counter = new IntByRef(); TestResult result = new TestResult() { @Override public void testStarted(Test test) { super.testStarted(test); Assert.isInstanceOf(CountingTest.class, test); } }; new TestRunner(Iterators.iterable(new SimpleTestSuite(counter, NUM_TESTS, failingIndices))) .run(result); Assert.areEqual(NUM_TESTS, result.testCount()); Assert.areEqual(failingIndices.length, result.failures().size()); Assert.areEqual(NUM_TESTS + 2, counter.value); }
private void checkConsistency() { ConsistencyReport report = new ConsistencyChecker((LocalObjectContainer) container()).checkSlotConsistency(); if (!report.consistent()) { Assert.fail(report.toString()); } }
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); } }
public static void sameContent(Iterator expected, Iterator actual) { final Collection4 allExpected = new Collection4(); while (expected.hasNext()) { allExpected.add(expected.next()); } while (actual.hasNext()) { final Object current = actual.next(); final boolean removed = allExpected.remove(current); if (!removed) { unexpected(current); } } Assert.isTrue(allExpected.isEmpty(), allExpected.toString()); }
public void test() { final Collection4 expected = new Collection4(new Object[] {"PING", Boolean.TRUE, new Integer(42)}); final MessageCollector recipient = new MessageCollector(); final ObjectServer server = openServerWith(recipient); try { final ObjectContainer client = openClient("client", server); try { final MessageSender sender = messageSender(client); sendAll(expected, sender); } finally { client.close(); } } finally { server.close(); } Assert.areEqual(expected.toString(), recipient.messages.toString()); }
public void testRunsRed() { TestResult result = new TestResult(); new TestRunner(Iterators.singletonIterable(new RunsRed(EXCEPTION))).run(result); Assert.isTrue(result.failures().size() == 1, "not red"); }
public void testRunsGreen() { TestResult result = new TestResult(); new TestRunner(Iterators.singletonIterable(new RunsGreen())).run(result); Assert.isTrue(result.failures().size() == 0, "not green"); }
public void test() { Assert.isNotNull(db()); Assert.isNotNull(values); }
private static void unexpected(Object element) { Assert.fail("Unexpected element: " + element); }
public void testUnknownStoredClass() { Assert.isNull(storedClass(this.getClass())); }
@Override protected void suiteTearDown() throws Exception { Assert.areEqual(_numTests + 1, _counter.value); _counter.value++; }
@Override protected void suiteSetUp() throws Exception { Assert.areEqual(0, _counter.value); _counter.value++; }
public void testEqualsAndHashCode() { StoredClass clazz = itemStoredClass(); StoredClass same = itemStoredClass(); StoredClass other = db().storedClass(ItemParent.class); Assert.equalsAndHashcode(clazz, same, other); }
public void testStoredClassImpl() { Assert.isInstanceOf(StoredClassImpl.class, itemStoredClass()); }
public void testGetIds() { StoredClass itemClass = itemStoredClass(); long[] ids = itemClass.getIDs(); Assert.areEqual(1, ids.length); Assert.areEqual(_id, ids[0]); }
public void testGetParentStoredClass() { StoredClass itemClass = itemStoredClass(); StoredClass parentStoredClass = itemClass.getParentStoredClass(); Assert.areEqual(reflector().forClass(ItemParent.class).getName(), parentStoredClass.getName()); Assert.areEqual(parentStoredClass, db().storedClass(ItemParent.class)); }
public void testGetName() { StoredClass itemClass = itemStoredClass(); Assert.areEqual(reflector().forClass(Item.class).getName(), itemClass.getName()); }
private void assertHandlerComparison(Comparable4 handler, Object smaller, Object greater) { PreparedComparison comparable = handler.prepareComparison(context(), smaller); Assert.isNotNull(comparable); Assert.areEqual(0, comparable.compareTo(smaller)); Assert.isSmaller(0, comparable.compareTo(greater)); Assert.isGreater(0, comparable.compareTo(null)); comparable = handler.prepareComparison(context(), greater); Assert.isNotNull(comparable); Assert.areEqual(0, comparable.compareTo(greater)); Assert.isGreater(0, comparable.compareTo(smaller)); Assert.isGreater(0, comparable.compareTo(null)); comparable = handler.prepareComparison(context(), null); Assert.isNotNull(comparable); Assert.areEqual(0, comparable.compareTo(null)); Assert.isSmaller(0, comparable.compareTo(smaller)); }
public void testAccessingBTree() throws Exception { BTree bTree = storedField().getIndex(trans()); Assert.isNotNull(bTree); expectKeysSearch(bTree, FOOS); }