-
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.
- Loading branch information
Showing
143 changed files
with
2,844 additions
and
1,141 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
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
95 changes: 95 additions & 0 deletions
95
app/src/androidTest/java/com/teester/whatsnearby/DatabaseInstrumentedTest.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,95 @@ | ||
package com.teester.whatsnearby; | ||
|
||
import android.arch.core.executor.testing.InstantTaskExecutorRule; | ||
import android.arch.persistence.room.Room; | ||
import android.support.test.InstrumentationRegistry; | ||
import android.support.test.runner.AndroidJUnit4; | ||
|
||
import com.teester.whatsnearby.data.OsmObject; | ||
import com.teester.whatsnearby.data.database.AppDatabase; | ||
import com.teester.whatsnearby.data.database.VisitedLocation; | ||
import com.teester.whatsnearby.data.database.VisitedLocationDao; | ||
|
||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import java.util.List; | ||
|
||
import static junit.framework.Assert.assertEquals; | ||
import static junit.framework.Assert.assertNull; | ||
import static junit.framework.Assert.assertTrue; | ||
|
||
@RunWith(AndroidJUnit4.class) | ||
public class DatabaseInstrumentedTest { | ||
|
||
@Rule | ||
public InstantTaskExecutorRule instantTaskExecutorRule = new InstantTaskExecutorRule(); | ||
|
||
private AppDatabase mDatabase; | ||
private VisitedLocationDao visitedLocationDao; | ||
private OsmObject osmObject = new OsmObject(1, "", "1", "", 1, 1, 1); | ||
private OsmObject osmObject2 = new OsmObject(2, "", "2", "", 1, 1, 1); | ||
private OsmObject osmObject3 = new OsmObject(3, "", "3", "", 1, 1, 1); | ||
private OsmObject osmObject4 = new OsmObject(4, "", "4", "", 1, 1, 1); | ||
private OsmObject osmObject5 = new OsmObject(5, "", "5", "", 1, 1, 1); | ||
|
||
@Before | ||
public void initDb() throws Exception { | ||
mDatabase = Room.inMemoryDatabaseBuilder(InstrumentationRegistry.getContext(), | ||
AppDatabase.class) | ||
.allowMainThreadQueries() | ||
.build(); | ||
|
||
visitedLocationDao = mDatabase.visitedLocationDao(); | ||
} | ||
|
||
@After | ||
public void closeDb() throws Exception { | ||
mDatabase.close(); | ||
} | ||
|
||
@Test | ||
public void onFetchingLocationsShouldGetEmptyListIfTableIsEmpty() throws InterruptedException { | ||
List<VisitedLocation> LocationList = visitedLocationDao.getAllVisitedLocations(); | ||
assertTrue(LocationList.isEmpty()); | ||
} | ||
|
||
@Test | ||
public void onInsertingLocationsCheckIfRowCountIsCorrect() throws InterruptedException { | ||
visitedLocationDao.insert(new VisitedLocation(osmObject)); | ||
visitedLocationDao.insert(new VisitedLocation(osmObject2)); | ||
visitedLocationDao.insert(new VisitedLocation(osmObject3)); | ||
visitedLocationDao.insert(new VisitedLocation(osmObject4)); | ||
visitedLocationDao.insert(new VisitedLocation(osmObject5)); | ||
|
||
assertEquals(5, visitedLocationDao.getAllVisitedLocations().size()); | ||
} | ||
|
||
@Test | ||
public void onUpdatingALocationCheckIfUpdateHappensCorrectly() throws InterruptedException { | ||
VisitedLocation visitedLocation = new VisitedLocation(osmObject); | ||
visitedLocationDao.insert(visitedLocation); | ||
|
||
visitedLocation = visitedLocationDao.findByOsmId(osmObject.getId()); | ||
visitedLocation.setName("New Name"); | ||
visitedLocationDao.update(visitedLocation); | ||
|
||
assertEquals(1, visitedLocationDao.getAllVisitedLocations().size()); | ||
assertEquals("New Name", visitedLocationDao.findByOsmId(osmObject.getId()).getName()); | ||
} | ||
|
||
@Test | ||
public void onLocationDeletionCheckIfLocationIsDeletedFromTable() { | ||
visitedLocationDao.insert(new VisitedLocation(osmObject)); | ||
visitedLocationDao.insert(new VisitedLocation(osmObject2)); | ||
visitedLocationDao.insert(new VisitedLocation(osmObject3)); | ||
visitedLocationDao.insert(new VisitedLocation(osmObject4)); | ||
visitedLocationDao.insert(new VisitedLocation(osmObject5)); | ||
|
||
visitedLocationDao.delete(visitedLocationDao.findByOsmId(osmObject2.getId())); | ||
assertNull(visitedLocationDao.findByOsmId(osmObject2.getId())); | ||
} | ||
} |
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
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
Oops, something went wrong.