Skip to content

Conversation

@sunkup
Copy link
Member

@sunkup sunkup commented Nov 17, 2025

Reason: Gain more control by decoupl from android.

Short description

  • add CertStore interface implemented by CustomCertStore
  • CustomCertManager: replace context with CertStore
  • move CustomCertManagerTest to unit (non-integration) tests

@sunkup sunkup self-assigned this Nov 17, 2025
@sunkup sunkup added the refactoring Quality improvement of existing functions label Nov 17, 2025
@sunkup sunkup linked an issue Nov 17, 2025 that may be closed by this pull request
@sunkup
Copy link
Member Author

sunkup commented Nov 17, 2025

@bitfireAT/app-dev Not sure whether it's smart to test CustomCertManager with CustomCertManagerTest at all, since most of the logic resides in CustomCertStore anyhow - which still relies on android context and therefore needs to be mocked/faked in unit tests. What do you think?

@rfc2822
Copy link
Member

rfc2822 commented Nov 18, 2025

I'd leave it as it is for now. For future refactoring, I think it's not good design to have

CustomTrustManager      ---        CustomCertStore
only delivers decisons             all logic here, including UI

It may be better to separate concerns more in detail into separate classes:

CustomTrustManager        ---   logic handler           --- store for certificates
delivers decisions              including settings      --- UI handling
                             (trust system certs etc.)

But that's only an idea for somewhen in the future. This PR should only be a small refactoring that allows to use a unit test.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR decouples CustomCertManager from Android dependencies to enable better testability and separation of concerns. The main change introduces a CertStore interface that abstracts certificate storage operations, allowing CustomCertManager to work with any implementation rather than being tightly coupled to Android's Context.

Key changes:

  • Introduced CertStore interface defining certificate storage operations
  • CustomCertStore now implements CertStore interface
  • CustomCertManager constructor now accepts CertStore instead of Context
  • Migrated CustomCertManagerTest from androidTest (integration) to test (unit) with a TestCertStore mock implementation

Reviewed Changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
lib/src/main/java/at/bitfire/cert4android/CertStore.kt New interface defining certificate storage operations
lib/src/main/java/at/bitfire/cert4android/CustomCertStore.kt Now implements CertStore interface; companion object moved to end of file
lib/src/main/java/at/bitfire/cert4android/CustomCertManager.kt Constructor changed to accept CertStore instead of Context; removed Android import
lib/src/test/java/at/bitfire/cert4android/CustomCertManagerTest.kt Migrated from androidTest with new TestCertStore implementation for unit testing
lib/src/androidTest/java/at/bitfire/cert4android/CustomCertManagerTest.kt Removed (moved to unit tests)
lib/src/androidTest/java/at/bitfire/cert4android/TestCertificates.kt Removed unused getSiteCertificates() method and Android-specific imports
lib/src/androidTest/java/at/bitfire/cert4android/OkhttpTest.kt Updated to use new constructor with CustomCertStore.getInstance()
sample-app/src/main/java/at/bitfire/cert4android/demo/MainActivity.kt Updated to use new constructor with named parameter certStore

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@sunkup sunkup marked this pull request as ready for review November 18, 2025 10:35
@sunkup sunkup requested a review from a team as a code owner November 18, 2025 10:35
Copy link
Member

@rfc2822 rfc2822 left a comment

Choose a reason for hiding this comment

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

Looks good!

It would have been possible to move the TestCertStore to a separate file.

@sunkup sunkup merged commit 42d883e into main Nov 19, 2025
6 of 7 checks passed
@sunkup sunkup deleted the 75-decouple-customcertmanager-from-android branch November 19, 2025 09:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactoring Quality improvement of existing functions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Decouple CustomCertManager from Android

2 participants