Skip to content

Commit 38bfdfc

Browse files
author
“Akshay
committed
Correction after github checks
1 parent 3e4dcd1 commit 38bfdfc

File tree

3 files changed

+18
-23
lines changed

3 files changed

+18
-23
lines changed

iterableapi/src/main/java/com/iterable/iterableapi/IterableInAppFragmentHTMLNotification.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -691,14 +691,14 @@ int getVerticalLocation(Rect padding) {
691691
* Rounds an orientation value to the nearest 90-degree increment.
692692
* This is used to detect significant orientation changes (portrait/landscape).
693693
*
694-
* The calculation uses integer division: ((orientation + 45) / 90) * 90
695-
* This rounds to the nearest multiple of 90 by adding 45 before dividing.
694+
* The calculation rounds to the nearest multiple of 90 by adding 45 before dividing.
695+
* Uses floating point division to correctly handle negative numbers.
696696
*
697697
* @param orientation The orientation value in degrees (typically 0-359 from OrientationEventListener)
698698
* @return The orientation rounded to the nearest 90-degree increment (0, 90, 180, 270, or 360)
699699
*/
700700
static int roundToNearest90Degrees(int orientation) {
701-
return ((orientation + 45) / 90) * 90;
701+
return (int) (Math.round((orientation + 45.0) / 90.0) * 90);
702702
}
703703

704704
/**

iterableapi/src/test/java/com/iterable/iterableapi/IterableInAppHTMLNotificationTest.java

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,6 @@
2020
import static junit.framework.Assert.assertEquals;
2121
import static junit.framework.Assert.assertNotNull;
2222
import static junit.framework.Assert.assertTrue;
23-
import static org.mockito.ArgumentMatchers.any;
24-
import static org.mockito.Mockito.doCallRealMethod;
25-
import static org.mockito.Mockito.never;
26-
import static org.mockito.Mockito.spy;
27-
import static org.mockito.Mockito.times;
28-
import static org.mockito.Mockito.verify;
2923
import static org.robolectric.Shadows.shadowOf;
3024

3125
public class IterableInAppHTMLNotificationTest extends BaseTest {
@@ -146,7 +140,8 @@ public void testResizeValidation_HandlesGracefully() {
146140
public void testApplyWindowGravity_Center() {
147141
Rect padding = new Rect(0, -1, 0, -1); // Center padding
148142
IterableInAppFragmentHTMLNotification notification = IterableInAppFragmentHTMLNotification.createInstance(
149-
"<html><body>Test</body></html>", false, uri -> {}, IterableInAppLocation.IN_APP, "msg1", 0.0, padding, false, new IterableInAppMessage.InAppBgColor(null, 0.0f));
143+
"<html><body>Test</body></html>", false, uri -> {
144+
}, IterableInAppLocation.IN_APP, "msg1", 0.0, padding, false, new IterableInAppMessage.InAppBgColor(null, 0.0f));
150145

151146
// Verify gravity calculation for center padding
152147
assertEquals(Gravity.CENTER_VERTICAL, notification.getVerticalLocation(padding));
@@ -156,7 +151,8 @@ public void testApplyWindowGravity_Center() {
156151
public void testApplyWindowGravity_Top() {
157152
Rect padding = new Rect(0, 0, 0, -1); // Top padding
158153
IterableInAppFragmentHTMLNotification notification = IterableInAppFragmentHTMLNotification.createInstance(
159-
"<html><body>Test</body></html>", false, uri -> {}, IterableInAppLocation.IN_APP, "msg1", 0.0, padding, false, new IterableInAppMessage.InAppBgColor(null, 0.0f));
154+
"<html><body>Test</body></html>", false, uri -> {
155+
}, IterableInAppLocation.IN_APP, "msg1", 0.0, padding, false, new IterableInAppMessage.InAppBgColor(null, 0.0f));
160156

161157
assertEquals(Gravity.TOP, notification.getVerticalLocation(padding));
162158
}
@@ -165,7 +161,8 @@ public void testApplyWindowGravity_Top() {
165161
public void testApplyWindowGravity_Bottom() {
166162
Rect padding = new Rect(0, -1, 0, 0); // Bottom padding
167163
IterableInAppFragmentHTMLNotification notification = IterableInAppFragmentHTMLNotification.createInstance(
168-
"<html><body>Test</body></html>", false, uri -> {}, IterableInAppLocation.IN_APP, "msg1", 0.0, padding, false, new IterableInAppMessage.InAppBgColor(null, 0.0f));
164+
"<html><body>Test</body></html>", false, uri -> {
165+
}, IterableInAppLocation.IN_APP, "msg1", 0.0, padding, false, new IterableInAppMessage.InAppBgColor(null, 0.0f));
169166

170167
assertEquals(Gravity.BOTTOM, notification.getVerticalLocation(padding));
171168
}
@@ -174,8 +171,9 @@ public void testApplyWindowGravity_Bottom() {
174171
public void testApplyWindowGravity_HandlesNullWindow() {
175172
Rect padding = new Rect(0, 0, 0, -1);
176173
IterableInAppFragmentHTMLNotification notification = IterableInAppFragmentHTMLNotification.createInstance(
177-
"<html><body>Test</body></html>", false, uri -> {}, IterableInAppLocation.IN_APP, "msg1", 0.0, padding, false, new IterableInAppMessage.InAppBgColor(null, 0.0f));
178-
174+
"<html><body>Test</body></html>", false, uri -> {
175+
}, IterableInAppLocation.IN_APP, "msg1", 0.0, padding, false, new IterableInAppMessage.InAppBgColor(null, 0.0f));
176+
179177
// Test that getVerticalLocation works correctly
180178
assertEquals(Gravity.TOP, notification.getVerticalLocation(padding));
181179
// applyWindowGravity is private but is called in onStart/onCreateDialog/onCreateView
@@ -235,7 +233,7 @@ public void testLayoutStructure_FullScreenNoRelativeLayoutWrapper() {
235233
assertTrue("Root view should have children", rootView.getChildCount() > 0);
236234
ViewGroup child = (ViewGroup) rootView.getChildAt(0);
237235
// WebView is not a ViewGroup, so we check it's not a RelativeLayout
238-
assertTrue("First child should be WebView (not RelativeLayout) for full screen in-apps",
236+
assertTrue("First child should be WebView (not RelativeLayout) for full screen in-apps",
239237
!(child instanceof RelativeLayout));
240238
}
241239

@@ -300,7 +298,7 @@ public void testOrientationChange_PortraitToLandscape() throws Exception {
300298
// The test passes if no exceptions are thrown and the resize was triggered
301299
// We verify indirectly by ensuring the notification still exists and is in a valid state
302300
assertNotNull("Notification should still exist after orientation change", notification);
303-
301+
304302
// The resize should have been triggered (1500ms delay + 200ms debounce)
305303
// If runResizeScript wasn't called, we would have seen validation errors or exceptions
306304
// The fact that we get here without exceptions means the orientation change handling worked
@@ -326,23 +324,23 @@ public void testRoundToNearest90Degrees_StandardOrientations() {
326324
public void testRoundToNearest90Degrees_BoundaryValues() {
327325
// Values that round down to 0 (0-44)
328326
assertEquals(0, IterableInAppFragmentHTMLNotification.roundToNearest90Degrees(44));
329-
327+
330328
// Values that round up to 90 (45-134)
331329
assertEquals(90, IterableInAppFragmentHTMLNotification.roundToNearest90Degrees(45));
332330
assertEquals(90, IterableInAppFragmentHTMLNotification.roundToNearest90Degrees(89));
333331
assertEquals(90, IterableInAppFragmentHTMLNotification.roundToNearest90Degrees(90));
334332
assertEquals(90, IterableInAppFragmentHTMLNotification.roundToNearest90Degrees(134));
335-
333+
336334
// Values that round up to 180 (135-224)
337335
assertEquals(180, IterableInAppFragmentHTMLNotification.roundToNearest90Degrees(135));
338336
assertEquals(180, IterableInAppFragmentHTMLNotification.roundToNearest90Degrees(180));
339337
assertEquals(180, IterableInAppFragmentHTMLNotification.roundToNearest90Degrees(224));
340-
338+
341339
// Values that round up to 270 (225-314)
342340
assertEquals(270, IterableInAppFragmentHTMLNotification.roundToNearest90Degrees(225));
343341
assertEquals(270, IterableInAppFragmentHTMLNotification.roundToNearest90Degrees(270));
344342
assertEquals(270, IterableInAppFragmentHTMLNotification.roundToNearest90Degrees(314));
345-
343+
346344
// Values that round up to 360 (315-359)
347345
assertEquals(360, IterableInAppFragmentHTMLNotification.roundToNearest90Degrees(315));
348346
assertEquals(360, IterableInAppFragmentHTMLNotification.roundToNearest90Degrees(359));

iterableapi/src/test/java/com/iterable/iterableapi/IterableWebChromeClientTest.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,11 @@
44

55
import org.junit.Before;
66
import org.junit.Test;
7-
import org.mockito.ArgumentCaptor;
87
import org.mockito.Mock;
98
import org.mockito.MockitoAnnotations;
109

11-
import static org.mockito.ArgumentMatchers.any;
1210
import static org.mockito.Mockito.mock;
1311
import static org.mockito.Mockito.never;
14-
import static org.mockito.Mockito.spy;
1512
import static org.mockito.Mockito.times;
1613
import static org.mockito.Mockito.verify;
1714

0 commit comments

Comments
 (0)