Skip to content

Commit

Permalink
feature: upgrade versions
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathan Henrique Medeiros committed Sep 23, 2024
1 parent cf3c696 commit 4d26d28
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 9 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.3.1</version>
<version>3.3.3</version>
<relativePath/>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public int hashCode() {

@Override
public void generateIdempotencyId(final IdempotencyGenerator generator) {
final var uuid = generator.generate(this);
final var uuid = generator.apply(this);
this.setIdempotencyId(uuid);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
import br.com.multidatasources.model.IdempotentEntity;

import java.util.UUID;
import java.util.function.Function;

@FunctionalInterface
public interface IdempotencyGenerator {

UUID generate(final IdempotentEntity entity);
public interface IdempotencyGenerator extends Function<IdempotentEntity, UUID> {

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
public class UUIDIdempotencyGenerator implements IdempotencyGenerator {

@Override
public UUID generate(final IdempotentEntity data) {
public UUID apply(final IdempotentEntity data) {
try {
final var messageDigest = MessageDigest.getInstance(Algorithm.SHA_256.value());
final var jsonDataBytes = JsonUtils.toJson(data).getBytes(StandardCharsets.UTF_8);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ void givenANewBillionaire_whenSave_thenReturnASameBillionaireSaved(@DefaultBilli
.ignoringFields("id")
.isEqualTo(billionaire);

verify(this.idempotencyGenerator).generate(billionaire);
verify(this.idempotencyGenerator).apply(billionaire);
verify(this.billionaireRepository).existsBillionaireByIdempotencyId(billionaire.getIdempotencyId());
verify(this.billionaireRepository).save(billionaire);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ void givenANewBillionaire_whenSave_thenReturnASameBillionaireSaved() {

final var idempotencyId = UUID.randomUUID();

when(idempotencyGenerator.generate(any(Billionaire.class))).thenReturn(idempotencyId);
when(idempotencyGenerator.apply(any(Billionaire.class))).thenReturn(idempotencyId);
when(billionaireRepository.existsBillionaireByIdempotencyId(idempotencyId)).thenReturn(Boolean.FALSE);
when(billionaireRepository.save(any(Billionaire.class))).thenReturn(expected);

Expand All @@ -132,7 +132,7 @@ void givenAnExistentBillionaire_whenSave_thenThrowsEntityExistsException() {

final var idempotencyId = UUID.randomUUID();

when(idempotencyGenerator.generate(any(Billionaire.class))).thenReturn(idempotencyId);
when(idempotencyGenerator.apply(any(Billionaire.class))).thenReturn(idempotencyId);
when(billionaireRepository.existsBillionaireByIdempotencyId(idempotencyId)).thenReturn(Boolean.TRUE);

assertThatThrownBy(() -> subject.save(expected))
Expand Down

0 comments on commit 4d26d28

Please sign in to comment.