-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix the connected tests (disable tests which where skipped before by …
…FlakyTest flag)
- Loading branch information
Showing
10 changed files
with
306 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
115 changes: 115 additions & 0 deletions
115
persistence/src/androidTest/java/de/cyface/persistence/TestUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
/* | ||
* Copyright 2017 Cyface GmbH | ||
* | ||
* This file is part of the Cyface SDK for Android. | ||
* | ||
* The Cyface SDK for Android is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* The Cyface SDK for Android is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with the Cyface SDK for Android. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package de.cyface.persistence; | ||
|
||
import static junit.framework.TestCase.fail; | ||
import static org.hamcrest.CoreMatchers.equalTo; | ||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.hamcrest.CoreMatchers.not; | ||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNotEquals; | ||
import static org.junit.Assert.assertThat; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import android.content.ContentResolver; | ||
import android.content.ContentValues; | ||
import android.database.Cursor; | ||
import android.net.Uri; | ||
import android.provider.BaseColumns; | ||
|
||
import de.cyface.utils.Validate; | ||
|
||
/** | ||
* A utility class with static methods for supporting tests on the persistence code. | ||
* | ||
* @author Klemens Muthmann | ||
* @version 2.0.3 | ||
* @since 1.0.0 | ||
*/ | ||
class TestUtils { | ||
|
||
static final String AUTHORITY = "de.cyface.persistence.test.provider"; | ||
|
||
private static void compareCursorWithValues(final Cursor cursor, final List<ContentValues> contentValues) { | ||
assertThat(contentValues.size() <= cursor.getCount(), is(equalTo(true))); | ||
for (ContentValues values : contentValues) { | ||
cursor.moveToNext(); | ||
for (String key : values.keySet()) { | ||
int cursorColumnIndex = cursor.getColumnIndex(key); | ||
assertNotEquals(cursorColumnIndex, -1); | ||
int dataType = cursor.getType(cursorColumnIndex); | ||
switch (dataType) { | ||
case Cursor.FIELD_TYPE_FLOAT: | ||
assertEquals(values.getAsDouble(key), cursor.getDouble(cursorColumnIndex), 0.01); | ||
break; | ||
case Cursor.FIELD_TYPE_INTEGER: | ||
assertEquals((long)values.getAsLong(key), cursor.getLong(cursorColumnIndex)); | ||
break; | ||
case Cursor.FIELD_TYPE_STRING: | ||
assertEquals(values.getAsString(key), cursor.getString(cursorColumnIndex)); | ||
default: | ||
fail(); | ||
} | ||
} | ||
} | ||
} | ||
|
||
static long create(final ContentResolver mockResolver, final Uri contentUri, final ContentValues entry) { | ||
final Uri result = mockResolver.insert(contentUri, entry); | ||
Validate.notNull(result); | ||
assertThat("Unable to create new entry.", result.getLastPathSegment(), is(not("-1"))); | ||
Validate.notNull(result.getLastPathSegment()); | ||
long identifier = Long.parseLong(result.getLastPathSegment()); | ||
assertThat("Entry inserted under wrong id.", identifier > 0L, is(true)); | ||
return identifier; | ||
} | ||
|
||
static void read(final ContentResolver mockResolver, final Uri contentUri, final ContentValues entry) { | ||
try (Cursor cursor = mockResolver.query(contentUri, null, null, null, null);) { | ||
List<ContentValues> fixture = new ArrayList<>(); | ||
fixture.add(entry); | ||
Validate.notNull(cursor); | ||
TestUtils.compareCursorWithValues(cursor, fixture); | ||
} | ||
} | ||
|
||
static void update(final ContentResolver mockResolver, final Uri contentUri, final long identifier, | ||
final String columnName, final double changedValue) { | ||
ContentValues changedValues = new ContentValues(); | ||
changedValues.put(columnName, changedValue); | ||
|
||
final int rowsUpdated = mockResolver.update(contentUri, changedValues, BaseColumns._ID + "=?", | ||
new String[] {Long.valueOf(identifier).toString()}); | ||
assertEquals("Update of rotation point was unsuccessful.", 1, rowsUpdated); | ||
} | ||
|
||
static void delete(final ContentResolver mockResolver, final Uri contentUri, final long identifier) { | ||
final int rowsDeleted = mockResolver.delete(contentUri, BaseColumns._ID + "=?", | ||
new String[] {String.valueOf(identifier)}); | ||
assertEquals("Delete was unsuccessful for uri " + contentUri, 1, rowsDeleted); | ||
} | ||
|
||
static int count(final ContentResolver mockResolver, final Uri contentUri) { | ||
final Cursor cursor = mockResolver.query(contentUri, null, null, null, null); | ||
Validate.notNull(cursor); | ||
return cursor.getCount(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
synchronization/src/androidTest/java/de/cyface/synchronization/MockAuth.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package de.cyface.synchronization; | ||
|
||
import android.accounts.AbstractAccountAuthenticator; | ||
import android.accounts.Account; | ||
import android.accounts.AccountAuthenticatorResponse; | ||
import android.accounts.AccountManager; | ||
import android.accounts.NetworkErrorException; | ||
import android.content.Context; | ||
import android.os.Bundle; | ||
|
||
public class MockAuth extends AbstractAccountAuthenticator { | ||
public MockAuth(Context context) { | ||
super(context); | ||
} | ||
|
||
@Override | ||
public Bundle editProperties(AccountAuthenticatorResponse response, String accountType) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public Bundle addAccount(AccountAuthenticatorResponse response, String accountType, String authTokenType, String[] requiredFeatures, Bundle options) throws NetworkErrorException { | ||
return null; | ||
} | ||
|
||
@Override | ||
public Bundle confirmCredentials(AccountAuthenticatorResponse response, Account account, Bundle options) throws NetworkErrorException { | ||
return null; | ||
} | ||
|
||
@Override | ||
public Bundle getAuthToken(AccountAuthenticatorResponse response, Account account, String authTokenType, Bundle options) throws NetworkErrorException { | ||
|
||
// Return a bundle containing the token | ||
//Log.v(TAG, "Fresh authToken: **" + freshAuthToken.substring(freshAuthToken.length - 7)) | ||
final var result = new Bundle(); | ||
result.putString(AccountManager.KEY_ACCOUNT_NAME, account.name); | ||
result.putString(AccountManager.KEY_ACCOUNT_TYPE, account.type); | ||
result.putString(AccountManager.KEY_AUTHTOKEN, "eyTestToken"); | ||
return result; | ||
} | ||
|
||
@Override | ||
public String getAuthTokenLabel(String authTokenType) { | ||
return "JWT test token"; | ||
} | ||
|
||
@Override | ||
public Bundle updateCredentials(AccountAuthenticatorResponse response, Account account, String authTokenType, Bundle options) throws NetworkErrorException { | ||
return null; | ||
} | ||
|
||
@Override | ||
public Bundle hasFeatures(AccountAuthenticatorResponse response, Account account, String[] features) throws NetworkErrorException { | ||
return null; | ||
} | ||
} |
Oops, something went wrong.