Skip to content

Latest commit

 

History

History
65 lines (56 loc) · 1.46 KB

generic-types-snippets.md

File metadata and controls

65 lines (56 loc) · 1.46 KB

Generic Types Snippets

1. All Generic Return Types Contain X In Their Name

@Test
fun `all generic return types contain X in their name`() {
    Konsist
        .scopeFromProduction()
        .functions()
        .returnTypes
        .withGeneric()
        .assertTrue { it.hasNameContaining("X") }
}

2. Property Generic Type Does Not Contains Star Projection

@Test
fun `property generic type does not contains star projection`() {
    Konsist
        .scopeFromProduction()
        .properties()
        .types
        .assertFalse { type ->
            type
                .typeArguments
                ?.flatten()
                ?.any { it.isStarProjection }
        }
}

3. All Generic Return Types Contain Kotlin Collection Type Argument

@Test
fun `all generic return types contain Kotlin collection type argument`() {
    Konsist
        .scopeFromProduction()
        .functions()
        .returnTypes
        .withGeneric()
        .typeArguments
        .assertTrue { it.sourceDeclaration?.isKotlinCollectionType }
}

4. Function Parameter Has Generic Type Argument With Name Ending With Repository

@Test
fun `function parameter has generic type argument with name ending with 'Repository'`() {
    Konsist
        .scopeFromProduction()
        .functions()
        .parameters
        .types
        .withGeneric()
        .sourceDeclarations()
        .assertFalse { it.hasNameEndingWith("Repository") }
}