@Test public void testMissingColumns() { ContentValues values = new ContentValues(); values.put("a", 123); values.put("b", "stringValue"); values.put("c", new byte[] { 3, 2, 1 }); values.putNull("d"); MatrixCursor cursor = new MatrixCursor(new String[] { "c", "b" }); cursor.addRow(new Seq<>(new byte[] { 3, 2, 1 }, "stringValue")); cursor.moveToFirst(); assertThat(new ContainsValues(values), is(not(satisfiedBy(cursor)))); }
@Override public boolean satisfiedBy(Cursor testedInstance) { for (String key : mValues.keySet()) { int columnIdx = testedInstance.getColumnIndex(key); if (columnIdx < 0) { return false; } if (testedInstance.getType(columnIdx) == Cursor.FIELD_TYPE_BLOB) { if (!Arrays.equals(mValues.getAsByteArray(key), testedInstance.getBlob(columnIdx))) { return false; } } else { String stringValue = mValues.getAsString(key); if (stringValue != null && !stringValue.equals(testedInstance.getString(columnIdx)) || stringValue == null && !testedInstance.isNull(columnIdx)) { return false; } } } return true; }
ContainsValues implements Predicate<Cursor> { @Override public boolean satisfiedBy(Cursor testedInstance) { for (String key : mValues.keySet()) { int columnIdx = testedInstance.getColumnIndex(key); if (columnIdx < 0) { return false; } if (testedInstance.getType(columnIdx) == Cursor.FIELD_TYPE_BLOB) { if (!Arrays.equals(mValues.getAsByteArray(key), testedInstance.getBlob(columnIdx))) { return false; } } else { String stringValue = mValues.getAsString(key); if (stringValue != null && !stringValue.equals(testedInstance.getString(columnIdx)) || stringValue == null && !testedInstance.isNull(columnIdx)) { return false; } } } return true; } }
ContainsValues implements Predicate<Cursor> { @Override public boolean satisfiedBy(Cursor testedInstance) { for (String key : mValues.keySet()) { int columnIdx = testedInstance.getColumnIndex(key); if (columnIdx < 0) { return false; } if (testedInstance.getType(columnIdx) == Cursor.FIELD_TYPE_BLOB) { if (!Arrays.equals(mValues.getAsByteArray(key), testedInstance.getBlob(columnIdx))) { return false; } } else { String stringValue = mValues.getAsString(key); if (stringValue != null && !stringValue.equals(testedInstance.getString(columnIdx)) || stringValue == null && !testedInstance.isNull(columnIdx)) { return false; } } } return true; } ContainsValues(ContentValues values); }
ContainsValues implements Predicate<Cursor> { @Override public boolean satisfiedBy(Cursor testedInstance) { for (String key : mValues.keySet()) { int columnIdx = testedInstance.getColumnIndex(key); if (columnIdx < 0) { return false; } if (testedInstance.getType(columnIdx) == Cursor.FIELD_TYPE_BLOB) { if (!Arrays.equals(mValues.getAsByteArray(key), testedInstance.getBlob(columnIdx))) { return false; } } else { String stringValue = mValues.getAsString(key); if (stringValue != null && !stringValue.equals(testedInstance.getString(columnIdx)) || stringValue == null && !testedInstance.isNull(columnIdx)) { return false; } } } return true; } ContainsValues(ContentValues values); @Override boolean satisfiedBy(Cursor testedInstance); }
ContainsValues implements Predicate<Cursor> { @Override public boolean satisfiedBy(Cursor testedInstance) { for (String key : mValues.keySet()) { int columnIdx = testedInstance.getColumnIndex(key); if (columnIdx < 0) { return false; } if (testedInstance.getType(columnIdx) == Cursor.FIELD_TYPE_BLOB) { if (!Arrays.equals(mValues.getAsByteArray(key), testedInstance.getBlob(columnIdx))) { return false; } } else { String stringValue = mValues.getAsString(key); if (stringValue != null && !stringValue.equals(testedInstance.getString(columnIdx)) || stringValue == null && !testedInstance.isNull(columnIdx)) { return false; } } } return true; } ContainsValues(ContentValues values); @Override boolean satisfiedBy(Cursor testedInstance);  }