deps: Refactor dependencies (#3224)

* remove spring dep
move junit, logging, mockito under dep mgmt

* upgrade anti-corruption-layer deps

* async method invocation

* balking, bloc

* bridge to bytecode

* caching

* callback - cqrs

* component - health check

* hexagonal - metadata mapping

* rest of the patterns

* remove checkstyle, take spotless into use
This commit is contained in:
Ilkka Seppälä authored and GitHub committed 2025-03-29 19:34:27 +02:00
1 parent 371439aeaa
commit 0ca162a55c
1863 files changed
+14403 -17632

No files matched your search

@@ -35,7 +35,7 @@ public interface UpdateService<T> {
* Update entity.
*
* @param obj entity to update
* @param id primary key
* @param id primary key
* @return modified entity
*/
T doUpdate(T obj, long id);
@@ -24,9 +24,7 @@
*/
package com.iluwatar.exception;
/**
* Exception happens in application during business-logic execution.
*/
/** Exception happens in application during business-logic execution. */
public class ApplicationException extends RuntimeException {
/**
@@ -24,38 +24,27 @@
*/
package com.iluwatar.model;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* Bank card entity.
*/
/** Bank card entity. */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class Card {
/**
* Primary key.
*/
/** Primary key. */
private long id;
/**
* Foreign key points to card's owner.
*/
/** Foreign key points to card's owner. */
private long personId;
/**
* Sum of money.
*/
/** Sum of money. */
private float sum;
/**
* Current version of object.
*/
/** Current version of object. */
private int version;
}
@@ -30,9 +30,7 @@ import com.iluwatar.model.Card;
import com.iluwatar.repository.JpaRepository;
import lombok.RequiredArgsConstructor;
/**
* Service to update {@link Card} entity.
*/
/** Service to update {@link Card} entity. */
@RequiredArgsConstructor
public class CardUpdateService implements UpdateService<Card> {
@@ -45,11 +43,10 @@ public class CardUpdateService implements UpdateService<Card> {
int initialVersion = cardToUpdate.getVersion();
float resultSum = cardToUpdate.getSum() + additionalSum;
cardToUpdate.setSum(resultSum);
//Maybe more complex business-logic e.g. HTTP-requests and so on
// Maybe more complex business-logic e.g. HTTP-requests and so on
if (initialVersion != cardJpaRepository.getEntityVersionById(id)) {
String exMessage =
String.format("Entity with id %s were updated in another transaction", id);
String exMessage = String.format("Entity with id %s were updated in another transaction", id);
throw new ApplicationException(exMessage);
}
@@ -24,6 +24,9 @@
*/
package com.iluwatar;
import static org.mockito.Mockito.eq;
import static org.mockito.Mockito.when;
import com.iluwatar.exception.ApplicationException;
import com.iluwatar.model.Card;
import com.iluwatar.repository.JpaRepository;
@@ -33,9 +36,6 @@ import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import static org.mockito.Mockito.when;
import static org.mockito.Mockito.eq;
@SuppressWarnings({"rawtypes", "unchecked"})
public class OptimisticLockTest {
@@ -53,27 +53,19 @@ public class OptimisticLockTest {
public void shouldNotUpdateEntityOnDifferentVersion() {
int initialVersion = 1;
long cardId = 123L;
Card card = Card.builder()
.id(cardId)
.version(initialVersion)
.sum(123f)
.build();
Card card = Card.builder().id(cardId).version(initialVersion).sum(123f).build();
when(cardRepository.findById(eq(cardId))).thenReturn(card);
when(cardRepository.getEntityVersionById(Mockito.eq(cardId))).thenReturn(initialVersion + 1);
Assertions.assertThrows(ApplicationException.class,
() -> cardUpdateService.doUpdate(card, cardId));
Assertions.assertThrows(
ApplicationException.class, () -> cardUpdateService.doUpdate(card, cardId));
}
@Test
public void shouldUpdateOnSameVersion() {
int initialVersion = 1;
long cardId = 123L;
Card card = Card.builder()
.id(cardId)
.version(initialVersion)
.sum(123f)
.build();
Card card = Card.builder().id(cardId).version(initialVersion).sum(123f).build();
when(cardRepository.findById(eq(cardId))).thenReturn(card);
when(cardRepository.getEntityVersionById(Mockito.eq(cardId))).thenReturn(initialVersion);