Skip to content

Commit

Permalink
Cover code generation from regressions (#130)
Browse files Browse the repository at this point in the history
This patch covers the code generated files from regressions
  • Loading branch information
MarcoSignoretto authored Oct 3, 2022
1 parent e77fd07 commit af73c24
Show file tree
Hide file tree
Showing 16 changed files with 1,257 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ All notable changes to this project will be documented in this file.
---

## master
* Adding test to cover code generation regression using Ksp

## 2.8.1
* Fixing double mock generation crash
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
* Copyright Careem, an Uber Technologies Inc. company
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.careem.mockingbird.kspsample

import com.careem.mockingbird.test.annotations.Mock
import org.junit.Test
import java.io.File
import kotlin.test.assertEquals

class GeneratedFilesTest {

@Mock
val pippoMock: PippoSample = PippoSampleMock()

@Mock
val outerInterface: OuterInterface = OuterInterfaceMock()

@Mock
val multipleGetterProperties: MultipleGetterProperties = MultipleGetterPropertiesMock()

@Mock
val mockWithExternalDependencies: MockWithExternalDependencies = MockWithExternalDependenciesMock()

@Mock
val mock1: Mock1 = Mock1Mock()

@Mock
val lambdaSample: LambdaSample = LambdaSampleMock()

@Mock
val javaTypes: JavaTypes = JavaTypesMock()

@Mock
private val internalSampleInterface: InternalSampleInterface = InternalSampleInterfaceMock()

@Mock
val interfaceWithGenerics: InterfaceWithGenerics = InterfaceWithGenericsMock()

@Mock
val innerInterface: InnerInterface = InnerInterfaceMock()

@Mock
val innerInnerInterface: InnerInnerInterface = InnerInnerInterfaceMock()

@Mock
val uiDelegate: UiDelegate<UiState> = UiDelegate_UiStateMock()

@Mock
val uiDelegate2Args: UiDelegate2Args<UiState, Value> = UiDelegate2Args_UiState_ValueMock()

@Test
fun testFileGeneration() {
val expectFolder = expectedCodeGenFolder()
val actualFolder = actualCodeGenFolder()

assertEquals(actualFolder.listFiles()!!.size, expectFolder.listFiles()!!.size)

expectFolder.listFiles()!!.forEach { expect ->
val actual = lookUpActual(actualFolder, expect)
assertEquals(expect.readText(), actual.readText())
}
}

private fun expectedCodeGenFolder(): File = File("src/jvmTest/resources/mocks/com/careem/mockingbird/kspsample")
private fun actualCodeGenFolder(): File = File("build/generated/ksp/jvm/jvmTest/kotlin/com/careem/mockingbird/kspsample")
private fun lookUpActual(actualFolder: File, expectFile: File): File {
return File("${actualFolder.path}/${expectFile.name}")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.careem.mockingbird.kspsample

import com.careem.mockingbird.test.Mock
import com.careem.mockingbird.test.mock
import com.careem.mockingbird.test.mockUnit
import com.careem.mockingbird.test.uuid
import kotlin.Int
import kotlin.String
import kotlin.Unit

public class InnerInnerInterfaceMock : InnerInnerInterface, Mock {
public override val uuid: String by uuid()

public override val yo3: Int
get() = mock(
methodName = Property.getYo3
)

public override fun deepFoo(deepArg: String): Unit {
return mockUnit(
methodName = Method.deepFoo,
arguments = mapOf(Arg.deepArg to deepArg)
)
}

public object Method {
public const val deepFoo: String = "deepFoo"
}

public object Arg {
public const val deepArg: String = "deepArg"
}

public object Property {
public const val getYo3: String = "getYo3"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package com.careem.mockingbird.kspsample

import com.careem.mockingbird.test.Mock
import com.careem.mockingbird.test.mock
import com.careem.mockingbird.test.mockUnit
import com.careem.mockingbird.test.uuid
import kotlin.Int
import kotlin.String
import kotlin.Unit

public class InnerInterfaceMock : InnerInterface, Mock {
public override val uuid: String by uuid()

public override var yo2: String
get() = mock(
methodName = Property.getYo2
)
set(`value`) {
return mockUnit(
methodName = Property.setYo2,
arguments = mapOf(Property.`value` to value)
)
}

public override val yo3: Int
get() = mock(
methodName = Property.getYo3
)

public override fun foo(fooArg: String): Unit {
return mockUnit(
methodName = Method.foo,
arguments = mapOf(Arg.fooArg to fooArg)
)
}

public override fun foo2(fooArg2: String): Unit {
return mockUnit(
methodName = Method.foo2,
arguments = mapOf(Arg.fooArg2 to fooArg2)
)
}

public override fun deepFoo(deepArg: String): Unit {
return mockUnit(
methodName = Method.deepFoo,
arguments = mapOf(Arg.deepArg to deepArg)
)
}

public object Method {
public const val foo: String = "foo"

public const val foo2: String = "foo2"

public const val deepFoo: String = "deepFoo"
}

public object Arg {
public const val fooArg: String = "fooArg"

public const val fooArg2: String = "fooArg2"

public const val deepArg: String = "deepArg"
}

public object Property {
public const val getYo2: String = "getYo2"

public const val setYo2: String = "setYo2"

public const val getYo3: String = "getYo3"

public const val `value`: String = "value"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package com.careem.mockingbird.kspsample

import com.careem.mockingbird.test.Mock
import com.careem.mockingbird.test.mock
import com.careem.mockingbird.test.mockUnit
import com.careem.mockingbird.test.uuid
import kotlin.Int
import kotlin.String
import kotlin.collections.List
import kotlin.collections.Map

public class InterfaceWithGenericsMock : InterfaceWithGenerics, Mock {
public override val uuid: String by uuid()

public override var g1: List<String>
get() = mock(
methodName = Property.getG1
)
set(`value`) {
return mockUnit(
methodName = Property.setG1,
arguments = mapOf(Property.`value` to value)
)
}

public override var g2: Map<String, Int>
get() = mock(
methodName = Property.getG2
)
set(`value`) {
return mockUnit(
methodName = Property.setG2,
arguments = mapOf(Property.`value` to value)
)
}

public override fun complexFoo(fooArg: List<Map<List<List<Int>>, List<String>>>):
List<List<String>> {
return mock(
methodName = Method.complexFoo,
arguments = mapOf(Arg.fooArg to fooArg)
)
}

public override fun foo(fooArg: List<List<Int>>): List<List<String>> {
return mock(
methodName = Method.foo,
arguments = mapOf(Arg.fooArg to fooArg)
)
}

public override fun foo(fooArg: Map<Int, String>): Map<String, Int> {
return mock(
methodName = Method.foo,
arguments = mapOf(Arg.fooArg to fooArg)
)
}

public object Method {
public const val complexFoo: String = "complexFoo"

public const val foo: String = "foo"
}

public object Arg {
public const val fooArg: String = "fooArg"
}

public object Property {
public const val getG1: String = "getG1"

public const val setG1: String = "setG1"

public const val getG2: String = "getG2"

public const val setG2: String = "setG2"

public const val `value`: String = "value"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.careem.mockingbird.kspsample

import com.careem.mockingbird.test.Mock
import com.careem.mockingbird.test.mockUnit
import com.careem.mockingbird.test.uuid
import kotlin.String
import kotlin.Unit

internal class InternalSampleInterfaceMock : InternalSampleInterface, Mock {
public override val uuid: String by uuid()

public override fun thisIsInternal(`param`: String): Unit {
return mockUnit(
methodName = Method.thisIsInternal,
arguments = mapOf(Arg.`param` to param)
)
}

public object Method {
public const val thisIsInternal: String = "thisIsInternal"
}

public object Arg {
public const val `param`: String = "param"
}

public object Property
}
Loading

0 comments on commit af73c24

Please sign in to comment.