Skip to content

Commit

Permalink
Update integration tests to work with k2
Browse files Browse the repository at this point in the history
  • Loading branch information
eygraber committed Feb 8, 2024
1 parent 05f8627 commit d7a56a6
Show file tree
Hide file tree
Showing 52 changed files with 1,283 additions and 1,183 deletions.
5 changes: 0 additions & 5 deletions build-logic/src/main/kotlin/NativeTargets.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,3 @@ val nativeTargets = arrayOf(
"tvosArm64", "tvosX64", "tvosSimulatorArm64",
"watchosArm32", "watchosArm64", "watchosX64", "watchosSimulatorArm64",
)

val nativeKspTestConfigurations = nativeTargets.map {
@Suppress("DEPRECATION")
"ksp${it.capitalize()}Test"
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
package me.tatarka.inject.test

import me.tatarka.inject.annotations.Component
import kotlin.test.Test

@Component abstract class CompanionComponent {
companion object
}

class CompanionTest {
@Test
fun creates_a_component_with_a_companion() {
CompanionComponent.create()
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package me.tatarka.inject.test

import me.tatarka.inject.annotations.Component

@Component
abstract class CompanionComponent {
companion object
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,49 +7,6 @@ import me.tatarka.inject.annotations.Component
import me.tatarka.inject.annotations.Provides
import kotlin.test.Test

abstract class AbstractParentComponent {
@Provides
abstract fun foo(): NamedFoo

abstract val bar: INamedBar
}

@Component
abstract class ParentComponentImpl1 : AbstractParentComponent() {
override fun foo(): NamedFoo = NamedFoo("parent1")

@Provides
fun bar2(): INamedBar = NamedBar("parent1")
}

@Component
abstract class ParentComponentImpl2 : AbstractParentComponent() {
override fun foo(): NamedFoo = NamedFoo("parent2")

@Provides
fun bar2(): INamedBar = NamedBar("parent2")
}

@Component
abstract class AbstractParentChildComponent(@Component val parent: AbstractParentComponent) {
abstract val foo: NamedFoo
abstract val bar: INamedBar
}

@CustomScope
abstract class ScopedAbstractParentComponent

@Component
abstract class ScopedParentComponentImpl1 : ScopedAbstractParentComponent()

@Component
abstract class ScopedParentComponentImpl2 : ScopedAbstractParentComponent()

@Component
abstract class ScopedAbstractParentChildComponent(@Component val parent: ScopedAbstractParentComponent) {
abstract val bar: CustomScopeBar
}

class AbstractComponentTest {
@Test
fun generates_a_component_that_provides_a_dep_from_an_abstract_parent_component() {
Expand All @@ -74,4 +31,4 @@ class AbstractComponentTest {
assertThat(component1.bar).isNotNull()
assertThat(component2.bar).isNotNull()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,97 +11,6 @@ import me.tatarka.inject.annotations.Inject
import me.tatarka.inject.annotations.Provides
import kotlin.test.Test

@Inject
class AssistedBar(val foo: Foo, @Assisted val name: String)

@Component
abstract class AssistedComponent {
abstract val barFactory: (name: String) -> AssistedBar
}

@Inject
data class AssistedBarArity2(@Assisted val arg1: String, @Assisted val arg2: String)

@Inject
data class AssistedBarArity3(@Assisted val arg1: String, @Assisted val arg2: String, @Assisted val arg3: String)

@Inject
data class AssistedBarArity4(
@Assisted val arg1: String,
@Assisted val arg2: String,
@Assisted val arg3: String,
@Assisted val arg4: String,
)

@Component
abstract class AssistedArityComponent {
abstract val arity2: (arg1: String, arg2: String) -> AssistedBarArity2
abstract val arity3: (arg1: String, arg2: String, arg3: String) -> AssistedBarArity3
abstract val arity4: (arg1: String, arg2: String, arg3: String, arg4: String) -> AssistedBarArity4
}

@Inject
class NullableAssistedBar(@Assisted val foo: Foo?)

@Component
abstract class NullableAssistedComponent {
abstract val barProvider: (Foo?) -> NullableAssistedBar
}

@Inject
data class Person(val house: House.Factory, @Assisted val name: String) {

@Inject
class Factory(
val create: (String) -> Person,
)
}

@Inject
data class House(@Assisted val bricks: Int) {
@Inject
class Factory(val create: (Int) -> House)
}

@Component
abstract class NestedNestedFunctionComponent {
abstract val personFactory: Person.Factory
}

@Inject
data class OrderedAssistedBar(@Assisted val one: String, val two: Foo, @Assisted val three: String)

@Component
abstract class OrderedAssistedComponent {
abstract val orderedBar: (String, String) -> OrderedAssistedBar
}

@Inject
data class DefaultAssistedBar(@Assisted val one: String, @Assisted val two: Int = 2)

@Component
abstract class DefaultAssistedComponent {
abstract val withoutDefault: (String, Int) -> DefaultAssistedBar
abstract val withDefault: (String) -> DefaultAssistedBar
}

@Inject
class UnrelatedDependency(val someString: String)

@Inject
class AssistedAndUnrelatedDep(
@Assisted val assistedString: String,
val unrelatedDependency: UnrelatedDependency,
)

@Component
abstract class AssistedWithOtherDependency {
abstract val test: (String) -> AssistedAndUnrelatedDep

@Provides
fun string() = "provided"
}

class AssistedTest {

@Test
Expand Down Expand Up @@ -162,4 +71,4 @@ class AssistedTest {
.isEqualTo("provided")
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,6 @@ import assertk.assertions.isNotNull
import me.tatarka.inject.annotations.Component
import kotlin.test.Test

@Component abstract class Component1 {
abstract val foo: Foo
}

@Component abstract class Component2 {
abstract val bar: Bar
}

@Component interface Component3 {
val bar: Bar
}

@Component interface Component4 {
fun foo(): Foo
}

class ComponentTest {

@Test
Expand Down Expand Up @@ -52,4 +36,4 @@ class ComponentTest {

assertThat(component.foo()).isNotNull()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,6 @@ import assertk.assertions.isEqualTo
import me.tatarka.inject.annotations.Component
import kotlin.test.Test

@Component abstract class DefaultArgComponent(
val required1: String,
val optional: String = "default",
val required2: String
)

class DefaultArgTest {
@Test
fun generates_a_component_with_a_create_that_skips_default_args() {
Expand All @@ -24,4 +18,4 @@ class DefaultArgTest {
assertThat(componentDefault.optional).isEqualTo("default")
assertThat(componentDefault.required2).isEqualTo("three")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,61 +7,6 @@ import me.tatarka.inject.annotations.Inject
import me.tatarka.inject.annotations.Provides
import kotlin.test.Test

@Inject
class FooWithDefault(
override val name: String = "default",
override val fn: () -> String = { "default" },
override val lazy: Lazy<String> = lazy { "default" },
) : IFooWithDefault

interface IFooWithDefault {
val name: String
val fn: () -> String
val lazy: Lazy<String>
}

typealias fooWithDefaultFun = () -> IFooWithDefault

@Inject
fun fooWithDefaultFun(
name: String = "default",
fn: () -> String = { "default" },
lazy: Lazy<String> = lazy { "default" },
): IFooWithDefault {
return FooWithDefault(name, fn, lazy)
}

@Component
abstract class UseDefaultComponent {
abstract val foo: FooWithDefault
abstract val iFoo: IFooWithDefault
abstract val fooFun: fooWithDefaultFun

@Provides
fun iFoo(
name: String = "default",
fn: () -> String = { "default" },
lazy: Lazy<String> = lazy { "default" },
): IFooWithDefault = FooWithDefault(name, fn, lazy)
}

@Component
abstract class OverrideDefaultComponent {
abstract val foo: FooWithDefault
abstract val iFoo: IFooWithDefault
abstract val fooFun: fooWithDefaultFun

val name: String
@Provides get() = "override"

@Provides
fun iFoo(
name: String = "default",
fn: () -> String = { "default" },
lazy: Lazy<String> = lazy { "default" },
): IFooWithDefault = FooWithDefault(name, fn, lazy)
}

class DefaultParamTest {
@Test
fun generates_a_component_that_uses_a_default_value_for_a_param() {
Expand Down Expand Up @@ -92,4 +37,4 @@ class DefaultParamTest {
assertThat(component.fooFun().fn()).isEqualTo("override")
assertThat(component.fooFun().lazy.value).isEqualTo("override")
}
}
}
Loading

0 comments on commit d7a56a6

Please sign in to comment.