Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
AloqaIM-Android
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
AloqaIM-Android
Commits
68755814
Commit
68755814
authored
Nov 14, 2017
by
Leonardo Aramaki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix broken notifications
parent
839f60b0
Changes
6
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
279 additions
and
1096 deletions
+279
-1096
build.gradle
app/build.gradle
+4
-1
RocketChatCache.java
app/src/main/java/chat/rocket/android/RocketChatCache.java
+5
-1
PushManager.kt
app/src/main/java/chat/rocket/android/push/PushManager.kt
+118
-66
PushNotificationHandler.java
...ava/chat/rocket/android/push/PushNotificationHandler.java
+0
-986
RocketChatCacheTest.kt
...rc/test/kotlin/chat.rocket.android/RocketChatCacheTest.kt
+0
-42
PushManagerTest.kt
...c/test/kotlin/chat.rocket.android/push/PushManagerTest.kt
+152
-0
No files found.
app/build.gradle
View file @
68755814
...
...
@@ -150,8 +150,11 @@ dependencies {
compile
'com.github.matrixxun:MaterialBadgeTextView:c5a27e8243'
compile
'com.github.chrisbanes:PhotoView:2.0.0'
testCompile
'junit:junit:4.12'
testCompile
"org.mockito:mockito-core:2.8.9"
testCompile
'org.robolectric:robolectric:3.3'
testCompile
"org.jetbrains.kotlin:kotlin-test:$rootProject.ext.kotlinVersion"
testCompile
"org.jetbrains.kotlin:kotlin-test-junit:$rootProject.ext.kotlinVersion"
testCompile
"com.nhaarman:mockito-kotlin:1.1.0"
testCompile
'org.amshove.kluent:kluent:1.14'
testCompile
"org.jetbrains.kotlin:kotlin-reflect:$rootProject.ext.kotlinVersion"
}
apply
plugin:
'com.google.gms.google-services'
app/src/main/java/chat/rocket/android/RocketChatCache.java
View file @
68755814
...
...
@@ -17,6 +17,7 @@ import java.util.UUID;
import
chat.rocket.android.helper.Logger
;
import
chat.rocket.android.helper.TextUtils
;
import
chat.rocket.android.log.RCLog
;
import
chat.rocket.android.push.PushManager
;
import
chat.rocket.core.utils.Pair
;
import
io.reactivex.BackpressureStrategy
;
import
io.reactivex.Flowable
;
...
...
@@ -104,9 +105,12 @@ public class RocketChatCache {
}
}
public
@N
onNull
String
getSiteUrlFor
(
String
hostname
)
{
public
@N
ullable
String
getSiteUrlFor
(
String
hostname
)
{
try
{
String
selectedServerHostname
=
getSelectedServerHostname
();
if
(
getLoginHostnamesJson
()
==
null
||
getLoginHostnamesJson
().
isEmpty
())
{
return
null
;
}
return
new
JSONObject
(
getLoginHostnamesJson
())
.
optString
(
hostname
,
selectedServerHostname
);
}
catch
(
JSONException
e
)
{
...
...
app/src/main/java/chat/rocket/android/push/PushManager.kt
View file @
68755814
This diff is collapsed.
Click to expand it.
app/src/main/java/chat/rocket/android/push/PushNotificationHandler.java
deleted
100644 → 0
View file @
839f60b0
This diff is collapsed.
Click to expand it.
app/src/test/kotlin/chat.rocket.android/RocketChatCacheTest.kt
deleted
100644 → 0
View file @
839f60b0
package
chat.rocket.android;
import
android.content.Context
import
chat.rocket.core.utils.Pair
import
org.hamcrest.CoreMatchers.equalTo
import
org.json.JSONObject
import
org.junit.Assert.assertThat
import
org.junit.Before
import
org.junit.Test
import
org.junit.runner.RunWith
import
org.mockito.Mockito.*
import
org.mockito.junit.MockitoJUnitRunner
@RunWith
(
MockitoJUnitRunner
::
class
)
class
RocketChatCacheTest
{
lateinit
var
cache
:
RocketChatCache
@Before
fun
setup
()
{
val
mockedContext
=
mock
(
Context
::
class
.
java
)
val
mockAppContext
=
mock
(
Context
::
class
.
java
)
`when`
(
mockedContext
.
applicationContext
).
thenReturn
(
mockAppContext
)
cache
=
spy
(
RocketChatCache
(
mockedContext
))
}
@Test
fun
getServerList_ShouldReturnHostnameList
()
{
val
hostnameList
=
JSONObject
()
.
put
(
"http://open.rocket.chat"
,
"images/logo/logo.png"
)
.
put
(
"http://192.168.0.6:3000"
,
"images/icon.svg"
)
.
toString
()
doReturn
(
hostnameList
).
`when`
(
cache
).
getString
(
"KEY_HOSTNAME_LIST"
,
null
)
val
expectedServerList
=
mutableListOf
(
Pair
(
"http://192.168.0.6:3000"
,
"http://192.168.0.6:3000/images/icon.svg"
),
Pair
(
"http://open.rocket.chat"
,
"http://open.rocket.chat/images/logo/logo.png"
))
val
serverList
=
cache
.
serverList
assertThat
(
serverList
,
equalTo
(
expectedServerList
))
}
}
\ No newline at end of file
app/src/test/kotlin/chat.rocket.android/push/PushManagerTest.kt
0 → 100644
View file @
68755814
package
chat.rocket.android.push
import
android.app.Application
import
android.content.Context
import
android.content.res.Resources
import
android.os.Bundle
import
chat.rocket.android.BuildConfig
import
chat.rocket.android.R
import
chat.rocket.android.push.PushManager.PushMessage
import
com.nhaarman.mockito_kotlin.*
import
org.amshove.kluent.`should
equal
`
import
org.junit.Before
import
org.junit.Test
import
org.junit.runner.RunWith
import
org.mockito.ArgumentMatchers.anyString
import
org.mockito.MockitoAnnotations
import
org.robolectric.RobolectricTestRunner
import
org.robolectric.RuntimeEnvironment
import
org.robolectric.annotation.Config
import
kotlin.test.assertTrue
@RunWith
(
RobolectricTestRunner
::
class
)
@Config
(
constants
=
BuildConfig
::
class
,
application
=
PushManagerTest
.
StubApplication
::
class
,
sdk
=
intArrayOf
(
23
))
class
PushManagerTest
{
val
EJSON
=
"""
{
"host":"https://open.rocket.chat/",
"rid":"FaXMyHqbNJbPq6Ym9uWiyfQkgekhXywvKw",
"sender":{
"_id":"uWiFa3adOi0adac",
"username":"jean-luc.picard",
"name":"Jean-Luc Picard"
},
"type":"d",
"name":null
}
"""
val
EJSON_NO_SENDER
=
"""
{
"host":"https://open.rocket.chat/",
"rid":"FaXMyHqbNJbPq6Ym9uWiyfQkgekhXywvKw",
"sender":null,
"type":"d",
"name":null
}
"""
lateinit
var
data
:
Bundle
lateinit
var
pushManager
:
PushManager
lateinit
var
context
:
Context
@Before
fun
setUp
()
{
MockitoAnnotations
.
initMocks
(
this
)
data
=
Bundle
()
data
.
putString
(
"message"
,
"Hello"
)
data
.
putString
(
"title"
,
"jean-luc.picard"
)
data
.
putString
(
"ejson"
,
EJSON
)
data
.
putString
(
"notId"
,
"1"
)
context
=
spy
(
RuntimeEnvironment
.
application
)
pushManager
=
spy
(
PushManager
)
val
res
=
mock
<
Resources
>
{
on
{
getColor
(
any
())
}
doReturn
0
on
{
getIdentifier
(
anyString
(),
anyString
(),
any
())
}
doReturn
R
.
drawable
.
notification_background
on
{
getConfiguration
()
}
doReturn
RuntimeEnvironment
.
application
.
resources
.
configuration
}
whenever
(
context
.
resources
).
doReturn
(
res
)
whenever
(
context
.
applicationContext
).
doReturn
(
context
)
}
@Test
fun
`
should
create
PushMessage
without
throwing
`
()
{
PushMessage
(
null
,
null
,
null
,
null
,
null
,
"xxx"
,
null
,
null
)
}
@Test
fun
`
given
data
shoud
show
notification
`
()
{
pushManager
.
handle
(
context
,
data
)
val
push
=
PushMessage
(
title
=
data
[
"title"
]
as
String
,
message
=
data
[
"message"
]
as
String
,
ejson
=
EJSON
,
notificationId
=
"1"
)
verify
(
pushManager
,
times
(
1
)).
showNotification
(
context
,
push
)
}
@Test
fun
`
given
required
data
is
missing
do
not
show
notification
`
()
{
val
bundle
=
Bundle
()
pushManager
.
handle
(
context
,
bundle
)
verify
(
pushManager
,
never
()).
showNotification
(
any
(),
any
())
bundle
.
putString
(
"title"
,
"jean-luc.picard"
)
bundle
.
putString
(
"message"
,
"Hello!"
)
pushManager
.
handle
(
context
,
bundle
)
verify
(
pushManager
,
never
()).
showNotification
(
any
(),
any
())
bundle
.
clear
()
bundle
.
putString
(
"ejson"
,
EJSON
)
bundle
.
putString
(
"message"
,
"Hello!"
)
pushManager
.
handle
(
context
,
bundle
)
verify
(
pushManager
,
never
()).
showNotification
(
any
(),
any
())
bundle
.
clear
()
bundle
.
putString
(
"ejson"
,
EJSON
)
bundle
.
putString
(
"title"
,
"jean-luc.picard"
)
pushManager
.
handle
(
context
,
bundle
)
verify
(
pushManager
,
never
()).
showNotification
(
any
(),
any
())
}
@Test
fun
`
given
data
should
deserialize
correctly
`
()
{
pushManager
.
handle
(
context
,
data
)
val
push
=
PushMessage
(
data
.
getString
(
"title"
),
data
.
getString
(
"message"
),
null
,
EJSON
,
null
,
data
.
getString
(
"notId"
),
null
,
null
)
verify
(
pushManager
,
times
(
1
)).
showNotification
(
context
,
push
)
push
.
title
`
should
equal
`
"jean-luc.picard"
push
.
message
`
should
equal
`
"Hello"
val
sender
=
push
.
sender
assertTrue
(
sender
!=
null
)
sender
?.
_id
`
should
equal
`
"uWiFa3adOi0adac"
sender
?.
name
`
should
equal
`
"Jean-Luc Picard"
sender
?.
username
`
should
equal
`
"jean-luc.picard"
}
@Test
fun
`
given
that
only
sender
is
missing
show
notification
`
()
{
val
bundle
=
Bundle
()
bundle
.
putString
(
"title"
,
"jean-luc.picard"
)
bundle
.
putString
(
"message"
,
"Hello"
)
bundle
.
putString
(
"ejson"
,
EJSON_NO_SENDER
)
pushManager
.
handle
(
context
,
bundle
)
verify
(
pushManager
,
times
(
1
)).
showNotification
(
any
(),
any
())
}
internal
class
StubApplication
:
Application
()
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment