mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-10-13 04:15:07 +00:00
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:
1 parent
371439aeaa
commit
0ca162a55c
1863 files changed
+14403
-17632
No files matched your search
@@ -34,6 +34,14 @@
|
||||
<artifactId>converter</artifactId>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>ch.qos.logback</groupId>
|
||||
<artifactId>logback-classic</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-engine</artifactId>
|
||||
|
||||
@@ -48,11 +48,11 @@ public class App {
|
||||
User user = userConverter.convertFromDto(dtoUser);
|
||||
LOGGER.info("Entity converted from DTO: {}", user);
|
||||
|
||||
var users = List.of(
|
||||
new User("Camile", "Tough", false, "124sad"),
|
||||
new User("Marti", "Luther", true, "42309fd"),
|
||||
new User("Kate", "Smith", true, "if0243")
|
||||
);
|
||||
var users =
|
||||
List.of(
|
||||
new User("Camile", "Tough", false, "124sad"),
|
||||
new User("Marti", "Luther", true, "42309fd"),
|
||||
new User("Kate", "Smith", true, "if0243"));
|
||||
LOGGER.info("Domain entities:");
|
||||
users.stream().map(User::toString).forEach(LOGGER::info);
|
||||
|
||||
|
||||
@@ -86,5 +86,4 @@ public class Converter<T, U> {
|
||||
public final List<T> createFromEntities(final Collection<U> entities) {
|
||||
return entities.stream().map(this::convertFromEntity).toList();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -24,7 +24,5 @@
|
||||
*/
|
||||
package com.iluwatar.converter;
|
||||
|
||||
/**
|
||||
* User record.
|
||||
*/
|
||||
/** User record. */
|
||||
public record User(String firstName, String lastName, boolean active, String userId) {}
|
||||
@@ -24,9 +24,7 @@
|
||||
*/
|
||||
package com.iluwatar.converter;
|
||||
|
||||
/**
|
||||
* Example implementation of the simple User converter.
|
||||
*/
|
||||
/** Example implementation of the simple User converter. */
|
||||
public class UserConverter extends Converter<UserDto, User> {
|
||||
|
||||
public UserConverter() {
|
||||
|
||||
@@ -24,7 +24,5 @@
|
||||
*/
|
||||
package com.iluwatar.converter;
|
||||
|
||||
/**
|
||||
* UserDto record.
|
||||
*/
|
||||
/** UserDto record. */
|
||||
public record UserDto(String firstName, String lastName, boolean active, String email) {}
|
||||
@@ -24,25 +24,20 @@
|
||||
*/
|
||||
package com.iluwatar.converter;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
||||
|
||||
/**
|
||||
* App running test
|
||||
*/
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/** App running test */
|
||||
class AppTest {
|
||||
|
||||
/**
|
||||
* Issue: Add at least one assertion to this test case.
|
||||
* Solution: Inserted assertion to check whether the execution of the main method in {@link App#main(String[])}
|
||||
* throws an exception.
|
||||
* Issue: Add at least one assertion to this test case. Solution: Inserted assertion to check
|
||||
* whether the execution of the main method in {@link App#main(String[])} throws an exception.
|
||||
*/
|
||||
|
||||
@Test
|
||||
void shouldExecuteApplicationWithoutException() {
|
||||
|
||||
assertDoesNotThrow(() -> App.main(new String[]{}));
|
||||
assertDoesNotThrow(() -> App.main(new String[] {}));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -30,16 +30,12 @@ import java.util.List;
|
||||
import java.util.Random;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Tests for {@link Converter}
|
||||
*/
|
||||
/** Tests for {@link Converter} */
|
||||
class ConverterTest {
|
||||
|
||||
private final UserConverter userConverter = new UserConverter();
|
||||
|
||||
/**
|
||||
* Tests whether a converter created of opposite functions holds equality as a bijection.
|
||||
*/
|
||||
/** Tests whether a converter created of opposite functions holds equality as a bijection. */
|
||||
@Test
|
||||
void testConversionsStartingFromDomain() {
|
||||
var u1 = new User("Tom", "Hanks", true, "tom@hanks.com");
|
||||
@@ -47,9 +43,7 @@ class ConverterTest {
|
||||
assertEquals(u1, u2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests whether a converter created of opposite functions holds equality as a bijection.
|
||||
*/
|
||||
/** Tests whether a converter created of opposite functions holds equality as a bijection. */
|
||||
@Test
|
||||
void testConversionsStartingFromDto() {
|
||||
var u1 = new UserDto("Tom", "Hanks", true, "tom@hanks.com");
|
||||
@@ -63,19 +57,22 @@ class ConverterTest {
|
||||
*/
|
||||
@Test
|
||||
void testCustomConverter() {
|
||||
var converter = new Converter<UserDto, User>(
|
||||
userDto -> new User(
|
||||
userDto.firstName(),
|
||||
userDto.lastName(),
|
||||
userDto.active(),
|
||||
String.valueOf(new Random().nextInt())
|
||||
),
|
||||
user -> new UserDto(
|
||||
user.firstName(),
|
||||
user.lastName(),
|
||||
user.active(),
|
||||
user.firstName().toLowerCase() + user.lastName().toLowerCase() + "@whatever.com")
|
||||
);
|
||||
var converter =
|
||||
new Converter<UserDto, User>(
|
||||
userDto ->
|
||||
new User(
|
||||
userDto.firstName(),
|
||||
userDto.lastName(),
|
||||
userDto.active(),
|
||||
String.valueOf(new Random().nextInt())),
|
||||
user ->
|
||||
new UserDto(
|
||||
user.firstName(),
|
||||
user.lastName(),
|
||||
user.active(),
|
||||
user.firstName().toLowerCase()
|
||||
+ user.lastName().toLowerCase()
|
||||
+ "@whatever.com"));
|
||||
var u1 = new User("John", "Doe", false, "12324");
|
||||
var userDto = converter.convertFromEntity(u1);
|
||||
assertEquals("johndoe@whatever.com", userDto.email());
|
||||
@@ -87,11 +84,11 @@ class ConverterTest {
|
||||
*/
|
||||
@Test
|
||||
void testCollectionConversion() {
|
||||
var users = List.of(
|
||||
new User("Camile", "Tough", false, "124sad"),
|
||||
new User("Marti", "Luther", true, "42309fd"),
|
||||
new User("Kate", "Smith", true, "if0243")
|
||||
);
|
||||
var users =
|
||||
List.of(
|
||||
new User("Camile", "Tough", false, "124sad"),
|
||||
new User("Marti", "Luther", true, "42309fd"),
|
||||
new User("Kate", "Smith", true, "if0243"));
|
||||
var fromDtos = userConverter.createFromDtos(userConverter.createFromEntities(users));
|
||||
assertEquals(users, fromDtos);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user