Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Delta Between Two Patch Sets: adblockplussbrowser/src/test/java/org/adblockplus/sbrowser/contentblocker/engine/UtilsTest.kt

Issue 29603697: Issue 5931 - Create tests for util package (Closed)
Left Patch Set: Created Nov. 10, 2017, 2:23 p.m.
Right Patch Set: Removed default srcDir Created Nov. 30, 2017, 8:39 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
LEFTRIGHT
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-present eyeo GmbH 3 * Copyright (C) 2006-present eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 12 matching lines...) Expand all
23 import org.adblockplus.sbrowser.contentblocker.util.SharedPrefsUtils 23 import org.adblockplus.sbrowser.contentblocker.util.SharedPrefsUtils
24 import org.adblockplus.sbrowser.contentblocker.util.SubscriptionUtils 24 import org.adblockplus.sbrowser.contentblocker.util.SubscriptionUtils
25 import org.junit.Assert.assertEquals 25 import org.junit.Assert.assertEquals
26 import org.junit.Assert.assertNotEquals 26 import org.junit.Assert.assertNotEquals
27 import org.junit.Before 27 import org.junit.Before
28 import org.junit.Test 28 import org.junit.Test
29 import org.junit.runner.RunWith 29 import org.junit.runner.RunWith
30 import org.mockito.Mockito.mock 30 import org.mockito.Mockito.mock
31 import org.robolectric.RobolectricTestRunner 31 import org.robolectric.RobolectricTestRunner
32 import org.robolectric.RuntimeEnvironment 32 import org.robolectric.RuntimeEnvironment
33 import java.util.* 33 import java.util.Locale
diegocarloslima 2017/11/13 21:10:13 I don't really like using wildcards on imports
jens 2017/11/14 10:57:58 Acknowledged.
34 34
35 @RunWith(RobolectricTestRunner::class) 35 @RunWith(RobolectricTestRunner::class)
36 class UtilsTest 36 class UtilsTest
37 { 37 {
38 38 private lateinit var mockedDefaultSubs: DefaultSubscriptions
39 private var mockedDefaultSubs: DefaultSubscriptions? = null 39 private lateinit var context: Context
40 private var context: Context? = null
anton 2017/11/14 06:04:09 it would be better to have it marked with `lateini
jens 2017/11/14 10:57:59 Acknowledged.
jens 2017/11/14 11:03:54 But lateinit can only be used on var. So I will ch
41 private val EASYLIST_GERMANY_COMPLETE_URL = 40 private val EASYLIST_GERMANY_COMPLETE_URL =
42 "https://easylist-downloads.adblockplus.org/easylistgermany+easylist .txt" 41 "https://easylist-downloads.adblockplus.org/easylistgermany+easylist .txt"
43 42
44 @Before 43 @Before
45 fun setup() 44 fun setup()
46 { 45 {
47 context = RuntimeEnvironment.application 46 context = RuntimeEnvironment.application
48 mockedDefaultSubs = mock(DefaultSubscriptions::class.java) 47 mockedDefaultSubs = mock(DefaultSubscriptions::class.java)
49 RuntimeEnvironment.application.resources 48 RuntimeEnvironment.application.resources
50 .openRawResource(R.raw.subscriptions).use({ subscriptionsXml -> mockedDefaultSubs = 49 .openRawResource(R.raw.subscriptions).use{ subscriptionsXml -> m ockedDefaultSubs =
diegocarloslima 2017/11/13 21:10:13 Is this parenthesis in .use( really necessary?
jens 2017/11/14 10:57:58 No it's not. Good catch.
51 DefaultSubscriptions.fromStream(subscriptionsXml) }) 50 DefaultSubscriptions.fromStream(subscriptionsXml) }
52 } 51 }
53 52
54 @Test 53 @Test
55 fun subscriptionUtilsChooseDefaultSubscriptionForEmptyList() 54 fun subscriptionUtilsChooseDefaultSubscriptionForEmptyList()
56 { 55 {
57 assertEquals(SubscriptionUtils.chooseDefaultSubscriptionUrl( 56 assertEquals(SubscriptionUtils.chooseDefaultSubscriptionUrl(
58 emptyList<DefaultSubscriptionInfo>()), Engine.EASYLIST_URL) 57 emptyList<DefaultSubscriptionInfo>()), Engine.EASYLIST_URL)
59 } 58 }
60 59
61 @Test 60 @Test
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 @Test 154 @Test
156 fun sharedPrefsUtilsPutAndGetDifferentStringSet() 155 fun sharedPrefsUtilsPutAndGetDifferentStringSet()
157 { 156 {
158 val testStringSet = setOf("Hello", "World") 157 val testStringSet = setOf("Hello", "World")
159 SharedPrefsUtils.putStringSet(context, R.string.key_previous_version_cod e, testStringSet) 158 SharedPrefsUtils.putStringSet(context, R.string.key_previous_version_cod e, testStringSet)
160 val unequalStringSet = SharedPrefsUtils.getStringSet(context, 159 val unequalStringSet = SharedPrefsUtils.getStringSet(context,
161 R.string.key_aa_info_shown, setOf("Hello", "World", "!")) 160 R.string.key_aa_info_shown, setOf("Hello", "World", "!"))
162 assertNotEquals(testStringSet, unequalStringSet) 161 assertNotEquals(testStringSet, unequalStringSet)
163 } 162 }
164 } 163 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld