1package com.peachpasswords.sync23import org.junit.Assert.assertEquals4import org.junit.Assert.assertFalse5import org.junit.Assert.assertTrue6import org.junit.Test789class RegistryTransactionTest {10 @Test11 fun failed_forward_commit_explicitly_restores_prior_state() {12 var state = "prior"13 val writes = mutableListOf<String>()1415 val applied = commitWithRollback("prior", "next", commit = { candidate ->16 writes += candidate17 state = candidate18 candidate != "next"19 })2021 assertFalse(applied)22 assertEquals("prior", state)23 assertEquals(listOf("next", "prior"), writes)24 }2526 @Test27 fun successful_forward_commit_does_not_run_rollback() {28 var state = "prior"29 val writes = mutableListOf<String>()3031 val applied = commitWithRollback("prior", "next", commit = { candidate ->32 writes += candidate33 state = candidate34 true35 })3637 assertTrue(applied)38 assertEquals("next", state)39 assertEquals(listOf("next"), writes)40 }41}