https://github.com/simplaex/dummies
Create Java/Scala mock objects with real content
https://github.com/simplaex/dummies
dummies java java-8 mock-data mocking scala testing testing-tools
Last synced: 4 months ago
JSON representation
Create Java/Scala mock objects with real content
- Host: GitHub
- URL: https://github.com/simplaex/dummies
- Owner: simplaex
- License: other
- Created: 2017-08-30T19:15:58.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2017-09-05T14:11:40.000Z (over 8 years ago)
- Last Synced: 2024-12-30T05:54:41.501Z (over 1 year ago)
- Topics: dummies, java, java-8, mock-data, mocking, scala, testing, testing-tools
- Language: Java
- Size: 288 KB
- Stars: 1
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG
- License: LICENSE
Awesome Lists containing this project
README
# easy dummies for Java/Scala
## Setup
### Java/Maven
com.simplaex
dummies
1.0.0
### Scala/SBT
libraryDependencies += "com.simplaex" % "dummies" % "1.0.0"
## Examples
### Java/Lombok
public class JavaExampleWithLombok {
public static void main(final String... args) {
val record1 = Dummies.get().create(Record.class);
val record2 = Dummies.get().fill(new Record());
val user = Dummies.get().create(User.class);
System.out.println(record1);
// -> JavaExample.Record(
// id=c235b645-cdb6-4d96-9048-fac93813ce36,
// createdAt=+271952187-10-06T20:59:55.612Z,
// updatedAt=+14800123-06-14T17:07:53.312Z)
System.out.println(record2);
// -> JavaExample.Record(
// id=b7fe44b8-f90d-41c3-8406-9276db0a406e,
// createdAt=+218282276-11-01T22:34:26.961Z,
// updatedAt=+153555425-04-24T17:03:03.930Z)
System.out.println(user);
// -> JavaExample.User(
// name=Julieta Vallon,
// currentAddress=JavaExample.Address(
// street=Main Street,
// city=New York,
// country=Thailand),
// formerAddresses=[
// JavaExample.Address(
// street=Maple Street,
// city=New York,
// country=Turkmenistan)])
}
@Data
public static class Record {
private UUID id;
private Instant createdAt;
private Instant updatedAt;
}
@Value
public static class User {
@DummyValues(generator = NameGenerator.class)
private final String name;
private final Address currentAddress;
@DummyValues(minLength = 0, maxLength = 5)
private final List
formerAddresses;
}
@Value
public static class Address {
@DummyValues({"Main Street", "Market Street", "Maple Street"})
private final String street;
@DummyValues({"New Amsterdam", "New Berlin", "New York"})
private final String city;
@DummyValues(generator = CountryNameGenerator.class)
private final String country;
}
}
### Scala
object ScalaExample {
def main(args: Array[String]): Unit = {
val record = Dummies.get().create(classOf[Record])
println(record)
// -> Record(a2a64f26-ed99-4265-8b57-f668099339c7,+127329170-07-19T19:33:44.946Z,+68490793-08-27T22:13:40.674Z,CZ)
}
final case class Record(
id: UUID,
createdAt: Instant,
updatedAt: Instant,
@(DummyValues @field)(generator = classOf[CountryCodeGenerator])
countryOfOrigin: String
)
}