Skip to content

eo-cqrs/xfake

Repository files navigation

logo

Managed By Self XDSD

EO principles respected here DevOps By Rultor.com We recommend IntelliJ IDEA

mvn maven central javadoc codecov

Hits-of-Code Lines-of-Code PDD status License

Project architect: @h1alexbel

XML In-Memory Storage for your Fake Objects.

Read about Fake Objects pattern and Watch Why Mocking Frameworks are Evil by @yegor256.

Motivation. To create a fake objects, we need to introduce some place where data will be stored.
We're not happy with creating this one again and again.

Principles. These are the design principles behind eo-kafka.

How to use. All you need is this (get the latest version here):

Maven:

<dependency>
  <groupId>io.github.eo-cqrs</groupId>
  <artifactId>xfake</artifactId>
</dependency>

Gradle:

dependencies {
    compile 'io.github.eo-cqrs:xfake:<version>'
}

Constructing Storage

To create an in-memory storage, we need to provide the name of the file to create and root XML node.

final FkStorage storage = new InFile("fake-test", "<fake/>");
storage.xml();

The output of storage.xml() will be:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<fake/>

After an object will be destroyed, the file will be deleted.

Applying Directives

final FkStorage storage = new InFile("fake-test", "<fake/>");
storage.apply(
  new Directives()
  .xpath("/fake")
  .addIf("servers")
);

The result of the applying will be:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<fake>
  <servers/>
</fake>

Synchronized Storage

Also, you can create a synchronized storage:

final FkStorage storage = 
  new Synchronized(
    new InFile("fake-synchronized", "<fake/>")
);

In this case reads xml() and writes apply(dirs) will be synchronized, and it will be possible to use it in multithreading environment.

Logging Storage

final FkStorage storage =
  new Logged(
    new Synchronized(
      new InFile("logged-test", "<fake/>")
    ),
  Level.INFO
);

This is the use-case of FkStorage in eo-kafka.

How to Contribute

Fork repository, make changes, send us a pull request. We will review your changes and apply them to the master branch shortly, provided they don't violate our quality standards. To avoid frustration, before sending us your pull request please run full Maven build:

$ mvn clean install

You will need Maven 3.8.7+ and Java 17+.

If you want to contribute to the next release version of eo-kafka, please check the project board.

Our rultor image for CI/CD.