Home > Development > Testing > ---
RoundViewModelTestAdapter Migration Guide
Purpose
This guide helps migrate tests from deprecated RoundViewModel scoring methods to LiveScoringViewModel using the test adapter pattern.
Quick Migration Steps
1. Add Imports
import com.archeryapprentice.test.support.RoundViewModelTestAdapter
import com.archeryapprentice.test.support.ViewModelFactory2. Add LiveScoringViewModel and Adapter Setup
class YourTest {
private lateinit var viewModel: RoundViewModel
private lateinit var liveScoringViewModel: LiveScoringViewModel
private lateinit var testAdapter: RoundViewModelTestAdapter
@Before
fun setup() {
// ... existing setup ...
viewModel = RoundViewModel(
application = mockk(relaxed = true),
repositoryFactory = mockRepositoryFactory
)
// Create LiveScoringViewModel for new scoring architecture
liveScoringViewModel = ViewModelFactory.createLiveScoringViewModel(
application = mockk(relaxed = true),
roundRepository = mockRoundRepository
)
// Create test adapter to route deprecated methods to LiveScoringViewModel
testAdapter = RoundViewModelTestAdapter(viewModel, liveScoringViewModel)
}
}3. Replace Deprecated Method Calls
| Old (Deprecated) | New (Adapter) |
|---|---|
viewModel.addArrowScore(10, false) | testAdapter.addArrowScore(10, false) |
viewModel.completeCurrentEnd() | testAdapter.completeCurrentEnd() |
viewModel.finalizeEnd(participantId, endNumber) | testAdapter.finalizeEnd(participantId, endNumber) |
4. Access State Through Adapter
// State access remains the same
val session = testAdapter.scoringSession.value
val progress = testAdapter.roundVM.someOtherPropertyFiles That Need Migration
Based on analysis of deprecated method usage:
- PostRefactorIntegrationTest.kt - 7 calls
- EndCompletionBehaviorComparisonTest.kt - 5 calls
- GuAdvancementTest.kt - 5 calls
- MultiParticipantIntegrationTest.kt - 3 calls
- EndSummaryKeyUniquenessTest.kt - (count needed)
- FailingTestDebugTest.kt - (count needed)
- MPEndCompletionFlowValidationTest.kt - (count needed)
- LiveScoringViewModelTest.kt - (count needed)
Example Migration (Already Complete)
SingleParticipantFinalEndCompletionRegressionTest.kt has been migrated as a reference example:
Before:
viewModel.addArrowScore(10, false)
viewModel.addArrowScore(9, false)
viewModel.addArrowScore(8, false)
viewModel.completeCurrentEnd()After:
testAdapter.addArrowScore(10, false)
testAdapter.addArrowScore(9, false)
testAdapter.addArrowScore(8, false)
testAdapter.completeCurrentEnd()Benefits of Adapter Pattern
- Incremental Migration: Tests can be migrated one at a time
- Working State: Each migration leaves tests in working condition
- Clear Path: Obvious migration path to eventual LiveScoringViewModel usage
- Rollback Safety: Easy to revert changes if needed
- Testing New Architecture: Validates LiveScoringViewModel functionality in test context
Future Cleanup
After all tests are migrated to the adapter:
- Remove deprecated methods from RoundViewModel
- Gradually replace adapter usage with direct LiveScoringViewModel calls
- Remove adapter when no longer needed
- Complete the ViewModel refactoring
Notes
- Tests should continue to pass after migration (existing failures may remain)
- Adapter provides same interface as original deprecated methods
- LiveScoringViewModel state and RoundViewModel state may differ during transition
- Focus on mechanical replacement first, logic validation second
Related Documentation:
- See Test-Failure-Analysis for state synchronization issues
- See Service-Architecture for ViewModel refactoring architecture