Skip to content

Commit

Permalink
Merge pull request #123 from Factotum-sdp/feature/contacts_update
Browse files Browse the repository at this point in the history
Feature/contacts update
  • Loading branch information
TimVW7 authored Apr 24, 2023
2 parents 16eaff7 + d9c7179 commit 53048fb
Show file tree
Hide file tree
Showing 104 changed files with 2,325 additions and 1,539 deletions.
88 changes: 39 additions & 49 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ android {
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

packagingOptions {
exclude 'META-INF/LICENSE.md'
exclude 'META-INF/LICENSE-notice.md'
}

buildTypes {
release {
minifyEnabled false
Expand Down Expand Up @@ -54,69 +59,54 @@ android {
}

dependencies {

androidTestImplementation 'androidx.arch.core:core-testing:2.2.0'
debugImplementation "androidx.fragment:fragment-testing:1.5.6"
implementation 'androidx.core:core-ktx:1.10.0'
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.8.0'
implementation 'com.google.android.gms:play-services-maps:18.1.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.navigation:navigation-fragment-ktx:2.5.3'
implementation 'androidx.navigation:navigation-ui-ktx:2.5.3'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.recyclerview:recyclerview:1.3.0'
implementation "androidx.fragment:fragment-ktx:1.5.6"
implementation 'androidx.test.espresso:espresso-contrib:3.5.1'
implementation platform('com.google.firebase:firebase-bom:31.2.3') // Firebase BOM
implementation 'com.google.firebase:firebase-auth-ktx'
implementation 'com.google.firebase:firebase-database-ktx'

implementation 'com.google.firebase:firebase-database-ktx:20.2.0'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.6.4'

implementation 'com.github.bumptech.glide:glide:4.15.1'
kapt 'com.github.bumptech.glide:compiler:4.15.1'

implementation 'androidx.fragment:fragment-ktx:1.5.6'
implementation 'androidx.lifecycle:lifecycle-common-java8:2.6.1'
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.6.1'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.1'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.navigation:navigation-dynamic-features-fragment:2.5.3'
implementation 'androidx.navigation:navigation-fragment-ktx:2.5.3'
implementation 'androidx.navigation:navigation-ui-ktx:2.5.3'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.6.1'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.1'
implementation 'androidx.recyclerview:recyclerview:1.3.0'
implementation 'androidx.test.espresso:espresso-contrib:3.5.1'
implementation 'com.google.android.gms:play-services-auth:20.5.0'
implementation 'androidx.viewpager2:viewpager2:1.1.0-beta01'

implementation 'com.github.bumptech.glide:glide:4.15.1'
kapt 'com.github.bumptech.glide:compiler:4.15.1'
implementation 'com.google.android.gms:play-services-auth:20.5.0'
implementation 'com.google.android.gms:play-services-location:21.0.1'

testImplementation 'org.junit.jupiter:junit-jupiter:5.8.1'
testImplementation 'org.mockito:mockito-core:3.12.4'
testImplementation 'org.mockito:mockito-inline:2.13.0'
testImplementation 'io.mockk:mockk:1.12.0'
androidTestImplementation 'io.mockk:mockk-android:1.12.0'

androidTestImplementation 'androidx.arch.core:core-testing:2.2.0'
implementation 'com.google.android.gms:play-services-maps:18.1.0'
implementation 'com.google.android.material:material:1.8.0'
implementation 'com.google.code.gson:gson:2.10.1'
implementation 'com.google.firebase:firebase-auth-ktx'
implementation 'com.google.firebase:firebase-database-ktx:20.2.0'
implementation 'com.google.firebase:firebase-storage-ktx:20.1.0'
implementation "androidx.lifecycle:lifecycle-common-java8:2.6.1"
implementation platform('com.google.firebase:firebase-bom:31.2.3') // Firebase BOM

testImplementation 'io.mockk:mockk:1.13.5'
androidTestImplementation 'io.mockk:mockk-android:1.13.5'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
testImplementation 'org.junit.jupiter:junit-jupiter:5.9.2'
testImplementation 'org.mockito:mockito-core:5.3.0'
testImplementation 'org.mockito:mockito-inline:5.2.0'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.6.4'
testImplementation "org.jetbrains.kotlin:kotlin-test:1.8.20"
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
androidTestImplementation 'androidx.test:runner:1.5.2'
androidTestImplementation 'androidx.test.espresso:espresso-intents:3.5.1'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
debugImplementation "androidx.test:monitor:1.6.1"
androidTestImplementation 'androidx.test:rules:1.5.0'
androidTestImplementation 'androidx.test:runner:1.5.2'
androidTestImplementation 'androidx.test.uiautomator:uiautomator:2.3.0-alpha02'
androidTestImplementation 'androidx.test.espresso:espresso-intents:3.5.1'
androidTestImplementation 'androidx.navigation:navigation-testing:2.5.3'
androidTestImplementation 'androidx.arch.core:core-testing:2.2.0'

debugImplementation "androidx.test:monitor:1.6.1"
debugImplementation "androidx.fragment:fragment-testing:1.5.6"

implementation 'com.google.code.gson:gson:2.9.0'
testImplementation "org.jetbrains.kotlin:kotlin-test:1.6.10"
}


tasks.withType(Test) {
jacoco.includeNoLocationClasses = true
jacoco.excludes = ['jdk.internal.*', '**/databinding/*']
Expand All @@ -131,12 +121,12 @@ task jacocoTestReport(type: JacocoReport, dependsOn: ['testDebugUnitTest', 'crea


def fileFilter = [
'**/R.class',
'**/R$*.class',
'**/BuildConfig.*',
'**/Manifest*.*',
'**/*Test*.*',
'android/**/*.*',
'**/R.class',
'**/R$*.class',
'**/BuildConfig.*',
'**/Manifest*.*',
'**/*Test*.*',
'android/**/*.*',
]
def debugTree = fileTree(dir: "$project.buildDir/tmp/kotlin-classes/debug", excludes: fileFilter)
def mainSrc = "$project.projectDir/src/main/java"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,15 @@ import androidx.test.ext.junit.rules.ActivityScenarioRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry.getInstrumentation
import androidx.test.uiautomator.UiDevice
import com.github.factotum_sdp.factotum.placeholder.ContactsList
import com.github.factotum_sdp.factotum.placeholder.UsersPlaceHolder
import com.github.factotum_sdp.factotum.ui.login.LoginFragmentTest
import com.github.factotum_sdp.factotum.utils.ContactsUtils
import com.github.factotum_sdp.factotum.utils.GeneralUtils.Companion.getAuth
import com.github.factotum_sdp.factotum.utils.GeneralUtils.Companion.getDatabase
import com.github.factotum_sdp.factotum.utils.GeneralUtils.Companion.initFirebase
import com.google.firebase.auth.FirebaseAuth
import com.google.firebase.auth.ktx.auth
import com.google.firebase.database.ktx.database
import com.google.firebase.ktx.Firebase
import kotlinx.coroutines.runBlocking
import org.hamcrest.Matchers
import org.junit.AfterClass
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.BeforeClass
Expand All @@ -48,18 +47,13 @@ class MainActivityTest {
@BeforeClass
@JvmStatic
fun setUpDatabase() {
val database = Firebase.database
val auth = Firebase.auth
database.useEmulator("10.0.2.2", 9000)
auth.useEmulator("10.0.2.2", 9099)
MainActivity.setDatabase(database)
MainActivity.setAuth(auth)
ContactsList.init(database)
initFirebase()

runBlocking {
ContactsList.populateDatabase()
ContactsUtils.populateDatabase()
}

UsersPlaceHolder.init(database, auth)
UsersPlaceHolder.init(getDatabase(), getAuth())
runBlocking {
UsersPlaceHolder.addUserToDb(UsersPlaceHolder.USER_BOSS)
}
Expand All @@ -79,14 +73,14 @@ class MainActivityTest {
UsersPlaceHolder.addAuthUser(UsersPlaceHolder.USER_CLIENT)
}
}

/**
@AfterClass
@JvmStatic
fun stopAuthEmulator() {
val auth = Firebase.auth
auth.signOut()
MainActivity.setAuth(auth)
}
val auth = getAuth()
auth.signOut()
MainActivity.setAuth(auth)
} **/
}

//========================================================================================
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ import java.util.concurrent.CountDownLatch
@RunWith(AndroidJUnit4::class)
class LocationTest {
@Test
fun rightLocationCreates(){
fun rightLocationCreates() {
val addressName = "Route Cantonale 15, 1015 Lausanne"
val location = Location(addressName, getApplicationContext())
val geocoder = Geocoder(getApplicationContext())
var result : Address? = null
val geocoder = Geocoder(getApplicationContext())
var result: Address? = null
val latch = CountDownLatch(1)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
geocoder.getFromLocationName(addressName, 1) { addresses ->
result = if(addresses.size != 0) addresses[0] else null
result = if (addresses.size != 0) addresses[0] else null
latch.countDown()
}
latch.await()
Expand All @@ -37,17 +37,17 @@ class LocationTest {
}

@Test
fun wrongLocationCreatesNull(){
fun wrongLocationCreatesNull() {
val addressName = "dfjsdk"
val location = Location(addressName, getApplicationContext())
assertEquals(location.address, null)
assertEquals(location.addressName, null)
}

@Test
fun searchQueryAddsToCache(){
fun searchQueryAddsToCache() {
val query = "Lausanne"
val context : Context = getApplicationContext()
val context: Context = getApplicationContext()
val locationCache = Location.createAndStore(query, context)
val location = Location(query, context)
val cacheFile = File(context.cacheDir, Location.CACHE_FILE_NAME)
Expand All @@ -56,21 +56,25 @@ class LocationTest {
var containsLat = false
var containsLng = false
cacheFile.forEachLine { line ->
if (line.contains(location.addressName.toString())){
containsAddress = true}
if (line.contains(location.address!!.latitude.toString())){
containsLat = true}
if (line.contains(location.address!!.longitude.toString())){
containsLng = true}
if (line.contains(location.addressName.toString())) {
containsAddress = true
}
if (line.contains(location.address!!.latitude.toString())) {
containsLat = true
}
if (line.contains(location.address!!.longitude.toString())) {
containsLng = true
}
}
assertTrue(containsAddress)
assertTrue(containsLat)
assertTrue(containsLng)
}

@Test
fun searchQueryDoNotAddIfNull(){
fun searchQueryDoNotAddIfNull() {
val query = "wrong_query"
val context : Context = getApplicationContext()
val context: Context = getApplicationContext()
val cacheFile = File(context.cacheDir, Location.CACHE_FILE_NAME)
val cacheSizeBefore = cacheFile.length()
val locationCache = Location.createAndStore(query, context)
Expand All @@ -79,9 +83,9 @@ class LocationTest {
}

@Test
fun searchQueryDoNotDuplicate(){
fun searchQueryDoNotDuplicate() {
val query = "Lausanne"
val context : Context = getApplicationContext()
val context: Context = getApplicationContext()
val cacheFile = File(context.cacheDir, Location.CACHE_FILE_NAME)
Location.createAndStore(query, context)
val cacheSizeBefore = cacheFile.length()
Expand All @@ -91,7 +95,7 @@ class LocationTest {
}

@Test
fun rightQueryReturnsMultiplesResults(){
fun rightQueryReturnsMultiplesResults() {
val query = "rue de Genève"
val result = Location.geocoderQuery(query, getApplicationContext())
assertTrue(result!!.size > 1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import org.junit.runner.RunWith
@RunWith(AndroidJUnit4::class)
class RouteTest {
@Test
fun routeRightlyCreatedWithDouble(){
fun routeRightlyCreatedWithDouble() {
val srcLat = 46.5190999750367
val srcLng = 6.566757598226489
val dstLat = 46.52072048076863
Expand All @@ -25,7 +25,7 @@ class RouteTest {
assertEquals(dstLng, route.dst.longitude)
}

fun routeRightlyUpdates(){
fun routeRightlyUpdates() {
val srcLat = 46.5190999750367
val srcLng = 6.566757598226489
val dstLat = 46.52072048076863
Expand All @@ -38,7 +38,7 @@ class RouteTest {
}

@Test
fun routeRightlyCreatedWithLatLon(){
fun routeRightlyCreatedWithLatLon() {
val srcLat = 46.5190999750367
val srcLng = 6.566757598226489
val dstLat = 46.52072048076863
Expand All @@ -53,24 +53,25 @@ class RouteTest {
}

@Test
fun routePrintsRightCoordinates(){
fun routePrintsRightCoordinates() {
val srcLat = 46.5190999750367
val srcLng = 6.566757598226489
val dstLat = 46.52072048076863
val dstLng = 6.567838722207785
val route = Route(srcLat, srcLng, dstLat, dstLng)
val str = "The route starts at coordinates ($srcLat, $srcLng) and finishes at coordinates ($dstLat, $dstLng)"
val str =
"The route starts at coordinates ($srcLat, $srcLng) and finishes at coordinates ($dstLat, $dstLng)"
assertEquals(str, route.toString())
}

@Test
fun routeViewInitializesCorrectly(){
fun routeViewInitializesCorrectly() {
val mapView = MapsViewModel()
assertEquals(0, mapView.routesState.value!!.size)
}

@Test
fun routeViewAdd(){
fun routeViewAdd() {
val mapView = MapsViewModel()
val route = Route(10.0, 10.0, 10.0, 10.0)
val route2 = Route(10.0, 10.0, 10.0, 10.0)
Expand All @@ -82,7 +83,7 @@ class RouteTest {
}

@Test
fun routeViewAddAll(){
fun routeViewAddAll() {
val mapView = MapsViewModel()
val route = Route(10.0, 10.0, 10.0, 10.0)
val route2 = Route(10.0, 10.0, 10.0, 10.0)
Expand All @@ -94,16 +95,17 @@ class RouteTest {

@get:Rule
val rule = InstantTaskExecutorRule()

@Test
fun routeViewSetsRun(){
fun routeViewSetsRun() {
val mapView = MapsViewModel()
val route = Route(10.0, 10.0, 10.0, 10.0)
mapView.setRunRoute(route)
assertEquals(route, mapView.runRouteState.value)
}

@Test
fun routeViewDeletes(){
fun routeViewDeletes() {
val mapView = MapsViewModel()
val route = Route(10.0, 10.0, 10.0, 10.0)
mapView.addRoute(route)
Expand All @@ -112,9 +114,9 @@ class RouteTest {
}

@Test
fun routeViewSetsLocation(){
fun routeViewSetsLocation() {
val mapView = MapsViewModel()
val query = "Lausanne"
val query = "Lausanne"
val location = Location(query, getApplicationContext())
mapView.setLocation(location)
assertEquals(location.address!!.latitude, mapView.location.value!!.address!!.latitude)
Expand Down
Loading

0 comments on commit 53048fb

Please sign in to comment.