Hermes Mock

A thin library designed to mocking Hermes Frontend in tests.

Overview

Mocking is provided by HermesMock class, which consists of 3 parts: - HermesMockDefine - HermesMockExpect - HermesMockQuery

HermesMockDefine

Is responsible for defining new topics on Hermes, provides the following methods:

HermesMockExpect

Is responsible for expectation of message on Hermes side, provides the following methods:

HermesMockQuery

Is responsible for querying Hermes for a received messages, provides the following methods:

Creating

To start using Hermes mock, add it as a dependency:

compile group: 'pl.allegro.tech.hermes', name: 'hermes-mock', version: versions.hermes

Example

class MyServiceTest {

    @Rule
    HermesMockRule hermesMock = new HermesMockRule(8090);

    @Test
    public void exampleTest() {
        // given
        MyMessage myMessage = new MyMessage("id123", "content");
        String topicName = "myTopic";

        hermesMock.define().jsonTopic(topicName);

        // when
        myService.publishHermesMessage(myMessage);

        // then
        hermesMock.expect().jsonMessagesOnTopicAs(topicName, MyMessage.class);

        // and
        List<MyMessage> all = hermesMock.query().allJsonMessagesAs(topicName, MyMessage.class);

        // and verify that `all` contains what we're expecting 
    }
}