Skip to content

wjur/args

Repository files navigation

Args Build Status Coverage Status Maven Central

Args is a groovy library to make map-based test builders safer.

The main disadvantage of map-based test builder is that they are typo-prone. When you pass values as a map there is no validation and you never know whether a key you used is correct or not. Args validates keys' names and assure that there are no typos.

Usage

Add Args as dependency:

repositories {
    mavenCentral()
}

dependencies {
    compile 'io.github.wjur:args:0.1.0'
}

Use the Args class in your test builders:

class DomainObjectTestBuilder {
  private DomainObjectTestBuilder() {}

  private static final def defaults = [
    "id"       : "object-1",
    "size"     : 100,
    "createdAt": "2019-04-23"
]

static DomainObject domainObject(Map overrides = [:]) {
-  def args = defaults + overrides
+  def args = Args.args(defaults, overrides)
  return new DomainObject(
    args.id,
    args.size,
    DateTime.parse(args.createdAt)
  )
}

Licence

MIT License

Copyright (c) 2018 Wojciech Jurczyk