1
+ package fr.free.nrw.commons
2
+
3
+ import android.content.Context
4
+ import android.net.Uri
5
+ import android.view.Menu
6
+ import android.view.MenuItem
7
+ import org.junit.Assert
8
+ import org.junit.Before
9
+ import org.junit.Test
10
+ import org.junit.runner.RunWith
11
+ import org.mockito.Mock
12
+ import org.mockito.MockitoAnnotations
13
+ import org.robolectric.Robolectric
14
+ import org.robolectric.RobolectricTestRunner
15
+ import org.robolectric.RuntimeEnvironment
16
+ import org.robolectric.Shadows
17
+ import org.robolectric.annotation.Config
18
+ import org.robolectric.fakes.RoboMenu
19
+ import org.robolectric.fakes.RoboMenuItem
20
+ import org.robolectric.shadows.ShadowActivity
21
+
22
+
23
+ @RunWith(RobolectricTestRunner ::class )
24
+ @Config(sdk = [21 ], application = TestCommonsApplication ::class )
25
+ class AboutActivityUnitTests {
26
+
27
+ private lateinit var activity: AboutActivity
28
+
29
+ @Mock
30
+ private lateinit var context: Context
31
+
32
+ @Before
33
+ fun setUp () {
34
+ MockitoAnnotations .initMocks(this )
35
+
36
+ activity = Robolectric .buildActivity(AboutActivity ::class .java).get()
37
+
38
+ context = RuntimeEnvironment .application.applicationContext
39
+ }
40
+
41
+ @Test
42
+ @Throws(Exception ::class )
43
+ fun checkActivityNotNull () {
44
+ Assert .assertNotNull(activity)
45
+ }
46
+
47
+ @Test
48
+ @Throws(Exception ::class )
49
+ fun testLaunchFacebook () {
50
+ activity.launchFacebook(null )
51
+ val shadowActivity: ShadowActivity = Shadows .shadowOf(activity)
52
+ val startedIntent = shadowActivity.nextStartedActivity
53
+ Assert .assertEquals(startedIntent.action, " android.intent.action.VIEW" )
54
+ Assert .assertEquals(startedIntent.`package`, " com.facebook.katana" )
55
+ Assert .assertEquals(startedIntent.`data`, Uri .parse(" fb://page/1921335171459985" ))
56
+ }
57
+
58
+ @Test
59
+ @Throws(Exception ::class )
60
+ fun testLaunchGithub () {
61
+ activity.launchGithub(null )
62
+ }
63
+
64
+ @Test
65
+ @Throws(Exception ::class )
66
+ fun testLaunchWebsite () {
67
+ activity.launchWebsite(null )
68
+ }
69
+
70
+ @Test
71
+ @Throws(Exception ::class )
72
+ fun testLaunchRatings () {
73
+ activity.launchRatings(null )
74
+ }
75
+
76
+ @Test
77
+ @Throws(Exception ::class )
78
+ fun testLaunchCredits () {
79
+ activity.launchCredits(null )
80
+ }
81
+
82
+ @Test
83
+ @Throws(Exception ::class )
84
+ fun testLaunchPrivacyPolicy () {
85
+ activity.launchPrivacyPolicy(null )
86
+ }
87
+
88
+ @Test
89
+ @Throws(Exception ::class )
90
+ fun testLaunchFrequentlyAskedQuestions () {
91
+ activity.launchFrequentlyAskedQuesions(null )
92
+ }
93
+
94
+ @Test
95
+ @Throws(Exception ::class )
96
+ fun testOnCreateOptionsMenu () {
97
+ val menu: Menu = RoboMenu (context)
98
+ activity.onCreateOptionsMenu(menu)
99
+ }
100
+
101
+ @Test
102
+ @Throws(Exception ::class )
103
+ fun testOnOptionsItemSelected () {
104
+ val menuItem: MenuItem = RoboMenuItem (R .menu.menu_about)
105
+ activity.onOptionsItemSelected(menuItem)
106
+ val shadowActivity = Shadows .shadowOf(activity)
107
+ shadowActivity.clickMenuItem(R .id.share_app_icon)
108
+ }
109
+
110
+ }
0 commit comments