Skip to content

Commit 1a1a687

Browse files
committed
Fixed boolean conversion issue and updated docs.
1 parent 84a0a87 commit 1a1a687

File tree

3 files changed

+19
-9
lines changed

3 files changed

+19
-9
lines changed

android/src/main/java/com/azure/reactnative/notificationhub/ReactNativeUtil.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ public static WritableMap convertBundleToMap(Bundle bundle) {
8585
map.putInt(key, ((Short) o).intValue());
8686
} else if (o instanceof Byte) {
8787
map.putInt(key, ((Byte) o).intValue());
88+
} else if (o instanceof Boolean) {
89+
map.putBoolean(key, (Boolean) o);
8890
} else {
8991
map.putNull(key);
9092
}

docs/android-installation.md

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,9 @@ import {
181181
const NotificationHub = require('react-native-azurenotificationhub');
182182
const PushNotificationEmitter = new NativeEventEmitter(NotificationHub);
183183

184-
const NOTIF_REGISTER_AZURE_HUB_EVENT = 'azureNotificationHubRegistered';
185-
const NOTIF_AZURE_HUB_REGISTRATION_ERROR_EVENT = 'azureNotificationHubRegistrationError';
186-
const DEVICE_NOTIF_EVENT = 'remoteNotificationReceived';
184+
const EVENT_AZURE_NOTIFICATION_HUB_REGISTERED = 'azureNotificationHubRegistered';
185+
const EVENT_AZURE_NOTIFICATION_HUB_REGISTERED_ERROR = 'azureNotificationHubRegisteredError';
186+
const EVENT_REMOTE_NOTIFICATION_RECEIVED = 'remoteNotificationReceived';
187187

188188
const connectionString = '...'; // The Notification Hub connection string
189189
const hubName = '...'; // The Notification Hub name
@@ -201,12 +201,12 @@ const channelEnableVibration = true;
201201
export default class App extends Component {
202202
constructor(props) {
203203
super(props);
204-
PushNotificationEmitter.addListener(DEVICE_NOTIF_EVENT, this._onRemoteNotification);
204+
PushNotificationEmitter.addListener(EVENT_REMOTE_NOTIFICATION_RECEIVED, this._onRemoteNotification);
205205
}
206206

207207
register() {
208-
PushNotificationEmitter.addListener(NOTIF_REGISTER_AZURE_HUB_EVENT, this._onAzureNotificationHubRegistered);
209-
PushNotificationEmitter.addListener(NOTIF_AZURE_HUB_REGISTRATION_ERROR_EVENT, this._onAzureNotificationHubRegistrationError);
208+
PushNotificationEmitter.addListener(EVENT_AZURE_NOTIFICATION_HUB_REGISTERED, this._onAzureNotificationHubRegistered);
209+
PushNotificationEmitter.addListener(EVENT_AZURE_NOTIFICATION_HUB_REGISTERED_ERROR, this._onAzureNotificationHubRegisteredError);
210210

211211
NotificationHub.register({
212212
connectionString,
@@ -251,13 +251,12 @@ export default class App extends Component {
251251
console.warn('RegistrationID: ' + registrationID);
252252
}
253253

254-
_onAzureNotificationHubRegistrationError(error) {
254+
_onAzureNotificationHubRegisteredError(error) {
255255
console.warn('Error: ' + error);
256256
}
257257

258258
_onRemoteNotification(notification) {
259-
// Note notification will be a JSON string for android
260-
console.warn('Notification received: ' + notification);
259+
console.warn(notification);
261260
}
262261
}
263262

sample/android/app/src/test/java/com/reactnativeazurenotificationhubsample/ReactNativeUtilTest.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import static com.azure.reactnative.notificationhub.ReactNativeNotificationHubUtil.*;
2323
import static com.azure.reactnative.notificationhub.ReactNativeConstants.*;
24+
import static org.mockito.ArgumentMatchers.anyBoolean;
2425
import static org.mockito.ArgumentMatchers.anyDouble;
2526
import static org.mockito.ArgumentMatchers.anyFloat;
2627
import static org.mockito.ArgumentMatchers.anyInt;
@@ -113,6 +114,7 @@ public void testConvertBundleToMapNullArgument() {
113114
verify(expectedMap, times(0)).putDouble(anyString(), anyDouble());
114115
verify(expectedMap, times(0)).putDouble(anyString(), anyFloat());
115116
verify(expectedMap, times(0)).putInt(anyString(), anyInt());
117+
verify(expectedMap, times(0)).putBoolean(anyString(), anyBoolean());
116118
verify(expectedMap, times(0)).putNull(anyString());
117119
}
118120

@@ -184,6 +186,13 @@ public void testConvertBundleToMap() {
184186
convertBundleToMap(mBundle);
185187
verify(expectedMap, times(1)).putInt(key, byteValue.intValue());
186188

189+
reset(expectedMap);
190+
when(mBundle.keySet()).thenReturn(keys);
191+
final Boolean booleanValue = new Boolean(true);
192+
when(mBundle.get(key)).thenReturn(booleanValue);
193+
convertBundleToMap(mBundle);
194+
verify(expectedMap, times(1)).putBoolean(key, booleanValue);
195+
187196
reset(expectedMap);
188197
when(mBundle.keySet()).thenReturn(keys);
189198
when(mBundle.get(key)).thenReturn(new HashMap<>());

0 commit comments

Comments
 (0)