Skip to content

Commit

Permalink
Update Gradle and Kotlin
Browse files Browse the repository at this point in the history
  • Loading branch information
robertzhao2002 committed Jul 19, 2024
1 parent 2944b64 commit c4fc1a9
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 62 deletions.
15 changes: 4 additions & 11 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
buildscript {
ext.kotlin_version = '1.3.21'
ext.kotlin_version = '2.0.0'

repositories {
mavenCentral()
jcenter()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.vanniktech:gradle-maven-publish-plugin:0.8.0'
classpath 'com.vanniktech:gradle-maven-publish-plugin:0.29.0'
}
}

Expand All @@ -22,17 +22,10 @@ repositories {
}

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"

testImplementation 'junit:junit:4.12'
testImplementation 'com.nhaarman.mockitokotlin2:mockito-kotlin:2.1.0'
testImplementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
testImplementation 'org.assertj:assertj-core:3.11.1'
}

compileKotlin {
kotlinOptions.jvmTarget = JavaVersion.VERSION_1_8
}
compileTestKotlin {
kotlinOptions.jvmTarget = JavaVersion.VERSION_1_8
testImplementation "com.google.truth:truth:1.4.4"
}
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.3.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-all.zip
2 changes: 1 addition & 1 deletion src/main/kotlin/com/tinder/StateMachine.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class StateMachine<STATE : Any, EVENT : Any, SIDE_EFFECT : Any> private construc
private val graph: Graph<STATE, EVENT, SIDE_EFFECT>
) {

private val stateRef = AtomicReference<STATE>(graph.initialState)
private val stateRef = AtomicReference(graph.initialState)

val state: STATE
get() = stateRef.get()
Expand Down
99 changes: 50 additions & 49 deletions src/test/kotlin/com/tinder/StateMachineTest.kt
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package com.tinder

import com.google.common.truth.Truth.assertThat
import com.nhaarman.mockitokotlin2.mock
import com.nhaarman.mockitokotlin2.then
import org.assertj.core.api.Assertions.assertThat
import org.assertj.core.api.Assertions.assertThatIllegalArgumentException
import org.assertj.core.api.Assertions.assertThatIllegalStateException
import org.junit.Assert.assertThrows
import org.junit.Test
import org.junit.experimental.runners.Enclosed
import org.junit.runner.RunWith
import java.lang.IllegalArgumentException
import java.lang.IllegalStateException

@RunWith(Enclosed::class)
internal class StateMachineTest {
Expand Down Expand Up @@ -42,6 +43,7 @@ internal class StateMachineTest {
SideEffect.LogFrozen -> logger.log(ON_FROZEN_MESSAGE)
SideEffect.LogVaporized -> logger.log(ON_VAPORIZED_MESSAGE)
SideEffect.LogCondensed -> logger.log(ON_CONDENSED_MESSAGE)
null -> Unit
}
}
}
Expand Down Expand Up @@ -127,23 +129,23 @@ internal class StateMachineTest {
const val ON_CONDENSED_MESSAGE = "I condensed"

sealed class State {
object Solid : State()
object Liquid : State()
object Gas : State()
data object Solid : State()
data object Liquid : State()
data object Gas : State()
}

sealed class Event {
object OnMelted : Event()
object OnFrozen : Event()
object OnVaporized : Event()
object OnCondensed : Event()
data object OnMelted : Event()
data object OnFrozen : Event()
data object OnVaporized : Event()
data object OnCondensed : Event()
}

sealed class SideEffect {
object LogMelted : SideEffect()
object LogFrozen : SideEffect()
object LogVaporized : SideEffect()
object LogCondensed : SideEffect()
data object LogMelted : SideEffect()
data object LogFrozen : SideEffect()
data object LogVaporized : SideEffect()
data object LogCondensed : SideEffect()
}

interface Logger {
Expand Down Expand Up @@ -336,22 +338,22 @@ internal class StateMachineTest {

sealed class State {
data class Locked(val credit: Int) : State()
object Unlocked : State()
data object Unlocked : State()
data class Broken(val oldState: State) : State()
}

sealed class Event {
data class InsertCoin(val value: Int) : Event()
object AdmitPerson : Event()
object MachineDidFail : Event()
object MachineRepairDidComplete : Event()
data object AdmitPerson : Event()
data object MachineDidFail : Event()
data object MachineRepairDidComplete : Event()
}

sealed class Command {
object SoundAlarm : Command()
object CloseDoors : Command()
object OpenDoors : Command()
object OrderRepair : Command()
data object SoundAlarm : Command()
data object CloseDoors : Command()
data object OpenDoors : Command()
data object OrderRepair : Command()
}
}
}
Expand Down Expand Up @@ -502,10 +504,9 @@ internal class StateMachineTest {
@Test
fun transition_givenUndeclaredState_shouldThrowIllegalStateException() {
// Then
assertThatIllegalStateException()
.isThrownBy {
stateMachine.transition(Event.E4)
}
assertThrows(IllegalStateException::class.java) {
stateMachine.transition(Event.E4)
}
}
}

Expand All @@ -514,31 +515,29 @@ internal class StateMachineTest {
@Test
fun create_givenNoInitialState_shouldThrowIllegalArgumentException() {
// Then
assertThatIllegalArgumentException().isThrownBy {
assertThrows(IllegalArgumentException::class.java) {
StateMachine.create<State, Event, SideEffect> {}
}
}
}

private companion object {
private sealed class State {
object A : State()
object B : State()
object C : State()
object D : State()
data object A : State()
data object B : State()
data object C : State()
data object D : State()
}

private sealed class Event {
object E1 : Event()
object E2 : Event()
object E3 : Event()
object E4 : Event()
data object E1 : Event()
data object E2 : Event()
data object E3 : Event()
data object E4 : Event()
}

private sealed class SideEffect {
object SE1 : SideEffect()
object SE2 : SideEffect()
object SE3 : SideEffect()
data object SE1 : SideEffect()
}
}
}
Expand Down Expand Up @@ -569,12 +568,12 @@ internal class StateMachineTest {
transitionTo(STATE_D)
}
}
state(STATE_B) {
on(EVENT_3) {
state<String>(STATE_B) {
on<Int>(EVENT_3) {
transitionTo(STATE_C, SIDE_EFFECT_1)
}
}
state(STATE_C) {
state<String>(STATE_C) {
onEnter(onStateCEnterListener1)
onEnter(onStateCEnterListener2)
}
Expand Down Expand Up @@ -680,10 +679,9 @@ internal class StateMachineTest {
@Test
fun transition_givenUndeclaredState_shouldThrowIllegalStateException() {
// Then
assertThatIllegalStateException()
.isThrownBy {
stateMachine.transition(EVENT_4)
}
assertThrows(IllegalStateException::class.java) {
stateMachine.transition(EVENT_4)
}
}
}

Expand All @@ -692,7 +690,7 @@ internal class StateMachineTest {
@Test
fun create_givenNoInitialState_shouldThrowIllegalArgumentException() {
// Then
assertThatIllegalArgumentException().isThrownBy {
assertThrows(IllegalArgumentException::class.java) {
StateMachine.create<String, Int, String> {}
}
}
Expand All @@ -713,9 +711,12 @@ internal class StateMachineTest {
@Test
fun transition_givenMissingDestinationStateDefinition_shouldThrowIllegalStateExceptionWithStateName() {
// Then
assertThatIllegalStateException()
.isThrownBy { stateMachine.transition(EVENT_1) }
.withMessage("Missing definition for state ${STATE_B.javaClass.simpleName}!")
val exception = assertThrows(IllegalStateException::class.java) {
stateMachine.transition(EVENT_1)
}
assertThat(exception.message).isEqualTo(
"Missing definition for state ${STATE_B.javaClass.simpleName}!"
)
}
}

Expand Down

0 comments on commit c4fc1a9

Please sign in to comment.