{"id":20841507,"url":"https://github.com/wavesoftware/sampler","last_synced_at":"2026-04-24T00:35:15.826Z","repository":{"id":57742534,"uuid":"188446667","full_name":"wavesoftware/sampler","owner":"wavesoftware","description":"A typesafe engine for your project examples","archived":false,"fork":false,"pushed_at":"2023-03-19T19:12:43.000Z","size":74,"stargazers_count":0,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-19T00:48:06.524Z","etag":null,"topics":["developer-tools","samples","testing","typesafe"],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wavesoftware.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-05-24T15:33:06.000Z","updated_at":"2023-03-19T18:59:09.000Z","dependencies_parsed_at":"2022-09-09T09:22:34.446Z","dependency_job_id":null,"html_url":"https://github.com/wavesoftware/sampler","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wavesoftware%2Fsampler","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wavesoftware%2Fsampler/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wavesoftware%2Fsampler/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wavesoftware%2Fsampler/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wavesoftware","download_url":"https://codeload.github.com/wavesoftware/sampler/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243197211,"owners_count":20251956,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["developer-tools","samples","testing","typesafe"],"created_at":"2024-11-18T01:20:25.763Z","updated_at":"2026-04-24T00:35:10.792Z","avatar_url":"https://github.com/wavesoftware.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Sampler for Java\n\nA typesafe engine for your project examples\n\n## Installation\n\n```xml\n\u003c!-- For Spring integration --\u003e\n\u003cdependency\u003e\n  \u003cgroupId\u003epl.wavesoftware.sampler\u003c/groupId\u003e\n  \u003cartifactId\u003esampler-spring\u003c/artifactId\u003e\n  \u003cversion\u003e1.1.0\u003c/version\u003e\n  \u003cscope\u003etest\u003c/scope\u003e\n\u003c/dependency\u003e\n```\n\n## Usage\n\n\n### Basic usage\n\nYou can create a sample classes by implementing `Sampler\u003cT\u003e` interface.\n\n```java\n@Sample\npublic final class Jsr305Artifact implements Sampler\u003cArtifact\u003e {\n  private final SamplerContext context;\n\n  Jsr305Artifact(SamplerContext context) {\n    this.context = context;\n  }\n\n  @Override\n  public Artifact create() {\n    return new MavenlikeArtifact(\n      context,\n      \"jsr305\",\n      \"com.google.code.findbugs\",\n      new Semver(\"3.0.2\")\n    );\n  }\n}\n```\n\nThe `SampleContext` can be used to get instances of other samples, to achieve consistency across complex sample graphs.\n\n```java\n@Sample\npublic final class SimpleProject implements Sampler\u003cProject\u003e {\n\n  private final SamplerContext context;\n\n  SimpleProject(SamplerContext context) {\n    this.context = context;\n  }\n\n  @Override\n  public Project create() {\n    Path root = context.get(ProjectRoot.class);\n    return new AbstractProject(root, \"simple\") {\n      @Override\n      public Set\u003cArtifact\u003e dependencies() {\n        return HashSet\n            .of(HibernateArtifact.class, Jsr305Artifact.class)\n            .map(context::get);\n      }\n    };\n  }\n}\n```\n\n### Vanilla Java\n\nTo use Sampler in vanilla Java, you need to create a `SamplerContext` instance,\nand register all samples in it.\n\n```java\nclass SampleTests {\n  @Test\n  void samples() {\n    var samplers = HashMap.of(JohnDoe.class, (Sampler\u003cUser\u003e) () -\u003e User.builder()\n      .id(43L)\n      .name(\"John Doe\")\n      .build()\n    );\n    try (var ctx = new StaticSamplerContext(samplers)) {\n      User user = ctx.get(JohnDoe.class);\n      assertThat(user).isNotNull();\n    }\n  }\n}\n```\n\n### Spring integration\n\nTo use Sampler in Spring, you need to autowire a `SamplerContext` instance. If\nyou are using the Spring Boot, the `SamplerContext` is already available as a\nbean. You need to register all samples using `@Sample` annotation.\n\n```java\n@Configuration\nclass Samples {\n  @Bean\n  Sampler\u003cUser\u003e johnDoe() {\n    return () -\u003e User.builder()\n      .id(43L)\n      .name(\"John Doe\")\n      .build();\n  }\n}\n```\n\nUsing it is also simple\n\n```java\n@SpringBootTest\nclass SampleTests {\n  @Autowired\n  private SamplerContext ctx;\n\n  @Test\n  void samples() {\n    User user = ctx.get(JohnDoe.class);\n    assertThat(user).isNotNull();\n  }\n}\n```\n\n### Random samples\n\nIf you like to randomize your samples, you can use user the\n`SamplerContext#controller()` method to get a `SamplerController` instance.\nUsing sample controller you can fetch a `Random` instance, and use it to create\nrandom samples.\n\nIf you happen to encounter a situation where you need to re-create a given\nrandomized execution, like a failure on CI system, you can use the\n`sampler.seed` system property, or `SAMPLER_SEED` environment variable to\nrecreate same execution. The seed used by `DefaultRandomSource` is printed on\nconsole during the execution.\n\n```java\n@Sample\n@RequiredArgsConstructor\nclass JohnDoe implements Sampler\u003cUser\u003e {\n  private final SamplerContext ctx;\n\n  @Override\n  public User create() {\n    return User.builder()\n      .id(ctx.controller().random().nextLong())\n      .name(\"John Doe\")\n      .build();\n  }\n}\n```\n\n## Contributing\n\nContributions are welcome! To contribute, file a PR.\n\nEven if you can't contribute code, if you have an idea for an improvement\nplease open an [issue](https://github.com/wavesoftware/sampler/issues).\n\n## Requirements\n\n* Java 11+ (Tested on JDK 11, and 17)\n* Spring module requires any modern Spring, tested against latest 6.x, but\n  should work in Spring 3+ as well.\n\n## Releases\n\n* `1.1.0` - codename: *FriarySparkle*\n  * Migrate to Spring Boot 3.x\n\n* `1.0.0` - codename: *BananaBow*\n\t* First publicly available release\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwavesoftware%2Fsampler","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwavesoftware%2Fsampler","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwavesoftware%2Fsampler/lists"}