From 200a439aa6841276a3ab19517f2a33c9ed707523 Mon Sep 17 00:00:00 2001 From: Beverly Date: Mon, 18 Jun 2018 16:42:14 -0400 Subject: [PATCH] Fix flaky ScheduleCalendarTest Accurately get the next day. Test: atest com.android.server.notification.ScheduleCalendarTest Fixes: 110355145 (cherry picked from commit fe099b59ec4d6e387837082310326a2a7564b2c3) Test: Treehugger Bug: 110355145 Change-Id: Idc20944679b44b30a40eb65d958df9fffec69375 Merged-In: Idc20944679b44b30a40eb65d958df9fffec69375 --- .../notification/ScheduleCalendarTest.java | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/services/tests/uiservicestests/src/com/android/server/notification/ScheduleCalendarTest.java b/services/tests/uiservicestests/src/com/android/server/notification/ScheduleCalendarTest.java index 942a07acbf9f0..96ac93536a8a5 100644 --- a/services/tests/uiservicestests/src/com/android/server/notification/ScheduleCalendarTest.java +++ b/services/tests/uiservicestests/src/com/android/server/notification/ScheduleCalendarTest.java @@ -121,7 +121,7 @@ public class ScheduleCalendarTest extends UiServiceTestCase { cal.set(Calendar.MINUTE, 15); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); - mScheduleInfo.days = new int[] {getTodayDay(), getTodayDay() + 1}; + mScheduleInfo.days = new int[] {getTodayDay(), getTodayDay(1)}; mScheduleInfo.startHour = 1; mScheduleInfo.endHour = 3; mScheduleInfo.startMinute = 15; @@ -149,7 +149,7 @@ public class ScheduleCalendarTest extends UiServiceTestCase { cal.set(Calendar.MINUTE, 15); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); - mScheduleInfo.days = new int[] {getTodayDay(), getTodayDay() + 1}; + mScheduleInfo.days = new int[] {getTodayDay(), getTodayDay(1)}; mScheduleInfo.startHour = 22; mScheduleInfo.endHour = 3; mScheduleInfo.startMinute = 15; @@ -250,7 +250,7 @@ public class ScheduleCalendarTest extends UiServiceTestCase { calAlarm.add(Calendar.DATE, 1); // add a day // ScheduleInfo: day 1, day 2: 9pm-7am - mScheduleInfo.days = new int[] {getTodayDay(), getTodayDay() + 1}; + mScheduleInfo.days = new int[] {getTodayDay(), getTodayDay(1)}; mScheduleInfo.startHour = 21; mScheduleInfo.endHour = 7; mScheduleInfo.startMinute = 0; @@ -418,7 +418,7 @@ public class ScheduleCalendarTest extends UiServiceTestCase { now.set(Calendar.MILLISECOND, 0); now.add(Calendar.DATE, 1); // add a day - mScheduleInfo.days = new int[] {getTodayDay(), getTodayDay() + 1}; + mScheduleInfo.days = new int[] {getTodayDay(), getTodayDay(1)}; mScheduleInfo.startHour = 22; mScheduleInfo.startMinute = 15; mScheduleInfo.endHour = 3; @@ -446,7 +446,7 @@ public class ScheduleCalendarTest extends UiServiceTestCase { now.set(Calendar.MILLISECOND, 0); now.add(Calendar.DATE, 1); // add a day - mScheduleInfo.days = new int[] {getTodayDay(), getTodayDay() + 1}; + mScheduleInfo.days = new int[] {getTodayDay(), getTodayDay(1)}; mScheduleInfo.startHour = 22; mScheduleInfo.startMinute = 15; mScheduleInfo.endHour = 3; @@ -464,4 +464,10 @@ public class ScheduleCalendarTest extends UiServiceTestCase { private int getTodayDay() { return new GregorianCalendar().get(Calendar.DAY_OF_WEEK); } + + private int getTodayDay(int offset) { + Calendar cal = new GregorianCalendar(); + cal.add(Calendar.DATE, offset); + return cal.get(Calendar.DAY_OF_WEEK); + } }