Skip to content

Conversation

@MihaiCristianCondrea
Copy link
Owner

Summary

  • allow AppUsageNotificationWorker to accept injected SharedPreferences and NotificationManager so it can be tested
  • skip posting the reminder when the lastUsed timestamp is missing and always refresh the stored value
  • add unit tests covering last-used scenarios beyond the threshold, within it, and when missing

Testing

  • ./gradlew test (fails: SDK location not found in container)

https://chatgpt.com/codex/tasks/task_e_68c976488a5c832d9864d1c2d4474b05

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codex Review: Here are some suggestions.

Reply with @codex fix comments to fix any unresolved comments.

About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you open a pull request for review, mark a draft as ready, or comment "@codex review". If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex fix this CI failure" or "@codex address that feedback".

Comment on lines +88 to +100
@Test
public void doWork_postsNotificationWhenBeyondThreshold() {
long threshold = TimeUnit.DAYS.toMillis(3);
long lastUsed = System.currentTimeMillis() - threshold - TimeUnit.HOURS.toMillis(1);
when(sharedPreferences.getLong(eq("lastUsed"), anyLong())).thenReturn(lastUsed);

AppUsageNotificationWorker worker = createWorker();

worker.doWork();

verify(sharedPreferences).getLong("lastUsed", 0);
verify(notificationManager).createNotificationChannel(any(NotificationChannel.class));
verify(notificationManager).notify(eq(0), any(Notification.class));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] Avoid invoking Android framework stubs in local unit tests

The new AppUsageNotificationWorkerTest lives under app/src/test, but the test methods construct the worker and exercise NotificationManager.createNotificationChannel and other framework APIs. Local JVM tests in this module run with the stubbed android.jar, so any call into NotificationManager or NotificationChannel will throw RuntimeException("Method … not mocked") unless the test runs under Robolectric or instrumentation. As-is, ./gradlew test will consistently fail once the Android SDK path issue is fixed. Consider converting this test to Robolectric or moving it under androidTest so that Android APIs are available.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants