@Test public void testExecSQLAutoIncrementSQLite() throws Exception { database.execSQL("CREATE TABLE auto_table (id INTEGER PRIMARY KEY AUTOINCREMENT, name VARCHAR(255));"); ContentValues values = new ContentValues(); values.put("name", "Chuck"); long key = database.insert("auto_table", null, values); assertThat(key).isNotEqualTo(0L); long key2 = database.insert("auto_table", null, values); assertThat(key2).isNotEqualTo(key); }
@Test public void testInsertRowIdGeneration() throws Exception { ContentValues values = new ContentValues(); values.put("name", "Chuck"); long id = database.insert("table_name", null, values); assertThat(id).isNotEqualTo(0L); }
public void testTouchTime() throws IOException { File temp = createTempFile(); assertTrue(temp.exists()); temp.setLastModified(0); assertEquals(0, temp.lastModified()); Files.touch(temp); assertThat(temp.lastModified()).isNotEqualTo(0); }
public void testTouchTime() throws IOException { Path temp = createTempFile(); assertTrue(Files.exists(temp)); Files.setLastModifiedTime(temp, FileTime.fromMillis(0)); assertEquals(0, Files.getLastModifiedTime(temp).toMillis()); MoreFiles.touch(temp); assertThat(Files.getLastModifiedTime(temp).toMillis()).isNotEqualTo(0); }
@Test public void testInsertKeyGeneration() throws Exception { ContentValues values = new ContentValues(); values.put("name", "Chuck"); long key = database.insertWithOnConflict("table_name", null, values, SQLiteDatabase.CONFLICT_IGNORE); assertThat(key).isNotEqualTo(0L); }
@Test public void shouldAllowForFakingOfTime() throws Exception { assertThat(SystemClock.uptimeMillis()).isNotEqualTo(1000); Robolectric.getForegroundThreadScheduler().advanceTo(1000); assertThat(SystemClock.uptimeMillis()).isEqualTo(1000); }
@Test public void testReplace() throws Exception { long id = addChuck(); assertThat(id).isNotEqualTo(-1L); ContentValues values = new ContentValues(); values.put("id", id); values.put("name", "Norris"); long replaceId = database.replace("table_name", null, values); assertThat(replaceId).isEqualTo(id); String query = "SELECT name FROM table_name where id = " + id; Cursor cursor = executeQuery(query); assertThat(cursor.moveToNext()).isTrue(); assertThat(cursor.getString(cursor.getColumnIndex("name"))).isEqualTo("Norris"); }
public void testUtf8() { char[] charsA = new char[128]; char[] charsB = new char[128]; for (int i = 0; i < charsA.length; i++) { if (i < 100) { charsA[i] = 'a'; charsB[i] = 'a'; } else { // Both two-byte characters, but must be different charsA[i] = (char) (0x0180 + i); charsB[i] = (char) (0x0280 + i); } } String stringA = new String(charsA); String stringB = new String(charsB); assertThat(stringA).isNotEqualTo(stringB); assertThat(HASH_FN.hashUnencodedChars(stringA)) .isNotEqualTo(HASH_FN.hashUnencodedChars(stringB)); assertThat(fingerprint(stringA.getBytes(UTF_8))) .isNotEqualTo(fingerprint(stringB.getBytes(UTF_8))); // ISO 8859-1 only has 0-255 (ubyte) representation so throws away UTF-8 characters // greater than 127 (ie with their top bit set). // Don't attempt to do this in real code. assertEquals( fingerprint(stringA.getBytes(ISO_8859_1)), fingerprint(stringB.getBytes(ISO_8859_1))); }
@Test public void testInsertEmptyBlobArgument() throws Exception { ContentValues emptyBlobValues = new ContentValues(); emptyBlobValues.put("id", 1); emptyBlobValues.put("blob_col", new byte[]{}); ContentValues nullBlobValues = new ContentValues(); nullBlobValues.put("id", 2); nullBlobValues.put("blob_col", (byte[])null); long key = database.insertWithOnConflict("blob_table", null, emptyBlobValues, SQLiteDatabase.CONFLICT_FAIL); assertThat(key).isNotEqualTo(0L); key = database.insertWithOnConflict("blob_table", null, nullBlobValues, SQLiteDatabase.CONFLICT_FAIL); assertThat(key).isNotEqualTo(0L); Cursor cursor = database.query("blob_table", new String[]{"blob_col"}, "id=1", null, null, null, null); try { assertThat(cursor.moveToFirst()).isTrue(); assertThat(cursor.getBlob(cursor.getColumnIndexOrThrow("blob_col"))).isNotNull(); } finally { cursor.close(); } cursor = database.query("blob_table", new String[]{"blob_col"}, "id=2", null, null, null, null); try { assertThat(cursor.moveToFirst()).isTrue(); assertThat(cursor.getBlob(cursor.getColumnIndexOrThrow("blob_col"))).isNull(); } finally { cursor.close(); } }
@Before public void setUp() throws Exception { database = SQLiteDatabase.create(null); database.execSQL("create table " + TABLE_NAME + " (" + COL_VALUE + " TEXT, " + COL_GROUP + " INTEGER" + ")"); ContentValues values = new ContentValues(); values.put(COL_VALUE, "record1"); values.put(COL_GROUP, 1); firstRecordId = database.insert(TABLE_NAME, null, values); assertThat(firstRecordId).isGreaterThan(0L); values.clear(); values.put(COL_VALUE, "record2"); values.put(COL_GROUP, 1); long secondRecordId = database.insert(TABLE_NAME, null, values); assertThat(secondRecordId).isGreaterThan(0L); assertThat(secondRecordId).isNotEqualTo(firstRecordId); values.clear(); values.put(COL_VALUE, "won't be selected"); values.put(COL_GROUP, 2); database.insert(TABLE_NAME, null, values); builder = new SQLiteQueryBuilder(); builder.setTables(TABLE_NAME); builder.appendWhere(COL_VALUE + " <> "); builder.appendWhereEscapeString("won't be selected"); }
@Test public void testMaxFileSize() throws Exception { assertThat(shadowMediaRecorder.getMaxFileSize()).isNotEqualTo(512000L); mediaRecorder.setMaxFileSize(512000); assertThat(shadowMediaRecorder.getMaxFileSize()).isEqualTo(512000L); }
@Test public void testModificationsAffectParsableArray() { ParsableByteArray parsableByteArray = getTestDataArray(); // When modifying the wrapped byte array byte[] data = parsableByteArray.data; long readValue = parsableByteArray.readUnsignedInt(); data[0] = (byte) (TEST_DATA[0] + 1); parsableByteArray.setPosition(0); // Then the parsed value changes. assertThat(parsableByteArray.readUnsignedInt()).isNotEqualTo(readValue); }
@Test public void initialBitrateEstimateOverwrite_forWifi_whileConnectedToOtherNetwork_doesNotSetInitialEstimate() { setActiveNetworkInfo(networkInfo2g); DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter.Builder(RuntimeEnvironment.application) .setInitialBitrateEstimate(C.NETWORK_TYPE_WIFI, 123456789) .build(); long initialEstimate = bandwidthMeter.getBitrateEstimate(); assertThat(initialEstimate).isNotEqualTo(123456789); }
@Test public void initialBitrateEstimateOverwrite_forEthernet_whileConnectedToOtherNetwork_doesNotSetInitialEstimate() { setActiveNetworkInfo(networkInfo2g); DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter.Builder(RuntimeEnvironment.application) .setInitialBitrateEstimate(C.NETWORK_TYPE_WIFI, 123456789) .build(); long initialEstimate = bandwidthMeter.getBitrateEstimate(); assertThat(initialEstimate).isNotEqualTo(123456789); }
@Test public void initialBitrateEstimateOverwrite_for4G_whileConnectedToOtherNetwork_doesNotSetInitialEstimate() { setActiveNetworkInfo(networkInfoWifi); DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter.Builder(RuntimeEnvironment.application) .setInitialBitrateEstimate(C.NETWORK_TYPE_4G, 123456789) .build(); long initialEstimate = bandwidthMeter.getBitrateEstimate(); assertThat(initialEstimate).isNotEqualTo(123456789); }
@Test public void initialBitrateEstimateOverwrite_for2G_whileConnectedToOtherNetwork_doesNotSetInitialEstimate() { setActiveNetworkInfo(networkInfoWifi); DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter.Builder(RuntimeEnvironment.application) .setInitialBitrateEstimate(C.NETWORK_TYPE_2G, 123456789) .build(); long initialEstimate = bandwidthMeter.getBitrateEstimate(); assertThat(initialEstimate).isNotEqualTo(123456789); }
@Test public void initialBitrateEstimateOverwrite_forOffline_whileConnectedToNetwork_doesNotSetInitialEstimate() { setActiveNetworkInfo(networkInfoWifi); DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter.Builder(RuntimeEnvironment.application) .setInitialBitrateEstimate(C.NETWORK_TYPE_OFFLINE, 123456789) .build(); long initialEstimate = bandwidthMeter.getBitrateEstimate(); assertThat(initialEstimate).isNotEqualTo(123456789); }
@Test public void initialBitrateEstimateOverwrite_for3G_whileConnectedToOtherNetwork_doesNotSetInitialEstimate() { setActiveNetworkInfo(networkInfoWifi); DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter.Builder(RuntimeEnvironment.application) .setInitialBitrateEstimate(C.NETWORK_TYPE_3G, 123456789) .build(); long initialEstimate = bandwidthMeter.getBitrateEstimate(); assertThat(initialEstimate).isNotEqualTo(123456789); }
@Test @Config(minSdk = JELLY_BEAN_MR1) public void shouldGetSerialNumberForUser() { long serialNumberInvalid = -1L; UserHandle userHandle = newUserHandle(10); assertThat(userManager.getSerialNumberForUser(userHandle)).isEqualTo(serialNumberInvalid); assertThat(userManager.getUserSerialNumber(userHandle.getIdentifier())) .isEqualTo(serialNumberInvalid); shadowOf(userManager).addUserProfile(userHandle); assertThat(userManager.getSerialNumberForUser(userHandle)).isNotEqualTo(serialNumberInvalid); assertThat(userManager.getUserSerialNumber(userHandle.getIdentifier())) .isNotEqualTo(serialNumberInvalid); }
@Test public void shouldAddCatWithDate(){ //given Date date = new Date(System.currentTimeMillis() - 60 * 1000); Cat cat = new Cat("Java",date); //when catEntityManager.add(cat); //then assertThat(catEntityManager.count()).isEqualTo(1); assertThat(cat.getId()).isNotEqualTo(0); }