1
+ package fr.free.nrw.commons.nearby
2
+
3
+ import android.net.Uri
4
+ import fr.free.nrw.commons.TestCommonsApplication
5
+ import fr.free.nrw.commons.contributions.ContributionController
6
+ import fr.free.nrw.commons.kvstore.JsonKvStore
7
+ import fr.free.nrw.commons.nearby.fragments.CommonPlaceClickActions
8
+ import fr.free.nrw.commons.profile.ProfileActivity
9
+ import org.junit.Assert
10
+ import org.junit.Before
11
+ import org.junit.Test
12
+ import org.junit.runner.RunWith
13
+ import org.mockito.Mock
14
+ import org.mockito.MockitoAnnotations
15
+ import org.robolectric.Robolectric
16
+ import org.robolectric.RobolectricTestRunner
17
+ import org.robolectric.annotation.Config
18
+ import org.robolectric.annotation.LooperMode
19
+ import java.lang.reflect.Method
20
+
21
+ @RunWith(RobolectricTestRunner ::class )
22
+ @Config(sdk = [21 ], application = TestCommonsApplication ::class )
23
+ @LooperMode(LooperMode .Mode .PAUSED )
24
+ class CommonPlaceClickActionsUnitTest {
25
+
26
+ private lateinit var commonPlaceClickActions: CommonPlaceClickActions
27
+
28
+ @Mock
29
+ private lateinit var store: JsonKvStore
30
+
31
+ @Mock
32
+ private lateinit var contributionController: ContributionController
33
+
34
+ @Mock
35
+ private lateinit var place: Place
36
+
37
+ @Mock
38
+ private lateinit var uri: Uri
39
+
40
+ @Before
41
+ fun setUp () {
42
+ MockitoAnnotations .initMocks(this )
43
+ val activity = Robolectric .buildActivity(ProfileActivity ::class .java).create().get()
44
+ commonPlaceClickActions = CommonPlaceClickActions (store, activity, contributionController)
45
+ }
46
+
47
+ @Test
48
+ fun testNonNull () {
49
+ Assert .assertNotNull(commonPlaceClickActions)
50
+ }
51
+
52
+ @Test
53
+ fun testFunctionDeclaration () {
54
+ Assert .assertNotNull(commonPlaceClickActions.onCameraClicked())
55
+ Assert .assertNotNull(commonPlaceClickActions.onGalleryClicked())
56
+ Assert .assertNotNull(commonPlaceClickActions.onOverflowClicked())
57
+ Assert .assertNotNull(commonPlaceClickActions.onDirectionsClicked())
58
+ }
59
+
60
+ @Test
61
+ @Throws(Exception ::class )
62
+ fun testStoreSharedPrefs () {
63
+ val method: Method = CommonPlaceClickActions ::class .java.getDeclaredMethod(
64
+ " storeSharedPrefs" ,
65
+ Place ::class .java
66
+ )
67
+ method.isAccessible = true
68
+ method.invoke(commonPlaceClickActions, place)
69
+ }
70
+
71
+ @Test
72
+ @Throws(Exception ::class )
73
+ fun testOpenWebView () {
74
+ val method: Method = CommonPlaceClickActions ::class .java.getDeclaredMethod(
75
+ " openWebView" ,
76
+ Uri ::class .java
77
+ )
78
+ method.isAccessible = true
79
+ Assert .assertEquals(method.invoke(commonPlaceClickActions, uri), true )
80
+ }
81
+
82
+ @Test
83
+ @Throws(Exception ::class )
84
+ fun testShowLoginDialog () {
85
+ val method: Method = CommonPlaceClickActions ::class .java.getDeclaredMethod(
86
+ " showLoginDialog"
87
+ )
88
+ method.isAccessible = true
89
+ method.invoke(commonPlaceClickActions)
90
+ }
91
+
92
+ @Test
93
+ @Throws(Exception ::class )
94
+ fun testSetPositiveButton () {
95
+ val method: Method = CommonPlaceClickActions ::class .java.getDeclaredMethod(
96
+ " setPositiveButton"
97
+ )
98
+ method.isAccessible = true
99
+ method.invoke(commonPlaceClickActions)
100
+ }
101
+
102
+ }
0 commit comments