package com.peachpasswords.sync import org.junit.Assert.assertEquals import org.junit.Assert.assertFalse import org.junit.Assert.assertTrue import org.junit.Test /** Pure failure-injection coverage for the real SharedPreferences transaction helper. */ class RegistryTransactionTest { @Test fun failed_forward_commit_explicitly_restores_prior_state() { var state = "prior" val writes = mutableListOf() val applied = commitWithRollback("prior", "next", commit = { candidate -> writes += candidate state = candidate candidate != "next" }) assertFalse(applied) assertEquals("prior", state) assertEquals(listOf("next", "prior"), writes) } @Test fun successful_forward_commit_does_not_run_rollback() { var state = "prior" val writes = mutableListOf() val applied = commitWithRollback("prior", "next", commit = { candidate -> writes += candidate state = candidate true }) assertTrue(applied) assertEquals("next", state) assertEquals(listOf("next"), writes) } }