Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename AccountStateRepository save to set function names #7175

Merged
merged 1 commit into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,27 @@ class InMemoryAccountStateRepository(
return state
}

override fun save(accountState: AccountState) {
override fun setState(accountState: AccountState) {
state = accountState
}

override fun saveEmailAddress(emailAddress: String) {
override fun setEmailAddress(emailAddress: String) {
state = state.copy(emailAddress = emailAddress)
}

override fun saveIncomingServerSettings(serverSettings: ServerSettings) {
override fun setIncomingServerSettings(serverSettings: ServerSettings) {
state = state.copy(incomingServerSettings = serverSettings)
}

override fun saveOutgoingServerSettings(serverSettings: ServerSettings) {
override fun setOutgoingServerSettings(serverSettings: ServerSettings) {
state = state.copy(outgoingServerSettings = serverSettings)
}

override fun saveAuthorizationState(authorizationState: AuthorizationState) {
override fun setAuthorizationState(authorizationState: AuthorizationState) {
state = state.copy(authorizationState = authorizationState)
}

override fun saveOptions(options: AccountOptions) {
override fun setOptions(options: AccountOptions) {
state = state.copy(options = options)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ interface AccountDomainContract {
interface AccountStateRepository {
fun getState(): AccountState

fun save(accountState: AccountState)
fun setState(accountState: AccountState)

fun saveEmailAddress(emailAddress: String)
fun setEmailAddress(emailAddress: String)

fun saveIncomingServerSettings(serverSettings: ServerSettings)
fun setIncomingServerSettings(serverSettings: ServerSettings)

fun saveOutgoingServerSettings(serverSettings: ServerSettings)
fun setOutgoingServerSettings(serverSettings: ServerSettings)

fun saveAuthorizationState(authorizationState: AuthorizationState)
fun setAuthorizationState(authorizationState: AuthorizationState)

fun saveOptions(options: AccountOptions)
fun setOptions(options: AccountOptions)

fun clear()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import com.fsck.k9.mail.AuthType
import com.fsck.k9.mail.ServerSettings

class PreviewAccountStateRepository : AccountDomainContract.AccountStateRepository {

override fun getState(): AccountState = AccountState(
emailAddress = "[email protected]",
incomingServerSettings = ServerSettings(
Expand All @@ -33,17 +34,17 @@ class PreviewAccountStateRepository : AccountDomainContract.AccountStateReposito
),
)

override fun save(accountState: AccountState) = Unit
override fun setState(accountState: AccountState) = Unit

override fun saveEmailAddress(emailAddress: String) = Unit
override fun setEmailAddress(emailAddress: String) = Unit

override fun saveIncomingServerSettings(serverSettings: ServerSettings) = Unit
override fun setIncomingServerSettings(serverSettings: ServerSettings) = Unit

override fun saveOutgoingServerSettings(serverSettings: ServerSettings) = Unit
override fun setOutgoingServerSettings(serverSettings: ServerSettings) = Unit

override fun saveAuthorizationState(authorizationState: AuthorizationState) = Unit
override fun setAuthorizationState(authorizationState: AuthorizationState) = Unit

override fun saveOptions(options: AccountOptions) = Unit
override fun setOptions(options: AccountOptions) = Unit

override fun clear() = Unit
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class InMemoryAccountStateRepositoryTest {
}

@Test
fun `should save state`() {
fun `should set state`() {
val testSubject = InMemoryAccountStateRepository(
AccountState(
uuid = "uuid",
Expand All @@ -58,56 +58,56 @@ class InMemoryAccountStateRepositoryTest {
),
)

testSubject.save(newState)
testSubject.setState(newState)

assertThat(testSubject.getState()).isEqualTo(newState)
}

@Test
fun `should save email address`() {
fun `should set email address`() {
val testSubject = InMemoryAccountStateRepository()

testSubject.saveEmailAddress("emailAddress")
testSubject.setEmailAddress("emailAddress")

assertThat(testSubject.getState().emailAddress)
.isEqualTo("emailAddress")
}

@Test
fun `should save incoming server settings`() {
fun `should set incoming server settings`() {
val testSubject = InMemoryAccountStateRepository()

testSubject.saveIncomingServerSettings(INCOMING_SERVER_SETTINGS)
testSubject.setIncomingServerSettings(INCOMING_SERVER_SETTINGS)

assertThat(testSubject.getState().incomingServerSettings)
.isEqualTo(INCOMING_SERVER_SETTINGS)
}

@Test
fun `should save outgoing server settings`() {
fun `should set outgoing server settings`() {
val testSubject = InMemoryAccountStateRepository()

testSubject.saveOutgoingServerSettings(OUTGOING_SERVER_SETTINGS)
testSubject.setOutgoingServerSettings(OUTGOING_SERVER_SETTINGS)

assertThat(testSubject.getState().outgoingServerSettings)
.isEqualTo(OUTGOING_SERVER_SETTINGS)
}

@Test
fun `should save authorization state`() {
fun `should set authorization state`() {
val testSubject = InMemoryAccountStateRepository()

testSubject.saveAuthorizationState(AuthorizationState("authorizationState"))
testSubject.setAuthorizationState(AuthorizationState("authorizationState"))

assertThat(testSubject.getState().authorizationState)
.isEqualTo(AuthorizationState("authorizationState"))
}

@Test
fun `should save options`() {
fun `should set options`() {
val testSubject = InMemoryAccountStateRepository()

testSubject.saveOptions(OPTIONS)
testSubject.setOptions(OPTIONS)

assertThat(testSubject.getState().options)
.isEqualTo(OPTIONS)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class IncomingServerSettingsViewModel(
}

if (!hasError) {
accountStateRepository.saveIncomingServerSettings(state.value.toServerSettings())
accountStateRepository.setIncomingServerSettings(state.value.toServerSettings())
navigateNext()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class OutgoingServerSettingsViewModel(
}

if (!hasError) {
accountStateRepository.saveOutgoingServerSettings(state.value.toServerSettings())
accountStateRepository.setOutgoingServerSettings(state.value.toServerSettings())
navigateNext()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class IncomingServerSettingsViewModelTest {
)
val turbines = turbinesWithInitialStateCheck(testSubject, State())

repository.save(accountState)
repository.setState(accountState)

testSubject.event(Event.LoadAccountState)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class OutgoingServerSettingsViewModelTest {
)
val turbines = turbinesWithInitialStateCheck(testSubject, State())

repository.save(accountState)
repository.setState(accountState)

testSubject.event(Event.LoadAccountState)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ abstract class BaseServerValidationViewModel(

private fun onOAuthResult(result: OAuthResult) {
if (result is OAuthResult.Success) {
accountStateRepository.saveAuthorizationState(result.authorizationState)
accountStateRepository.setAuthorizationState(result.authorizationState)
updateState {
it.copy(
needsAuthorization = false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class AccountSetupViewModel(

private fun changeToSetupStep(setupStep: SetupStep) {
if (setupStep == SetupStep.AUTO_CONFIG) {
accountStateRepository.saveAuthorizationState(AuthorizationState(null))
accountStateRepository.setAuthorizationState(AuthorizationState(null))
}

updateState {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ internal class AccountAutoDiscoveryViewModel(
private fun navigateBack() = emitEffect(Effect.NavigateBack)

private fun navigateNext(isAutomaticConfig: Boolean) {
accountStateRepository.save(state.value.toAccountState())
accountStateRepository.setState(state.value.toAccountState())

emitEffect(Effect.NavigateNext(isAutomaticConfig))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ internal class AccountOptionsViewModel(
}

if (!hasError) {
accountStateRepository.saveOptions(state.value.toAccountOptions())
accountStateRepository.setOptions(state.value.toAccountOptions())
navigateNext()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ class AccountSetupViewModelTest {
prop(State::setupStep).isEqualTo(SetupStep.OPTIONS)
}

accountStateRepository.save(expectedAccountState)
accountStateRepository.setState(expectedAccountState)

viewModel.event(AccountSetupContract.Event.OnNext)

Expand Down