Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[*.{kt,kts}]
ktlint_standard_no-wildcard-imports = disabled
ktlint_standard_value-argument-comment = disabled
ktlint_standard_value-parameter-comment = disabled
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -182,3 +182,4 @@ gradle-app.setting

# End of https://www.toptal.com/developers/gitignore/api/gradle,kotlin,java,intellij
/local.properties
/.kotlin/
3 changes: 3 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions LICENSE-2.0.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@
<link href="/css/min.bootstrap.css" rel="stylesheet">
<link href="/css/styles.css" rel="stylesheet">
<style>
.headerlink {
visibility: hidden;
}
dt:hover > .headerlink, p:hover > .headerlink, td:hover > .headerlink, h1:hover > .headerlink, h2:hover > .headerlink, h3:hover > .headerlink, h4:hover > .headerlink, h5:hover > .headerlink, h6:hover > .headerlink {
visibility: visible
}
.headerlink {
visibility: hidden;
}
dt:hover > .headerlink, p:hover > .headerlink, td:hover > .headerlink, h1:hover > .headerlink, h2:hover > .headerlink, h3:hover > .headerlink, h4:hover > .headerlink, h5:hover > .headerlink, h6:hover > .headerlink {
visibility: visible
}

</style>

Expand Down
30 changes: 8 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,28 +61,14 @@ README.

### Adding the dependency:

To add this library as a dependency you need to:

* Add the github package repo in your `build.gradle`:

```groovy
repositories {
maven {
url = "https://maven.pkg.github.com/alt236/codeplasterage"
}
}
```

* Add the dependency itself:
This library is hosted on Maven Central so just add it:

```groovy
dependencies {
testImplementation 'uk.co.alt236:codeplasterage:{latest-version}'
testImplementation 'dev.alt236:codeplasterage:{latest-version}'
}
```

You can find the latest version here: https://github.com/alt236/codeplasterage/packages/

## Configuration

Tests can be configured on both class and method level via the `@Config` annotation.
Expand All @@ -107,12 +93,12 @@ There are two parts in the config, the inclusion/exclusion filters and general c

There are four different filters you can use to target (and exclude classes). They can be all be used at the same time.

| Field Name | Priority | Input | Example |
|----------------------------|------------|--------------------------------------|--------------------------------------------|
| `forceIncludeClassNames` | 1, Highest | Array of fully qualified class names | `uk.co.alt236.codeplasteragetestapp.FOO$1` |
| `forceExcludeClassNames` | 2 | Array of fully qualified class names | `uk.co.alt236.codeplasteragetestapp.FOO$1` |
| `excludeClassNamePatterns` | 3 | Array of RegEx Pattern | `.*codeplasteragetestapp.*` |
| `includeClassNamePatterns` | 4, Lowest | Array of RegEx Pattern | `.*codeplasteragetestapp.*` |
| Field Name | Priority | Input | Example |
|----------------------------|------------|--------------------------------------|-----------------------------------------|
| `forceIncludeClassNames` | 1, Highest | Array of fully qualified class names | `dev.alt236codeplasteragetestapp.FOO$1` |
| `forceExcludeClassNames` | 2 | Array of fully qualified class names | `dev.alt236codeplasteragetestapp.FOO$1` |
| `excludeClassNamePatterns` | 3 | Array of RegEx Pattern | `.*codeplasteragetestapp.*` |
| `includeClassNamePatterns` | 4, Lowest | Array of RegEx Pattern | `.*codeplasteragetestapp.*` |

Note 1: It is always better to add the patterns for your own code in `includeClassNamePatterns` instead of just running
everything. Otherwise, any 3rd party libraries included in your project will be instantiated and many of them do no not
Expand Down
16 changes: 10 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
plugins {
id 'java'
id "org.jetbrains.kotlin.jvm" version "${kotlin_version}"
id "org.jlleitschuh.gradle.ktlint" version "${jlleitschuh_ktlint_version}"
id 'com.adarshr.test-logger' version "${test_logger_version}"
id 'org.jetbrains.kotlinx.kover' version "${kover_version}"
alias(libs.plugins.kotlin.jvm) apply false
alias(libs.plugins.kotlin.kapt) apply false
alias(libs.plugins.gradle.ktlint)
alias(libs.plugins.testlogger)
alias(libs.plugins.kover)
}

apply from: "$rootDir/buildsystem/kover.gradle"
apply from: "$rootDir/buildsystem/printcoverage.gradle"

group = "uk.co.alt236.codeplasterage"
version = "1.0-SNAPSHOT"
group = "dev.alt236"
version = "0.0.1-SNAPSHOT"

repositories {
mavenCentral()
Expand All @@ -28,4 +29,7 @@ subprojects {
showStandardStreams true
}

ktlint {
version.set("1.4.1")
}
}
116 changes: 61 additions & 55 deletions codeplasterage/build.gradle
Original file line number Diff line number Diff line change
@@ -1,81 +1,87 @@
import com.vanniktech.maven.publish.SonatypeHost

plugins {
id 'java'
id 'kotlin'
id 'maven-publish'
id 'java-library'
alias(libs.plugins.kotlin.jvm)
alias(libs.plugins.kotlin.kapt)
alias(libs.plugins.vanniktech.maven.publish)
}

def project_name = "Code Plasterage"
def github_owner_and_repo = "alt236/codeplasterage"
def group_id = 'uk.co.alt236'
def group_id = 'dev.alt236'
def artifact_id = 'codeplasterage'
def artifact_version = '1.1-SNAPSHOT'
def artifact_version = '2.0.0'

group group_id
version artifact_version

repositories {
mavenCentral()
gradlePluginPortal()
}

publishing {
publications {
mavenJava(MavenPublication) {
artifactId = artifact_id
groupId = group_id
version = artifact_version
dependencies {
implementation libs.commons.lang3
implementation libs.kotlin.reflect
implementation libs.guava
implementation libs.kotlin.reflect
implementation libs.junit4

testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1'
testImplementation 'org.junit.jupiter:junit-jupiter-params:5.8.1'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1'
}

test {
useJUnitPlatform()
}

ktlint {
disabledRules = ["no-wildcard-imports"]
}

from components.java
mavenPublishing { // This is for the 'vanniktech-maven-publish' plugin
var automaticRelease = false
publishToMavenCentral(SonatypeHost.CENTRAL_PORTAL, automaticRelease)
signAllPublications()

pom {
name = project_name
description = 'A library to artificially inflate code coverage stats via reflection'
url = "https://github.com/$github_owner_and_repo"
licenses {
license {
name = 'The Apache License, Version 2.0'
url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
}
}
developers {
developer {
id = 'alt236'
name = 'Alexandros Schillings'
}
}
scm {
url = "https://github.com/$github_owner_and_repo"
}
coordinates(group_id, artifact_id, artifact_version)
pom {
name = project_name
description = 'A library to artificially inflate code coverage stats via reflection'
url = "https://github.com/$github_owner_and_repo"
licenses {
license {
name = 'The Apache License, Version 2.0'
url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
distribution = "http://www.apache.org/licenses/LICENSE-2.0.txt"
}
}
}
repositories {
maven {
name = project_name.replace(" ", "")
url = uri("https://maven.pkg.github.com/$github_owner_and_repo")
credentials {
username = project.findProperty("gpr.user")
?: project.findProperty("GITHUB_ALT236_PUBLISH_USERNAME")
?: System.getenv("GITHUB_ALT236_PUBLISH_USERNAME")
password = project.findProperty("gpr.key")
?: project.findProperty("GITHUB_ALT236_PUBLISH_KEY")
?: System.getenv("GITHUB_ALT236_PUBLISH_KEY")
developers {
developer {
id = 'alt236'
name = 'Alexandros Schillings'
url = "https://github.com/alt236/"
}
}
scm {
url = "https://github.com/$github_owner_and_repo"
}
}
}

dependencies {
implementation "org.jetbrains.kotlin:kotlin-reflect:${kotlin_version}"
implementation 'org.apache.commons:commons-lang3:3.12.0'
implementation "com.google.guava:guava:31.1-jre"
implementation "junit:junit:4.13.2"

testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1'
testImplementation 'org.junit.jupiter:junit-jupiter-params:5.8.1'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1'
}
// Fix for dependency order issue: https://github.com/vanniktech/gradle-maven-publish-plugin/issues/814
afterEvaluate {
var sigDependentTasks = [
"publishMavenPublicationToMavenCentralRepository",
]

test {
useJUnitPlatform()
for (taskName in sigDependentTasks) {
tasks.named(taskName) {
println("Found: " + it.name)
dependsOn("signMavenPublication")
}
}
}

Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
package uk.co.alt236.codeplasterage

package dev.alt236.codeplasterage

import dev.alt236.codeplasterage.config.ConfigFactory
import dev.alt236.codeplasterage.config.TesterConfig
import dev.alt236.codeplasterage.datafactory.CustomDataFactoryFactory
import dev.alt236.codeplasterage.datafactory.DummyDataFactory
import dev.alt236.codeplasterage.datafactory.stats.DataFactoryRequestRecorder
import dev.alt236.codeplasterage.datafactory.stats.DataFactoryStatsPrinter
import dev.alt236.codeplasterage.reflection.classfinder.ClassFinder
import dev.alt236.codeplasterage.reflection.instantiation.Instantiator
import dev.alt236.codeplasterage.testers.reflection.EqualsTester
import dev.alt236.codeplasterage.testers.reflection.HashCodeTester
import dev.alt236.codeplasterage.testers.reflection.MethodCallingTester
import dev.alt236.codeplasterage.testers.reflection.ToStringTester
import org.junit.Ignore
import org.junit.Test
import org.junit.runner.Description
import org.junit.runner.Runner
import org.junit.runner.notification.Failure
import org.junit.runner.notification.RunNotifier
import uk.co.alt236.codeplasterage.config.ConfigFactory
import uk.co.alt236.codeplasterage.config.TesterConfig
import uk.co.alt236.codeplasterage.datafactory.CustomDataFactoryFactory
import uk.co.alt236.codeplasterage.datafactory.DummyDataFactory
import uk.co.alt236.codeplasterage.datafactory.stats.DataFactoryRequestRecorder
import uk.co.alt236.codeplasterage.datafactory.stats.DataFactoryStatsPrinter
import uk.co.alt236.codeplasterage.reflection.classfinder.ClassFinder
import uk.co.alt236.codeplasterage.reflection.instantiation.Instantiator
import uk.co.alt236.codeplasterage.testers.reflection.EqualsTester
import uk.co.alt236.codeplasterage.testers.reflection.HashCodeTester
import uk.co.alt236.codeplasterage.testers.reflection.MethodCallingTester
import uk.co.alt236.codeplasterage.testers.reflection.ToStringTester
import java.lang.reflect.Method

class CodeplasterageTestRunner(private val testClass: Class<Any>) : Runner() {
class CodeplasterageTestRunner(
private val testClass: Class<Any>,
) : Runner() {
private val dataFactoryStatsPrinter = DataFactoryStatsPrinter()
private val configFactory = ConfigFactory()

override fun getDescription(): Description {
return Description.createTestDescription(testClass, "***** Code Plasterage Test Runner *****")
}
override fun getDescription(): Description = Description.createTestDescription(testClass, "***** Code Plasterage Test Runner *****")

override fun run(notifier: RunNotifier) {
println("${CodeplasterageTestRunner::class.java.simpleName}: Running tests on $testClass")
Expand Down Expand Up @@ -85,7 +85,7 @@ class CodeplasterageTestRunner(private val testClass: Class<Any>) : Runner() {

private fun createAssembleDummyDataFactory(
config: TesterConfig,
requestRecorded: DataFactoryRequestRecorder
requestRecorded: DataFactoryRequestRecorder,
): DummyDataFactory {
val extraFactoriesFactory = CustomDataFactoryFactory(config.debug)
val extraFactories = extraFactoriesFactory.createSubDataFactories(config.customDummyDataFactories)
Expand All @@ -96,7 +96,7 @@ class CodeplasterageTestRunner(private val testClass: Class<Any>) : Runner() {
dummyDataFactory: DummyDataFactory,
config: TesterConfig,
notifier: RunNotifier,
method: Method
method: Method,
) {
val instantiator = Instantiator(dummyDataFactory, config.debug)

Expand All @@ -111,7 +111,7 @@ class CodeplasterageTestRunner(private val testClass: Class<Any>) : Runner() {
dummyDataFactory: DummyDataFactory,
config: TesterConfig,
notifier: RunNotifier,
method: Method
method: Method,
) {
val instantiator = Instantiator(dummyDataFactory, config.debug)

Expand All @@ -126,7 +126,7 @@ class CodeplasterageTestRunner(private val testClass: Class<Any>) : Runner() {
dummyDataFactory: DummyDataFactory,
config: TesterConfig,
notifier: RunNotifier,
method: Method
method: Method,
) {
val instantiator = Instantiator(dummyDataFactory, config.debug)

Expand All @@ -141,7 +141,7 @@ class CodeplasterageTestRunner(private val testClass: Class<Any>) : Runner() {
dummyDataFactory: DummyDataFactory,
config: TesterConfig,
notifier: RunNotifier,
method: Method
method: Method,
) {
val instantiator = Instantiator(dummyDataFactory, config.debug)

Expand All @@ -152,7 +152,11 @@ class CodeplasterageTestRunner(private val testClass: Class<Any>) : Runner() {
tester.test(classes, notifier, method)
}

private fun runTest(notifier: RunNotifier, classInstance: Any, method: Method) {
private fun runTest(
notifier: RunNotifier,
classInstance: Any,
method: Method,
) {
val description = Description.createTestDescription(testClass, method.name)

notifier.fireTestStarted(description)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package uk.co.alt236.codeplasterage
package dev.alt236.codeplasterage

internal object Consts {
val ROOT_PACKAGE: String = Consts::class.java.`package`.name
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
@file:Suppress("unused")

package uk.co.alt236.codeplasterage.config
package dev.alt236.codeplasterage.config

import uk.co.alt236.codeplasterage.config.DefaultConfigValues.DEBUG
import uk.co.alt236.codeplasterage.config.DefaultConfigValues.IGNORE_ERRORS
import uk.co.alt236.codeplasterage.datafactory.SubDataFactory
import dev.alt236.codeplasterage.config.DefaultConfigValues.DEBUG
import dev.alt236.codeplasterage.config.DefaultConfigValues.IGNORE_ERRORS
import dev.alt236.codeplasterage.datafactory.SubDataFactory
import kotlin.reflect.KClass

@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION)
Expand All @@ -15,7 +15,7 @@ annotation class Config(
val forceExcludeClassNames: Array<String> = [],
val customDummyDataFactories: Array<KClass<out SubDataFactory>> = [],
val ignoreErrors: Boolean = IGNORE_ERRORS,
val debug: Boolean = DEBUG
val debug: Boolean = DEBUG,
)

internal object DefaultConfigValues {
Expand Down
Loading
Loading