Documentation
Getting Started
Add JMock to a Java project and render your first template in minutes.
1
Installation
Add the core artifact to your Maven pom.xml. Include all-plugin at runtime for the full built-in function set.
pom.xml
<dependency> <groupId>cloud.xcan.jmock</groupId> <artifactId>xcan-jmock.core</artifactId> <version>2.0.0</version> </dependency> <!-- Include all plugins --> <dependency> <groupId>cloud.xcan.jmock</groupId> <artifactId>xcan-jmock.all-plugin</artifactId> <version>2.0.0</version> <scope>runtime</scope> </dependency>
2
Basic Usage
Example.java
import cloud.xcan.jmock.core.engine.MockEngine;
// Simple template rendering
MockEngine engine = MockEngine.defaultEngine();
String result = engine.render("Hello @Name(), your ID is @Integer(1000,9999)");
// → "Hello Alice, your ID is 4527"
// Batch generation
List<String> records = engine.renderBatch(template, 1000);
// Single expression evaluation
Object value = engine.evaluate("@Email()");
// → "john.doe@example.com"3
Template Syntax
JMock templates use @FunctionName(params) syntax. Common examples:
| Expression | Description |
|---|---|
@String() | Random 6-char string |
@Integer(1,100) | Random integer between 1 and 100 |
@Email() | Random email address |
@Name() | Random person name |
@Repeat(@Email(),3) | Array of 3 random emails |
4
Plugin Architecture
JMock uses Java SPI for plugin discovery. All functions are automatically registered at runtime. You can add custom functions by implementing MockFunction and registering via META-INF/services.