forked from duckduckgo/Android
-
Notifications
You must be signed in to change notification settings - Fork 0
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
30 changed files
with
1,385 additions
and
123 deletions.
There are no files selected for viewing
584 changes: 584 additions & 0 deletions
584
app/schemas/com.duckduckgo.app.global.db.AppDatabase/15.json
Large diffs are not rendered by default.
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
83 changes: 83 additions & 0 deletions
83
app/src/androidTest/java/com/duckduckgo/app/global/exception/RootExceptionFinderTest.kt
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,83 @@ | ||
/* | ||
* Copyright (c) 2019 DuckDuckGo | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.duckduckgo.app.global.exception | ||
|
||
import org.junit.Assert.* | ||
import org.junit.Before | ||
import org.junit.Test | ||
|
||
class RootExceptionFinderTest { | ||
|
||
private lateinit var testee: RootExceptionFinder | ||
private val actualRoot = IllegalArgumentException("0") | ||
|
||
@Before | ||
fun setup() { | ||
testee = RootExceptionFinder() | ||
} | ||
|
||
@Test | ||
fun whenExceptionIsNullThenNullIsReturned() { | ||
val calculatedRoot = testee.findRootException(null) | ||
assertNull(calculatedRoot) | ||
} | ||
|
||
@Test | ||
fun whenExceptionHasNoAdditionalCausesItIsIdentifiedAsRoot() { | ||
val calculatedRoot = testee.findRootException(actualRoot) | ||
assertRootFound(calculatedRoot) | ||
} | ||
|
||
@Test | ||
fun whenSingleCauseThenCorrectRootIsFound() { | ||
val nestedException = buildNestedException(actualRoot, 1) | ||
val calculatedRoot = testee.findRootException(nestedException) | ||
assertRootFound(calculatedRoot) | ||
} | ||
|
||
@Test | ||
fun whenManyCausesThenCorrectRootIsFound() { | ||
val nestedException = buildNestedException(actualRoot, 15) | ||
val calculatedRoot = testee.findRootException(nestedException) | ||
assertRootFound(calculatedRoot) | ||
} | ||
|
||
@Test | ||
fun whenNestedCausesAreTooDeepThenReturnsExceptionFoundAtThreshold() { | ||
val nestedException = buildNestedException(actualRoot, 100) | ||
val calculatedRoot = testee.findRootException(nestedException) | ||
assertRootNotNull(calculatedRoot) | ||
assertEquals("80", calculatedRoot?.message) | ||
} | ||
|
||
private fun assertRootFound(calculatedRoot: Throwable?) { | ||
assertRootNotNull(calculatedRoot) | ||
assertEquals("Wrong cause identified", calculatedRoot?.message, actualRoot.message) | ||
} | ||
|
||
private fun assertRootNotNull(calculatedRoot: Throwable?) { | ||
assertNotNull("Root was null; not found correctly", calculatedRoot) | ||
} | ||
|
||
private fun buildNestedException(root: Throwable, depthRequired: Int): Throwable { | ||
var nested = root | ||
for (i in 0 until depthRequired) { | ||
nested = IllegalArgumentException((i + 1).toString(), nested) | ||
} | ||
return nested | ||
} | ||
} |
118 changes: 118 additions & 0 deletions
118
app/src/androidTest/java/com/duckduckgo/app/global/exception/UncaughtExceptionDaoTest.kt
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,118 @@ | ||
/* | ||
* Copyright (c) 2019 DuckDuckGo | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.duckduckgo.app.global.exception | ||
|
||
import androidx.arch.core.executor.testing.InstantTaskExecutorRule | ||
import androidx.room.Room | ||
import androidx.test.platform.app.InstrumentationRegistry | ||
import com.duckduckgo.app.CoroutineTestRule | ||
import com.duckduckgo.app.global.db.AppDatabase | ||
import com.duckduckgo.app.global.exception.UncaughtExceptionSource.* | ||
import kotlinx.coroutines.ExperimentalCoroutinesApi | ||
import org.junit.After | ||
import org.junit.Assert.assertEquals | ||
import org.junit.Before | ||
import org.junit.Rule | ||
import org.junit.Test | ||
|
||
class UncaughtExceptionDaoTest { | ||
|
||
@get:Rule | ||
@Suppress("unused") | ||
var instantTaskExecutorRule = InstantTaskExecutorRule() | ||
|
||
@ExperimentalCoroutinesApi | ||
@get:Rule | ||
var coroutinesTestRule = CoroutineTestRule() | ||
|
||
private lateinit var db: AppDatabase | ||
private lateinit var dao: UncaughtExceptionDao | ||
|
||
@Before | ||
fun before() { | ||
db = Room.inMemoryDatabaseBuilder(InstrumentationRegistry.getInstrumentation().targetContext, AppDatabase::class.java) | ||
.allowMainThreadQueries() | ||
.build() | ||
dao = db.uncaughtExceptionDao() | ||
} | ||
|
||
@After | ||
fun after() { | ||
db.close() | ||
} | ||
|
||
@Test | ||
fun whenInitialisedThereAre0ExceptionsRecorded() { | ||
assertEquals(0, dao.count()) | ||
} | ||
|
||
@Test | ||
fun whenNewExceptionAddedThenCountIsIncreased() { | ||
dao.add(anUncaughtExceptionEntity()) | ||
assertEquals(1, dao.count()) | ||
} | ||
|
||
@Test | ||
fun whenSeveralExceptionsAddedAndOneDeletedThenNotAllEntriesDeleted() { | ||
dao.add(anUncaughtExceptionEntity(id = 1)) | ||
dao.add(anUncaughtExceptionEntity(id = 2)) | ||
dao.add(anUncaughtExceptionEntity(id = 3)) | ||
dao.delete(2) | ||
assertEquals(2, dao.count()) | ||
} | ||
|
||
@Test | ||
fun whenSeveralExceptionExistAndOneDeletedThenCorrectEntryIsRemoved() { | ||
val exception1 = UncaughtExceptionEntity(id = 1, exceptionSource = GLOBAL, message = "foo1") | ||
val exception2 = UncaughtExceptionEntity(id = 2, exceptionSource = ON_PROGRESS_CHANGED, message = "foo2") | ||
val exception3 = UncaughtExceptionEntity(id = 3, exceptionSource = ON_PAGE_STARTED, message = "foo3") | ||
dao.add(exception1) | ||
dao.add(exception2) | ||
dao.add(exception3) | ||
|
||
dao.delete(2) | ||
|
||
val list = dao.all() | ||
list.first().apply { | ||
assertEquals(1, id) | ||
assertEquals(exception1.exceptionSource, exceptionSource) | ||
assertEquals(exception1.message, message) | ||
} | ||
|
||
list.last().apply { | ||
assertEquals(3, id) | ||
assertEquals(exception3.exceptionSource, exceptionSource) | ||
assertEquals(exception3.message, message) | ||
} | ||
} | ||
|
||
@Test | ||
fun whenExceptionRetrievedFromDatabaseThenAllDetailsRestored() { | ||
val exception = UncaughtExceptionEntity(id = 1, exceptionSource = GLOBAL, message = "foo") | ||
dao.add(exception) | ||
val list = dao.all() | ||
assertEquals(1, list.size) | ||
list.first().apply { | ||
assertEquals(1, id) | ||
assertEquals(exception.exceptionSource, exceptionSource) | ||
assertEquals(exception.message, message) | ||
} | ||
} | ||
|
||
private fun anUncaughtExceptionEntity(id: Long? = null) = | ||
UncaughtExceptionEntity(id = id ?: 0, exceptionSource = GLOBAL, message = "foo") | ||
} |
34 changes: 34 additions & 0 deletions
34
app/src/androidTest/java/com/duckduckgo/app/statistics/pixels/PixelNameTest.kt
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,34 @@ | ||
/* | ||
* Copyright (c) 2019 DuckDuckGo | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.duckduckgo.app.statistics.pixels | ||
|
||
import org.junit.Assert.fail | ||
import org.junit.Test | ||
|
||
class PixelNameTest { | ||
|
||
@Test | ||
fun verifyNoDuplicatePixelNames() { | ||
val existingNames = mutableSetOf<String>() | ||
Pixel.PixelName.values().forEach { | ||
if (!existingNames.add(it.pixelName)) { | ||
fail("Duplicate pixel name found: ${it.pixelName}") | ||
} | ||
} | ||
} | ||
|
||
} |
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.