Skip to content

Add offline unit tests for BackupService - #30

Merged
dmccoystephenson merged 1 commit into
mainfrom
feature/offline-backup-service-tests
Oct 3, 2026
Merged

dmccoystephenson merged 1 commit into
mainfrom
feature/offline-backup-service-tests

Conversation

@dmccoystephenson

Copy link
Copy Markdown
Member

Summary

Stage B (unit-test expansion) cycle targeting BackupService. No production code is changed.

  • testBackupUserRepositories_WithRepositories previously attempted a real clone from https://github.com/testuser/repo1.git; the failure was swallowed, so the test passed without exercising a successful clone. It now clones from a local JGit repository (a file:// URI) and asserts the .git directory was created.
  • New testBackupUserRepositories_ExistingRepositoryIsFetched: a second run against an existing backup takes the update path, prints the "updating"/"Updated successfully" lines, and moves refs/remotes/origin/<branch> to the new source commit.
  • New testBackupUserRepositories_FailedRepositoryIsSummarizedAndOthersContinue: a repository whose clone fails is listed in the ⚠ Warning: 1 repository(ies) failed to backup: summary while the remaining repository is still cloned.
  • New testBackupUserRepositories_BackupDirectoryCannotBeCreated: when the backup directory path is a regular file, the "Failed to create backup directory ''" IOException is raised and no clone is attempted.
  • New testGetBackupStatusData_IgnoresFilesAndFormatsLastModified: plain files at either level are not counted, and lastUpdated uses the yyyy-MM-dd HH:mm:ss system-zone format.
  • New showBackupStatus tests assert the actual stdout for the missing-directory, empty-directory, and populated cases (previously only assertDoesNotThrow).
  • CHANGELOG.md [Unreleased] entry added.

All tests are offline: no network access, filesystem confined to @TempDir, GitHubService/GHRepository mocked, following the existing @Mock + MockitoAnnotations.openMocks(this) pattern. No apparent bugs were surfaced; every assertion characterizes current behavior.

Test plan

  • mvn test -Dtest=BackupServiceTest — 16 tests run, 0 failures
  • mvn test — 125 tests run, 0 failures, 1 skipped (pre-existing)
  • CI Build workflow green on the PR head

Deferred issues

No tracking issue — gap found during triage (the clone test reached out to github.com, and the status tests asserted nothing about output).

This PR description was drafted during a Gardener session (https://github.com/Stephenson-Software/gardener).

🤖 Generated with Claude Code


drafted by Claude on behalf of Daniel Stephenson

Clone and fetch now run against a local source repository instead of
github.com, and the status output, failure summary and directory
creation error are asserted rather than only checked for no exception.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dmccoystephenson

Copy link
Copy Markdown
Member Author

Self-review rubric (head CI: build pass, docker-build pass):

  • Scope: PASS — only src/test/java/com/github/backup/BackupServiceTest.java and one CHANGELOG.md line are modified; no production code touched.
  • Tests-new: PASS (N/A) — no new public methods are introduced; the new private helpers (createSourceRepository, commitFile, captureStdout) are exercised by every test that uses them.
  • Tests-fix: N/A — no bug fix in this PR; all assertions characterize current behavior, and none of them exposed a defect.
  • Sibling structure: PASS — follows the test<MethodName>_<Scenario> naming, @Mock + MockitoAnnotations.openMocks(this), and @TempDir conventions already used in the file.
  • Sibling renames: N/A — nothing renamed.
  • Docs: PASS — no CLI flag, property, or endpoint changes; CHANGELOG.md [Unreleased] records the test addition in the same style as the Add offline unit tests for GitHubService.getPublicRepositories #29 entry.
  • Issue resolution: N/A — no Closes #N; the gap was found during triage, and README links to a LICENSE file that does not exist #8's deferral reason is recorded in the PR body.
  • CI: PASS — both jobs green on the head SHA; locally mvn test ran 125 tests, 0 failures, 1 pre-existing skip.
  • Config-doc parity / Command-doc parity: N/A — no configuration or command surface changed.
  • Package placement: PASS — the test stays in the 1:1 mirror location.
  • No credential leakage: PASS — no tokens used; the tests no longer contact github.com at all.

Observations (no change applied):

  • src/test/java/com/github/backup/BackupServiceTest.java (testBackupUserRepositories_FailedRepositoryIsSummarizedAndOthersContinue) — the failure is triggered by a file:// URI that does not exist, which relies on JGit raising on a missing source. A JGit upgrade that changed this to a silent empty clone would make this test fail loudly, not pass silently, so it is acceptable as a regression guard.
  • captureStdout swaps System.out globally; Surefire runs test classes sequentially in this build (no parallel config in pom.xml), so the swap cannot interleave with another class's output.

Summary: test-only change that removes the last live network call from BackupServiceTest and turns three assertDoesNotThrow-only tests into output assertions.

This review comment was drafted during a Gardener session (https://github.com/Stephenson-Software/gardener).


drafted by Claude on behalf of Daniel Stephenson

@dmccoystephenson
dmccoystephenson merged commit e79e48e into main Oct 3, 2026
2 checks passed
@dmccoystephenson
dmccoystephenson deleted the feature/offline-backup-service-tests branch October 3, 2026 07:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant