mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 21:03:54 +01:00
Convert API clients to kotlin (#5567)
* Convert UserClient to kotlin * Added tests for WikiBaseClient * Removed superfluous dao tests in review helper and got the proper ReviewDaoTest running in the unit test suite * Improved tests for ReviewHelper * Convert the ReviewHelper to kotlin * Convert the WikiBaseClient to kotlin * Convert the WikidataClient to kotlin
This commit is contained in:
parent
c43405267a
commit
728712c4e1
15 changed files with 496 additions and 526 deletions
|
|
@ -1,74 +0,0 @@
|
|||
package fr.free.nrw.commons;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
|
||||
import android.content.Context;
|
||||
import androidx.room.Room;
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
import fr.free.nrw.commons.db.AppDatabase;
|
||||
import fr.free.nrw.commons.review.ReviewDao;
|
||||
import fr.free.nrw.commons.review.ReviewEntity;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class ReviewDaoTest {
|
||||
|
||||
private ReviewDao reviewDao;
|
||||
private AppDatabase database;
|
||||
|
||||
/**
|
||||
* Set up the application database
|
||||
*/
|
||||
@Before
|
||||
public void createDb() {
|
||||
Context context = ApplicationProvider.getApplicationContext();
|
||||
database = Room.inMemoryDatabaseBuilder(
|
||||
context, AppDatabase.class)
|
||||
.allowMainThreadQueries()
|
||||
.build();
|
||||
reviewDao = database.ReviewDao();
|
||||
}
|
||||
|
||||
/**
|
||||
* Close the database
|
||||
*/
|
||||
@After
|
||||
public void closeDb() {
|
||||
database.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test insertion
|
||||
* Also checks isReviewedAlready():
|
||||
* Case 1: When image has been reviewed/skipped by the user
|
||||
*/
|
||||
@Test
|
||||
public void insert() {
|
||||
// Insert data
|
||||
String imageId = "1234";
|
||||
ReviewEntity reviewEntity = new ReviewEntity(imageId);
|
||||
reviewDao.insert(reviewEntity);
|
||||
|
||||
// Check insertion
|
||||
// Covers the case where the image exists in the database
|
||||
// And isReviewedAlready() returns true
|
||||
Boolean isInserted = reviewDao.isReviewedAlready(imageId);
|
||||
assertThat(isInserted, equalTo(true));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test review status of the image
|
||||
* Case 2: When image has not been reviewed/skipped
|
||||
*/
|
||||
@Test
|
||||
public void isReviewedAlready(){
|
||||
String imageId = "5856";
|
||||
Boolean isInserted = reviewDao.isReviewedAlready(imageId);
|
||||
assertThat(isInserted, equalTo(false));
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue