Konsist
GitHubSlack (kotlinlang)Twitter
  • 🚀GETTING STARTED
    • What is Konsist?
    • Getting Started
      • Add Konsist Dependency
      • Create First Konsist Test - Declaration Check
      • Create Secound Konsist Test - Architectural Check
    • Articles & Videos
  • ✅WRITING TESTS
    • Create The Scope
    • Declaration Filtering
    • Declaration Assertion
    • Architecture Assertion
    • Suppress Konsist Test
  • ✏️VERYFYING CODEBASE
    • Verify Classes
    • Verify Interfaces
    • Verify Functions
    • Verify Properties
    • Verify Generics
    • Verify Source Declarations
  • 📗FEATURES
    • Add Konsist Existing To Project (Baseline)
    • Debug Konsist Test
    • Declaration
    • Declaration Vs Property
    • Compiler Type Inference
    • Package Wildcard
    • Declaration References
    • Indirect Parents
    • Kotest Support
  • 🔍INSPIRATION
    • Starter Projects
    • Snippets
      • General Snippets
      • Android Snippets
      • Spring Snippets
      • Test Snippets
      • JUnit Snippets
      • Kotest Snippets
      • Architecture Snippets
      • Clean Architecture Snippets
      • Kotlin Serialization Snippets
      • Library Snippets
      • Generic Types Snippets
  • 🎓ADVANCED
    • Isolate Konsist Tests
    • Enable Full Command Line Logging
    • Dynamic Konsist Tests
      • Explicit Test Names
    • When Konsist API Is Not Enough
    • Additional JUnit5 Setup
    • Why There Are No Pre-defined Rules?
    • Konsist Snapshots
  • ❓HELP
    • Getting Help
    • Known Issues
      • java.lang.OutOfMemoryError: Java heap space
    • Compatibility
  • ℹ️OTHER
    • Changelog
    • Project Status
    • Contributing
    • Contributors
    • Assets And Logos
    • Open Source Licenses
    • Sponsor Konsist
Powered by GitBook
On this page
  • Verify Name
  • Verify Type
  • Verify Modifiers
  • Verify Annotations
  • Verify Accessors
  • Verify Initialization
  • Verify Delegates
  • Verify Visibility
  • Verify Mutability
Edit on GitHub
Export as PDF
  1. VERYFYING CODEBASE

Verify Properties

Properties can be checked for proper access modifiers, type declarations, and initialization patterns.

To verify properties start by querying all properties present in the project:

Konsist
.scopeFromProject()
.properties()
...

In practical scenarios you'll typically want to verify a specific subset of properties - such as those defined inside classes:

Konsist
.scopeFromProject()
.classes()
.properties()
...

Konsist allows you to verify multiple aspects of a properties. For a complete understanding of the available APIs, refer to the language reference documentation for .

Let's look at few examples.

Verify Name

Property names can be validated to ensure they follow project naming conventions and patterns.

Check if Boolean property has name starting with is:

...
.assertTrue { 
    it.type?.name == "Boolean" && it.hasNameStartingWith("is")
}

Verify Type

Property types can be validated to ensure type safety and conventions:

...
.assertTrue { 
    it.type?.name == "LocalDateTime"
}

Verify Modifiers

Property modifiers can be validated to ensure proper encapsulation:

...
.assertTrue { 
    it.hasLateinitModifier
}

Verify Annotations

Property annotations can be verified for presence and correct usage:

...
.assertTrue { 
    it.hasAnnotationOf(JsonProperty::class)
}

Verify Accessors

Getter and setter presence and implementation can be validated:

Check if property has getter:

...
.assertTrue { 
    it.hasGetter
}

Check if property has setter:

...
.assertTrue { 
    it.hasSetter
}

Verify Initialization

Property initialization can be verified:

...
.assertTrue { 
    it.isInitialized
}

Verify Delegates

Property delegates can be verified:

Check if property has lazy delegate:

...
.assertTrue { 
    it.hasDelegate("lazy") 
}

Verify Visibility

Property visibility scope can be validated:

Check if property has internal modifier:

...
.assertTrue { 
    it.isInternal
}

Verify Mutability

Property mutability can be checked.

Check if property is immutable:

...
.assertTrue { 
    it.isVal
}

Check if property is mutable:

...
.assertTrue { 
    it.isVar
}
PreviousVerify FunctionsNextVerify Generics

Last updated 5 months ago

✏️