@Test public void shouldAddFloatColumnForInsert() { final float value = 2; assertThat(sqlInsertRequest() .table(TABLE) .column(COLUMN, value) .compile().contentValues.getAsFloat(COLUMN), is(value)); }
@Test public void shouldAddNullFloatColumnForInsert() { final Float nullValue = null; assertThat(sqlInsertRequest() .table(TABLE) .column(COLUMN, nullValue) .compile().contentValues.getAsFloat(COLUMN), is(nullValue)); }
@Override public Float getAsFloat(String key) { return contentValues.getAsFloat(key); }
public Float getAsFloat(String key) { return values.getAsFloat(escape(key)); }
private Uri insertProduct(Uri uri, ContentValues values) { String name = values.getAsString(ProductEntry.COLUMN_PRODUCT_NAME); if (name == null) { throw new IllegalArgumentException("Product requires a name"); } Integer quantity = values.getAsInteger(ProductEntry.COLUMN_PRODUCT_QUANTITY); if (quantity != null && quantity < 0) { throw new IllegalArgumentException("Product requires valid quantity"); } Float price = values.getAsFloat(ProductEntry.COLUMN_PRODUCT_PRICE); if (price != null && price < 0) { throw new IllegalArgumentException("Product requires valid price"); } SQLiteDatabase database = mDbHelper.getReadableDatabase(); long id = database.insert(ProductEntry.TABLE_NAME, null, values); if (id == -1) { Log.e(LOG_TAG, "Failed to insert row for " + uri); return null; } getContext().getContentResolver().notifyChange(uri, null); return ContentUris.withAppendedId(uri, id); }
Float price = values.getAsFloat(ProductEntry.COLUMN_PRODUCT_PRICE); if (price != null && price < 0) { throw new IllegalArgumentException("Product requires valid price");
items.add(new Item(values.getAsString("name"),values.getAsFloat("price")))
break; case TYPE_FLOAT: setIfNotNull(field, object, values.getAsFloat(columnName)); break; case TYPE_DOUBLE:
private static void assertContentValuesEquals(ContentValues expected, ContentValues actual) { assertNotNull(actual); assertEquals(expected.getAsString("COL_STRING"), actual.getAsString("COL_STRING")); assertEquals(expected.getAsString("COL_STRING_NULL"), actual.getAsString("COL_STRING_NULL")); assertEquals(expected.getAsByte("COL_BYTE"), actual.getAsByte("COL_BYTE")); assertEquals(expected.getAsShort("COL_SHORT"), actual.getAsShort("COL_SHORT")); assertEquals(expected.getAsInteger("COL_INTEGER"), actual.getAsInteger("COL_INTEGER")); assertEquals(expected.getAsLong("COL_LONG"), actual.getAsLong("COL_LONG")); assertEquals(expected.getAsFloat("COL_FLOAT"), actual.getAsFloat("COL_FLOAT")); assertEquals(expected.getAsDouble("COL_DOUBLE"), actual.getAsDouble("COL_DOUBLE")); assertEquals(expected.getAsBoolean("COL_BOOLEAN"), actual.getAsBoolean("COL_BOOLEAN")); assertArrayEquals(expected.getAsByteArray("COL_BYTE_ARRAY"), actual.getAsByteArray("COL_BYTE_ARRAY")); }