Skip to content

Commit f77d2bb

Browse files
committed
Refactored class name for consistency.
1 parent c7bf7f8 commit f77d2bb

11 files changed

+77
-77
lines changed

android/src/main/java/com/azure/reactnative/notificationhub/Constants.java renamed to android/src/main/java/com/azure/reactnative/notificationhub/ReactNativeConstants.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.azure.reactnative.notificationhub;
22

3-
public final class Constants {
3+
public final class ReactNativeConstants {
44
// Notification
55
public static final String AZURE_NOTIFICATION_HUB_NAME = "AzureNotificationHub";
66
public static final String NOTIF_REGISTER_AZURE_HUB_EVENT = "azureNotificationHubRegistered";
@@ -82,6 +82,6 @@ public final class Constants {
8282
public static final String ERROR_NOT_REGISTERED = "E_NOT_REGISTERED";
8383
public static final String ERROR_NOT_REGISTERED_DESC = "No registration to Azure Notification Hub.";
8484

85-
private Constants() {
85+
private ReactNativeConstants() {
8686
}
8787
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import com.google.firebase.messaging.FirebaseMessagingService;
1212
import com.google.firebase.messaging.RemoteMessage;
1313

14-
import static com.azure.reactnative.notificationhub.Constants.*;
14+
import static com.azure.reactnative.notificationhub.ReactNativeConstants.*;
1515

1616
public class ReactNativeFirebaseMessagingService extends FirebaseMessagingService {
1717

@@ -21,8 +21,8 @@ public class ReactNativeFirebaseMessagingService extends FirebaseMessagingServic
2121

2222
public static void createNotificationChannel(Context context) {
2323
if (notificationChannelID == null) {
24-
NotificationHubUtil notificationHubUtil = NotificationHubUtil.getInstance();
25-
NotificationChannelBuilder builder = NotificationChannelBuilder.Factory.create();
24+
ReactNativeNotificationHubUtil notificationHubUtil = ReactNativeNotificationHubUtil.getInstance();
25+
ReactNativeNotificationChannelBuilder builder = ReactNativeNotificationChannelBuilder.Factory.create();
2626
if (notificationHubUtil.hasChannelImportance(context)) {
2727
builder.setImportance(notificationHubUtil.getChannelImportance(context));
2828
}
@@ -66,13 +66,13 @@ public static void deleteNotificationChannel(Context context) {
6666
public void onNewToken(String token) {
6767
Log.i(TAG, "Refreshing FCM Registration Token");
6868

69-
Intent intent = NotificationHubUtil.IntentFactory.createIntent(this, ReactNativeRegistrationIntentService.class);
69+
Intent intent = ReactNativeNotificationHubUtil.IntentFactory.createIntent(this, ReactNativeRegistrationIntentService.class);
7070
ReactNativeRegistrationIntentService.enqueueWork(this, intent);
7171
}
7272

7373
@Override
7474
public void onMessageReceived(RemoteMessage remoteMessage) {
75-
NotificationHubUtil notificationHubUtil = NotificationHubUtil.getInstance();
75+
ReactNativeNotificationHubUtil notificationHubUtil = ReactNativeNotificationHubUtil.getInstance();
7676
Log.d(TAG, "Remote message from: " + remoteMessage.getFrom());
7777

7878
if (notificationChannelID == null) {

android/src/main/java/com/azure/reactnative/notificationhub/NotificationChannelBuilder.java renamed to android/src/main/java/com/azure/reactnative/notificationhub/ReactNativeNotificationChannelBuilder.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
import android.app.NotificationChannel;
44
import android.app.NotificationManager;
55

6-
public class NotificationChannelBuilder {
7-
private String mID = Constants.NOTIFICATION_CHANNEL_ID;
6+
public class ReactNativeNotificationChannelBuilder {
7+
private String mID = ReactNativeConstants.NOTIFICATION_CHANNEL_ID;
88
private CharSequence mName = "rn-push-notification-channel-name";
99
private String mDesc = "rn-push-notification-channel-description";
1010
private int mImportance = NotificationManager.IMPORTANCE_DEFAULT;
@@ -13,12 +13,12 @@ public class NotificationChannelBuilder {
1313
private boolean mEnableVibration = true;
1414

1515
public static class Factory {
16-
public static NotificationChannelBuilder create() {
17-
return new NotificationChannelBuilder();
16+
public static ReactNativeNotificationChannelBuilder create() {
17+
return new ReactNativeNotificationChannelBuilder();
1818
}
1919
}
2020

21-
private NotificationChannelBuilder() {
21+
private ReactNativeNotificationChannelBuilder() {
2222
}
2323

2424
public NotificationChannel build() {
@@ -30,32 +30,32 @@ public NotificationChannel build() {
3030
return channel;
3131
}
3232

33-
public NotificationChannelBuilder setName(CharSequence name) {
33+
public ReactNativeNotificationChannelBuilder setName(CharSequence name) {
3434
this.mName = name;
3535
return this;
3636
}
3737

38-
public NotificationChannelBuilder setImportance(int importance) {
38+
public ReactNativeNotificationChannelBuilder setImportance(int importance) {
3939
this.mImportance = importance;
4040
return this;
4141
}
4242

43-
public NotificationChannelBuilder setDescription(String desc) {
43+
public ReactNativeNotificationChannelBuilder setDescription(String desc) {
4444
this.mDesc = desc;
4545
return this;
4646
}
4747

48-
public NotificationChannelBuilder setShowBadge(boolean showBadge) {
48+
public ReactNativeNotificationChannelBuilder setShowBadge(boolean showBadge) {
4949
this.mShowBadge = showBadge;
5050
return this;
5151
}
5252

53-
public NotificationChannelBuilder enableLights(boolean enableLights) {
53+
public ReactNativeNotificationChannelBuilder enableLights(boolean enableLights) {
5454
this.mEnableLights = enableLights;
5555
return this;
5656
}
5757

58-
public NotificationChannelBuilder enableVibration(boolean enableVibration) {
58+
public ReactNativeNotificationChannelBuilder enableVibration(boolean enableVibration) {
5959
this.mEnableVibration = enableVibration;
6060
return this;
6161
}

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import com.facebook.react.bridge.ReadableMap;
2727
import com.facebook.react.bridge.UiThreadUtil;
2828

29-
import static com.azure.reactnative.notificationhub.Constants.*;
29+
import static com.azure.reactnative.notificationhub.ReactNativeConstants.*;
3030

3131
public class ReactNativeNotificationHubModule extends ReactContextBaseJavaModule implements
3232
ActivityEventListener, LifecycleEventListener {
@@ -53,18 +53,18 @@ public String getName() {
5353
}
5454

5555
public void setIsForeground(boolean isForeground) {
56-
NotificationHubUtil notificationHubUtil = NotificationHubUtil.getInstance();
56+
ReactNativeNotificationHubUtil notificationHubUtil = ReactNativeNotificationHubUtil.getInstance();
5757
notificationHubUtil.setAppIsForeground(isForeground);
5858
}
5959

6060
public boolean getIsForeground() {
61-
NotificationHubUtil notificationHubUtil = NotificationHubUtil.getInstance();
61+
ReactNativeNotificationHubUtil notificationHubUtil = ReactNativeNotificationHubUtil.getInstance();
6262
return notificationHubUtil.getAppIsForeground();
6363
}
6464

6565
@ReactMethod
6666
public void register(ReadableMap config, Promise promise) {
67-
NotificationHubUtil notificationHubUtil = NotificationHubUtil.getInstance();
67+
ReactNativeNotificationHubUtil notificationHubUtil = ReactNativeNotificationHubUtil.getInstance();
6868
String connectionString = config.getString("connectionString");
6969
if (connectionString == null) {
7070
promise.reject(ERROR_INVALID_ARGUMENTS, ERROR_INVALID_CONNECTION_STRING);
@@ -134,14 +134,14 @@ public void register(ReadableMap config, Promise promise) {
134134
return;
135135
}
136136

137-
Intent intent = NotificationHubUtil.IntentFactory.createIntent(
137+
Intent intent = ReactNativeNotificationHubUtil.IntentFactory.createIntent(
138138
reactContext, ReactNativeRegistrationIntentService.class);
139139
ReactNativeRegistrationIntentService.enqueueWork(reactContext, intent);
140140
}
141141

142142
@ReactMethod
143143
public void unregister(Promise promise) {
144-
NotificationHubUtil notificationHubUtil = NotificationHubUtil.getInstance();
144+
ReactNativeNotificationHubUtil notificationHubUtil = ReactNativeNotificationHubUtil.getInstance();
145145

146146
ReactContext reactContext = getReactApplicationContext();
147147
String connectionString = notificationHubUtil.getConnectionString(reactContext);

android/src/main/java/com/azure/reactnative/notificationhub/NotificationHubUtil.java renamed to android/src/main/java/com/azure/reactnative/notificationhub/ReactNativeNotificationHubUtil.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@
2525
import org.json.JSONException;
2626
import org.json.JSONObject;
2727

28-
import static com.azure.reactnative.notificationhub.Constants.*;
28+
import static com.azure.reactnative.notificationhub.ReactNativeConstants.*;
2929

30-
public class NotificationHubUtil {
30+
public class ReactNativeNotificationHubUtil {
3131
public static final String TAG = "NotificationHubUtil";
3232

33-
private static NotificationHubUtil sharedNotificationHubUtilInstance = null;
33+
private static ReactNativeNotificationHubUtil sharedNotificationHubUtilInstance = null;
3434

3535
private final ExecutorService mPool = Executors.newFixedThreadPool(1);
3636

@@ -50,9 +50,9 @@ public static Intent createIntent(Context context, Class intentClass) {
5050
}
5151
}
5252

53-
public static NotificationHubUtil getInstance() {
53+
public static ReactNativeNotificationHubUtil getInstance() {
5454
if (sharedNotificationHubUtilInstance == null) {
55-
sharedNotificationHubUtilInstance = new NotificationHubUtil();
55+
sharedNotificationHubUtilInstance = new ReactNativeNotificationHubUtil();
5656
}
5757
return sharedNotificationHubUtilInstance;
5858
}

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

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

2222
import org.json.JSONObject;
2323

24-
import static com.azure.reactnative.notificationhub.Constants.*;
24+
import static com.azure.reactnative.notificationhub.ReactNativeConstants.*;
2525

2626
public final class ReactNativeNotificationsHandler {
2727
public static final String TAG = "ReactNativeNotification";
@@ -32,7 +32,7 @@ private ReactNativeNotificationsHandler() {
3232
}
3333

3434
public static void sendBroadcast(final Context context, final Bundle bundle, final long delay) {
35-
final NotificationHubUtil hubUtil = NotificationHubUtil.getInstance();
35+
final ReactNativeNotificationHubUtil hubUtil = ReactNativeNotificationHubUtil.getInstance();
3636
hubUtil.runInWorkerThread(new Runnable() {
3737
public void run() {
3838
try {
@@ -49,7 +49,7 @@ public void run() {
4949

5050
public static void sendNotification(Context context, Bundle bundle, String notificationChannelID) {
5151
try {
52-
final NotificationHubUtil hubUtil = NotificationHubUtil.getInstance();
52+
final ReactNativeNotificationHubUtil hubUtil = ReactNativeNotificationHubUtil.getInstance();
5353
Class intentClass = hubUtil.getMainActivityClass(context);
5454
if (intentClass == null) {
5555
Log.e(TAG, ERROR_NO_ACTIVITY_CLASS);

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ public static void enqueueWork(Context context, Intent work) {
3434
@Override
3535
protected void onHandleWork(Intent intent) {
3636
final LocalBroadcastManager localBroadcastManager = LocalBroadcastManager.getInstance(this);
37-
final Intent event = NotificationHubUtil.IntentFactory.createIntent(TAG);
38-
final NotificationHubUtil notificationHubUtil = NotificationHubUtil.getInstance();
37+
final Intent event = ReactNativeNotificationHubUtil.IntentFactory.createIntent(TAG);
38+
final ReactNativeNotificationHubUtil notificationHubUtil = ReactNativeNotificationHubUtil.getInstance();
3939
final String connectionString = notificationHubUtil.getConnectionString(this);
4040
final String hubName = notificationHubUtil.getHubName(this);
4141
final String storedToken = notificationHubUtil.getFCMToken(this);
@@ -71,7 +71,7 @@ public void onSuccess(InstanceIdResult instanceIdResult) {
7171
notificationHubUtil.setRegistrationID(ReactNativeRegistrationIntentService.this, regID);
7272
notificationHubUtil.setFCMToken(ReactNativeRegistrationIntentService.this, token);
7373

74-
event.putExtra("event", Constants.NOTIF_REGISTER_AZURE_HUB_EVENT);
74+
event.putExtra("event", ReactNativeConstants.NOTIF_REGISTER_AZURE_HUB_EVENT);
7575
event.putExtra("data", regID);
7676
localBroadcastManager.sendBroadcast(event);
7777

@@ -82,7 +82,7 @@ public void onSuccess(InstanceIdResult instanceIdResult) {
8282
} catch (Exception e) {
8383
Log.e(TAG, "Failed to complete token refresh", e);
8484

85-
event.putExtra("event", Constants.NOTIF_AZURE_HUB_REGISTRATION_ERROR_EVENT);
85+
event.putExtra("event", ReactNativeConstants.NOTIF_AZURE_HUB_REGISTRATION_ERROR_EVENT);
8686
event.putExtra("data", e.getMessage());
8787
localBroadcastManager.sendBroadcast(event);
8888
}

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

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
import android.os.Bundle;
99
import android.util.Log;
1010

11-
import com.azure.reactnative.notificationhub.NotificationChannelBuilder;
12-
import com.azure.reactnative.notificationhub.NotificationHubUtil;
11+
import com.azure.reactnative.notificationhub.ReactNativeNotificationChannelBuilder;
12+
import com.azure.reactnative.notificationhub.ReactNativeNotificationHubUtil;
1313
import com.azure.reactnative.notificationhub.ReactNativeFirebaseMessagingService;
1414
import com.azure.reactnative.notificationhub.ReactNativeNotificationsHandler;
1515
import com.azure.reactnative.notificationhub.ReactNativeRegistrationIntentService;
@@ -26,7 +26,7 @@
2626
import org.powermock.modules.junit4.PowerMockRunner;
2727
import org.powermock.reflect.Whitebox;
2828

29-
import static com.azure.reactnative.notificationhub.Constants.*;
29+
import static com.azure.reactnative.notificationhub.ReactNativeConstants.*;
3030
import static org.mockito.ArgumentMatchers.any;
3131
import static org.mockito.ArgumentMatchers.anyBoolean;
3232
import static org.mockito.ArgumentMatchers.anyInt;
@@ -43,11 +43,11 @@
4343
*/
4444
@RunWith(PowerMockRunner.class)
4545
@PrepareForTest({
46-
NotificationHubUtil.class,
46+
ReactNativeNotificationHubUtil.class,
4747
ReactNativeNotificationsHandler.class,
4848
ReactNativeRegistrationIntentService.class,
49-
NotificationChannelBuilder.Factory.class,
50-
NotificationHubUtil.IntentFactory.class,
49+
ReactNativeNotificationChannelBuilder.Factory.class,
50+
ReactNativeNotificationHubUtil.IntentFactory.class,
5151
Build.VERSION.class,
5252
FirebaseMessagingService.class,
5353
RemoteMessage.class,
@@ -58,7 +58,7 @@ public class ReactNativeFirebaseMessagingServiceTest {
5858
ReactApplicationContext mReactApplicationContext;
5959

6060
@Mock
61-
NotificationHubUtil mHubUtil;
61+
ReactNativeNotificationHubUtil mHubUtil;
6262

6363
@Mock
6464
NotificationManager mNotificationManager;
@@ -72,12 +72,12 @@ public void setUp() {
7272
reset(mReactApplicationContext);
7373

7474
// Prepare mock objects
75-
PowerMockito.mockStatic(NotificationHubUtil.class);
76-
when(NotificationHubUtil.getInstance()).thenReturn(mHubUtil);
75+
PowerMockito.mockStatic(ReactNativeNotificationHubUtil.class);
76+
when(ReactNativeNotificationHubUtil.getInstance()).thenReturn(mHubUtil);
7777
PowerMockito.mockStatic(ReactNativeNotificationsHandler.class);
7878
PowerMockito.mockStatic(ReactNativeRegistrationIntentService.class);
79-
PowerMockito.mockStatic(NotificationChannelBuilder.Factory.class);
80-
PowerMockito.mockStatic(NotificationHubUtil.IntentFactory.class);
79+
PowerMockito.mockStatic(ReactNativeNotificationChannelBuilder.Factory.class);
80+
PowerMockito.mockStatic(ReactNativeNotificationHubUtil.IntentFactory.class);
8181
PowerMockito.suppress(methodsDeclaredIn(FirebaseMessagingService.class));
8282
PowerMockito.mockStatic(Log.class);
8383
when(mReactApplicationContext.getSystemService(Context.NOTIFICATION_SERVICE)).thenReturn(
@@ -97,8 +97,8 @@ public void setUp() {
9797
public void testCreateNotificationChannelBelowVersionO() {
9898
final int sdkVersion = Build.VERSION_CODES.LOLLIPOP;
9999

100-
NotificationChannelBuilder builder = PowerMockito.mock(NotificationChannelBuilder.class);
101-
when(NotificationChannelBuilder.Factory.create()).thenReturn(builder);
100+
ReactNativeNotificationChannelBuilder builder = PowerMockito.mock(ReactNativeNotificationChannelBuilder.class);
101+
when(ReactNativeNotificationChannelBuilder.Factory.create()).thenReturn(builder);
102102
when(mHubUtil.hasChannelImportance(mReactApplicationContext)).thenReturn(false);
103103
when(mHubUtil.hasChannelShowBadge(mReactApplicationContext)).thenReturn(false);
104104
when(mHubUtil.hasChannelEnableLights(mReactApplicationContext)).thenReturn(false);
@@ -124,8 +124,8 @@ public void testCreateNotificationChannel() {
124124
final boolean channelEnableVibration = true;
125125
final int sdkVersion = Build.VERSION_CODES.O;
126126

127-
NotificationChannelBuilder builder = PowerMockito.mock(NotificationChannelBuilder.class);
128-
when(NotificationChannelBuilder.Factory.create()).thenReturn(builder);
127+
ReactNativeNotificationChannelBuilder builder = PowerMockito.mock(ReactNativeNotificationChannelBuilder.class);
128+
when(ReactNativeNotificationChannelBuilder.Factory.create()).thenReturn(builder);
129129
NotificationChannel channel = PowerMockito.mock(NotificationChannel.class);
130130
when(channel.getId()).thenReturn(NOTIFICATION_CHANNEL_ID);
131131
when(builder.build()).thenReturn(channel);
@@ -161,8 +161,8 @@ public void testDeleteNotificationChannel() {
161161
Whitebox.setInternalState(Build.VERSION.class, "SDK_INT", sdkVersion);
162162

163163
// Prepare channel
164-
NotificationChannelBuilder builder = PowerMockito.mock(NotificationChannelBuilder.class);
165-
when(NotificationChannelBuilder.Factory.create()).thenReturn(builder);
164+
ReactNativeNotificationChannelBuilder builder = PowerMockito.mock(ReactNativeNotificationChannelBuilder.class);
165+
when(ReactNativeNotificationChannelBuilder.Factory.create()).thenReturn(builder);
166166
NotificationChannel channel = PowerMockito.mock(NotificationChannel.class);
167167
when(channel.getId()).thenReturn(NOTIFICATION_CHANNEL_ID);
168168
when(builder.build()).thenReturn(channel);
@@ -180,8 +180,8 @@ public void testOnNewToken() {
180180

181181
mMessagingService.onNewToken(token);
182182

183-
verifyStatic(NotificationHubUtil.IntentFactory.class);
184-
NotificationHubUtil.IntentFactory.createIntent(
183+
verifyStatic(ReactNativeNotificationHubUtil.IntentFactory.class);
184+
ReactNativeNotificationHubUtil.IntentFactory.createIntent(
185185
any(), eq(ReactNativeRegistrationIntentService.class));
186186
}
187187

@@ -195,8 +195,8 @@ public void testOnMessageReceivedForeground() {
195195
when(mHubUtil.getAppIsForeground()).thenReturn(true);
196196

197197
// Prepare channel
198-
NotificationChannelBuilder builder = PowerMockito.mock(NotificationChannelBuilder.class);
199-
when(NotificationChannelBuilder.Factory.create()).thenReturn(builder);
198+
ReactNativeNotificationChannelBuilder builder = PowerMockito.mock(ReactNativeNotificationChannelBuilder.class);
199+
when(ReactNativeNotificationChannelBuilder.Factory.create()).thenReturn(builder);
200200
NotificationChannel channel = PowerMockito.mock(NotificationChannel.class);
201201
when(channel.getId()).thenReturn(NOTIFICATION_CHANNEL_ID);
202202
when(builder.build()).thenReturn(channel);
@@ -224,8 +224,8 @@ public void testOnMessageReceivedBackground() {
224224
when(mHubUtil.getAppIsForeground()).thenReturn(false);
225225

226226
// Prepare channel
227-
NotificationChannelBuilder builder = PowerMockito.mock(NotificationChannelBuilder.class);
228-
when(NotificationChannelBuilder.Factory.create()).thenReturn(builder);
227+
ReactNativeNotificationChannelBuilder builder = PowerMockito.mock(ReactNativeNotificationChannelBuilder.class);
228+
when(ReactNativeNotificationChannelBuilder.Factory.create()).thenReturn(builder);
229229
NotificationChannel channel = PowerMockito.mock(NotificationChannel.class);
230230
when(channel.getId()).thenReturn(NOTIFICATION_CHANNEL_ID);
231231
when(builder.build()).thenReturn(channel);

0 commit comments

Comments
 (0)