Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clean code #1601

Merged
merged 4 commits into from
Dec 26, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 27 additions & 27 deletions README.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion boot-choas-monkey/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@
<configuration>
<java>
<googleJavaFormat>
<version>1.22.0</version>
<version>1.25.2</version>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

Version inconsistency found in googleJavaFormat configuration

The search results show that while most projects use version 1.25.2 for googleJavaFormat, there is an inconsistency in the boot-jooq-r2dbc-sample project which uses version 1.25.0.

  • boot-jooq-r2dbc-sample/pom.xml: Uses version 1.25.0
  • All other projects (boot-choas-monkey, multitenancy modules, etc.): Use version 1.25.2
🔗 Analysis chain

LGTM: Version update for googleJavaFormat

The update to version 1.25.2 is a good improvement that includes bug fixes and enhancements for Java code formatting.

Let's verify if this version is consistently used across the project:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any other googleJavaFormat version declarations
rg --type xml "googleJavaFormat.*version"

Length of output: 43


Script:

#!/bin/bash
# Let's try a broader search for any mentions of googleJavaFormat in XML files
rg --type xml "googleJavaFormat"

# Also search for the specific version number
rg --type xml "1\.25\.2"

# Let's also check all pom.xml files in the repository
fd "pom.xml" --exec cat {}

Length of output: 76972

<style>AOSP</style>
</googleJavaFormat>
</java>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

@SpringBootApplication
@EnableConfigurationProperties({ApplicationProperties.class})
public class Application {
public class ChoasMonkeyApplication {

public static void main(String[] args) {
SpringApplication.run(Application.class, args);
SpringApplication.run(ChoasMonkeyApplication.class, args);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import com.example.choasmonkey.common.ContainerConfig;
import org.springframework.boot.SpringApplication;

public class TestApplication {
public class TestChoasMonkeyApplication {

public static void main(String[] args) {
SpringApplication.from(Application::main).with(ContainerConfig.class).run(args);
SpringApplication.from(ChoasMonkeyApplication::main).with(ContainerConfig.class).run(args);
}
}
1 change: 0 additions & 1 deletion boot-grafana-lgtm/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<!-- Remove version when spring boot supports-->
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>grafana</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion boot-rabbitmq-thymeleaf/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@
<configuration>
<java>
<googleJavaFormat>
<version>1.22.0</version>
<version>1.25.2</version>
<style>AOSP</style>
</googleJavaFormat>
</java>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import static org.testcontainers.shaded.org.awaitility.Awaitility.await;

import com.poc.boot.rabbitmq.common.ContainerConfiguration;
import com.poc.boot.rabbitmq.model.Order;
import com.poc.boot.rabbitmq.repository.TrackingStateRepository;
import java.util.concurrent.TimeUnit;
Expand All @@ -20,7 +21,7 @@

@SpringBootTest(
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
classes = TestRabbitMQApplication.class)
classes = ContainerConfiguration.class)
@AutoConfigureMockMvc
class RabbitMQIntegrationTest {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,11 @@
package com.poc.boot.rabbitmq;

import com.poc.boot.rabbitmq.common.ContainerConfiguration;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.devtools.restart.RestartScope;
import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.boot.testcontainers.service.connection.ServiceConnection;
import org.springframework.context.annotation.Bean;
import org.testcontainers.containers.RabbitMQContainer;
import org.testcontainers.utility.DockerImageName;

@TestConfiguration(proxyBeanMethods = false)
public class TestRabbitMQApplication {

@Bean
@ServiceConnection
@RestartScope
RabbitMQContainer rabbitMQContainer() {
return new RabbitMQContainer(DockerImageName.parse("rabbitmq").withTag("4.0.4-management"));
}

public static void main(String[] args) {
SpringApplication.from(RabbitMQApplication::main).with(TestRabbitMQApplication.class).run();
SpringApplication.from(RabbitMQApplication::main).with(ContainerConfiguration.class).run();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.poc.boot.rabbitmq.common;

import org.springframework.boot.devtools.restart.RestartScope;
import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.boot.testcontainers.service.connection.ServiceConnection;
import org.springframework.context.annotation.Bean;
import org.testcontainers.containers.RabbitMQContainer;
import org.testcontainers.utility.DockerImageName;

@TestConfiguration(proxyBeanMethods = false)
public class ContainerConfiguration {

@Bean
@ServiceConnection
@RestartScope
RabbitMQContainer rabbitMQContainer() {
return new RabbitMQContainer(DockerImageName.parse("rabbitmq").withTag("4.0.5-management"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.http.MediaType;
import org.springframework.test.context.bean.override.mockito.MockitoBean;
import org.springframework.test.web.servlet.MockMvc;

@WebMvcTest(MessageController.class)
Expand All @@ -29,7 +29,7 @@ class MessageControllerTest {

@Autowired private MockMvc mockMvc;

@MockBean private OrderMessageSender orderMessageSender;
@MockitoBean private OrderMessageSender orderMessageSender;

@Test
void handleMessage() throws Exception {
Expand Down
2 changes: 1 addition & 1 deletion boot-rest-docs-sample/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@
<configuration>
<java>
<googleJavaFormat>
<version>1.22.0</version>
<version>1.25.2</version>
<style>AOSP</style>
</googleJavaFormat>
<importOrder />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

@SpringBootApplication
@EnableConfigurationProperties({ApplicationProperties.class})
public class Application {
public class RestDocsApplication {

public static void main(String[] args) {
SpringApplication.run(Application.class, args);
SpringApplication.run(RestDocsApplication.class, args);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import com.example.restdocs.common.ContainerConfig;
import org.springframework.boot.SpringApplication;

public class TestApplication {
public class TestRestDocsApplication {

public static void main(String[] args) {
SpringApplication.from(Application::main).with(ContainerConfig.class).run(args);
SpringApplication.from(RestDocsApplication::main).with(ContainerConfig.class).run(args);
}
}
4 changes: 4 additions & 0 deletions graphql/boot-graphql-webmvc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,10 @@

<build>
<plugins>
<plugin>
<groupId>org.graalvm.buildtools</groupId>
<artifactId>native-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
Expand Down
13 changes: 13 additions & 0 deletions jpa/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,16 @@
Java Persistence API (JPA) is a Java application programming interface specification that describes the management of relational data in applications using Java Platform, Standard Edition and Java Platform, Enterprise Edition. It provides an object-relational mapping (ORM) facility for the Java language, allowing developers to interact with databases through the use of Java objects. JPA allows developers to easily persist and query data in a database, providing a simple and standardized approach to data persistence and management.

## All Niche Thing about using JPA

| Title | Description |
|----------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Custom Sequences](./boot-data-customsequence) | <ol> Implements CustomSequence Generation like `ORD000001` </ol> <ol> Uses [Custom Repository](https://vladmihalcea.com/basejparepository-hypersistence-utils/) instead of OOTB spring data repository </ol><ol>Logging SQL Statements using `DataSourceProxy` </ol> <ol> Connections Acquiring Optimization using `LazyConnectionDataSourceProxy` </ol> |
| [Entity Auditing using envers](./boot-data-envers) | |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add missing description for Entity Auditing

The "Entity Auditing using envers" entry lacks a description of its features and benefits. Consider adding details about:

  • What Envers provides
  • How to implement entity auditing
  • Key configuration options
  • Best practices

| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

@SpringBootApplication
@EnableConfigurationProperties({ApplicationProperties.class})
public class Application {
public class JpaEnversApplication {

public static void main(String[] args) {
SpringApplication.run(Application.class, args);
SpringApplication.run(JpaEnversApplication.class, args);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
import com.example.envers.common.ContainersConfig;
import org.springframework.boot.SpringApplication;

public class TestApplication {
public class TestJpaEnversApplication {

public static void main(String[] args) {
SpringApplication.from(Application::main)
SpringApplication.from(JpaEnversApplication::main)
.with(ContainersConfig.class)
.withAdditionalProfiles("local")
.run(args);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ public class ContainersConfig {
@Bean
@ServiceConnection
PostgreSQLContainer<?> postgreSQLContainer() {
return new PostgreSQLContainer<>(DockerImageName.parse("postgres:17.2-alpine"));
return new PostgreSQLContainer<>(DockerImageName.parse("postgres").withTag("17.2-alpine"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
import org.springframework.context.annotation.Import;

@DataJpaTest(properties = {"spring.jpa.hibernate.ddl-auto=validate", "spring.test.database.replace=none"})
@DataJpaTest(properties = {"spring.jpa.hibernate.ddl-auto=validate"})
@Import(ContainersConfig.class)
class SchemaValidationTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.bean.override.mockito.MockitoBean;
import org.springframework.test.web.servlet.MockMvc;

@WebMvcTest(controllers = CustomerController.class)
Expand All @@ -48,7 +48,7 @@ class CustomerControllerTest {
@Autowired
private MockMvc mockMvc;

@MockBean
@MockitoBean
private CustomerService customerService;

@Autowired
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
suppressTimestampInGenerated = true)
public interface CustomerMapper {

@Mapping(target = "id", ignore = true)
Customer toEntity(CustomerRequest customerRequest);

@IterableMapping(elementTargetType = CustomerResponse.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
suppressTimestampInGenerated = true)
public interface OrderMapper {

@Mapping(target = "removeOrderItem", ignore = true)
@Mapping(target = "orderItems", ignore = true)
@Mapping(target = "id", ignore = true)
@Mapping(target = "customer.id", source = "customerId")
Expand All @@ -32,6 +33,7 @@ public interface OrderMapper {
@IterableMapping(elementTargetType = OrderResponse.class)
List<OrderResponse> mapToOrderResponseList(List<Order> orderList);

@Mapping(target = "removeOrderItem", ignore = true)
@Mapping(target = "orderItems", ignore = true)
@Mapping(target = "id", ignore = true)
@Mapping(target = "customer", ignore = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
public interface CustomerRepository
extends BaseJpaRepository<Customer, Long>, PagingAndSortingRepository<Customer, Long> {

@Transactional(readOnly = true)
@QueryHints(@QueryHint(name = HINT_CACHEABLE, value = "true"))
@EntityGraph(attributePaths = {"orders"})
Optional<Customer> findByFirstName(String firstName);
Expand Down
2 changes: 1 addition & 1 deletion jpa/boot-jndi-sample/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@
<configuration>
<java>
<palantirJavaFormat>
<version>2.47.0</version>
<version>2.50.0</version>
</palantirJavaFormat>
<importOrder />
<removeUnusedImports />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

@SpringBootApplication
@EnableConfigurationProperties({ApplicationProperties.class})
public class Application {
public class JNDIApplication {

public static void main(String[] args) {
SpringApplication.run(Application.class, args);
SpringApplication.run(JNDIApplication.class, args);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

@SpringBootApplication
@EnableConfigurationProperties({ApplicationProperties.class})
public class Application {
public class JpaLocksApplication {

public static void main(String[] args) {
SpringApplication.run(Application.class, args);
SpringApplication.run(JpaLocksApplication.class, args);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
import com.example.locks.utils.AppConstants;
import org.springframework.boot.SpringApplication;

public class TestApplication {
public class TestJpaLocksApplication {

public static void main(String[] args) {
SpringApplication.from(Application::main)
SpringApplication.from(JpaLocksApplication::main)
.with(ContainersConfig.class)
.withAdditionalProfiles(AppConstants.PROFILE_LOCAL)
.run(args);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import reactor.core.publisher.Mono;

@Service
@Transactional
@Transactional(readOnly = true)
@RequiredArgsConstructor
public class ReactiveCommentsService {

Expand All @@ -34,20 +34,23 @@ public Mono<ReactiveComments> findReactiveCommentById(UUID id) {
return reactiveCommentsRepository.findById(id);
}

@Transactional
public Mono<ReactiveComments> saveReactiveCommentByPostId(
ReactiveCommentRequest reactiveCommentRequest) {
ReactiveComments reactiveComments =
reactivePostCommentMapper.mapToReactivePostComments(reactiveCommentRequest);
return reactiveCommentsRepository.save(reactiveComments);
}

@Transactional
public Mono<ReactiveComments> updateReactivePostComment(
ReactiveCommentRequest reactiveCommentRequest, ReactiveComments reactiveComments) {
reactivePostCommentMapper.updateReactiveCommentRequestFromReactiveComments(
reactiveCommentRequest, reactiveComments);
return reactiveCommentsRepository.save(reactiveComments);
}

@Transactional
public Mono<Void> deleteReactiveCommentById(UUID id) {
return reactiveCommentsRepository.deleteById(id);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,9 @@ void deleteReactivePostById() {
// given
given(reactivePostRepository.deleteById(1L)).willReturn(Mono.empty());
// when
reactivePostService.deleteReactivePostById(1L);
Mono<Void> voidMono = reactivePostService.deleteReactivePostById(1L);
// then
StepVerifier.create(voidMono).expectComplete().verify();
verify(reactivePostRepository, times(1)).deleteById(1L);
}

Expand Down
Loading
Loading