Search⌘ K
AI Features

Develop the Mock Service

Explore how to develop a mock service for managing data with an in-memory custom database implemented via the Singleton pattern. Learn functions for adding, retrieving, editing, and removing data entries, and understand how these integrate with RESTful service operations. This lesson builds foundational skills for creating testable server-side services in Java.

add function

Let’s start with a simple add to the in-memory custom database, which is based on the Singleton pattern implemented as an enum.

Java
public enum ProtocolInMemoryDB {
INSTANCE;
private static List<ProtocolDto> list = new ArrayList<ProtocolDto>();
private static Integer lastId = 0;
public Integer getId() {
return ++lastId;
}
public void add(ProtocolDto protocolDto) {
protocolDto.setId(getId());
list.add(protocolDto);
}
}

Create operation

We will be looking at the mock ...