random-value-suppliers

Template repo to speed up creating new library projects

License

License

GroupId

GroupId

com.github.michaelruocco
ArtifactId

ArtifactId

random-value-suppliers
Last Version

Last Version

0.1.0
Release Date

Release Date

Type

Type

pom.sha512
Description

Description

random-value-suppliers
Template repo to speed up creating new library projects
Project URL

Project URL

https://github.com/michaelruocco/random-value-suppliers
Source Code Management

Source Code Management

https://github.com/michaelruocco/random-value-suppliers

Download random-value-suppliers

Dependencies

runtime (2)

Group / Artifact Type Version
org.apache.commons : commons-text jar 1.9
org.apache.commons : commons-lang3 jar 3.11

Project Modules

There are no modules declared in this project.

Library Template

Build codecov Codacy Badge BCH compliance Quality Gate Status Technical Debt Coverage Lines of Code Maven Central License: MIT

Overview

This library contains some small utilities for generating random values in a testable way.

UUIDs

If you need to generate a UUID value you can of course just call UUID.randomUUID() and this works fine. However, when you are testing you cannot easily determine what the value will be. This library aims to help with that by providing the UuidGenerator interface, in normal execution the RandomUuidGenerator can be used to provide a random UUID, this is ultimately just calls UUID.randomUUID(). when testing you can use NonRandomUuidGenerator instead, by default it will cycle around 5 fixed UUID values each time it is called, if you require more than 5 distinct values you can pass in your own list of fixed UUID values instead if you wish.

Numeric Strings

For generic string values a similar NumericStringGenerator interface has been created, the generate method takes a single argument which determines the length of the numeric string to be returned. If you do not need to vary the length of the string value you can wrap the generated inside the FixedLengthNumericStringGenerator class. There are two implementations of NumericStringGenerator the first is RandomNumericStringGenerator which unsurprisingly will generate a string containing random digits of the specified length. When testing you can use IncrementingNumericStringGenerator this will return predictable results by returning an incrementing value starting from 1. So if you pass a length of 5, the first 3 calls would return "00001", "00002", "00003".

Examples

The unit tests for each of the classes listed above demonstrate each of the classes above and how they can be used.

Useful Commands

// cleans build directories
// prints currentVersion
// formats code
// builds code
// runs tests
// checks for gradle issues
// checks dependency versions
./gradlew clean currentVersion dependencyUpdates lintGradle spotlessApply build

Versions

Version
0.1.0