Skip to content

Instantly share code, notes, and snippets.

Avatar
:octocat:
Leave your code better than you found it

Yusuf Çakal yusufcakal

:octocat:
Leave your code better than you found it
View GitHub Profile
@yusufcakal
yusufcakal / LoggingFilter.java
Last active Feb 8, 2021
Helps you easy to tracing logs to request and response via Spring
View LoggingFilter.java
import com.dolap.settlement.model.request.CreateSettlementRequest;
import com.dolap.settlement.model.response.GetSettlementResponse;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.logging.log4j.util.Strings;
import org.slf4j.MDC;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpMethod;
import org.springframework.stereotype.Component;
View checkstyle.xml
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
"-//Checkstyle//DTD Checkstyle Configuration 1.3//EN"
"https://checkstyle.org/dtds/configuration_1_3.dtd">
<!--
Checkstyle configuration that checks the Google coding conventions from Google Java Style
that can be found at https://google.github.io/styleguide/javaguide.html
Checkstyle is very configurable. Be sure to read the documentation at
View AddressServiceTest.java
@Test(expected = AddressUpdateException.class)
public void shouldNotUpdateAddressAndDoNotSendNotificationWhenAddressIdIsWrong() {
AddressUpdateRequest addressUpdateRequest = AddressUpdateRequestBuilder.anAddressUpdateRequestBuilder()
.id(1L)
.build();
when(addressRepository.findById(1L)).thenReturn(Optional.empty());
try {
addressService.update(addressUpdateRequest);
View AddressService.java
@Service
public class AddressService {
private final AddressRepository addressRepository;
private final SendNotificationService sendNotificationService;
public AddressService(AddressRepository addressRepository, SendNotificationService sendNotificationService) {
this.addressRepository = addressRepository;
this.sendNotificationService = sendNotificationService;
}
View SellerCenterServiceTest.java
@Test
public void shouldGetWorstSellerCenterLabelWhenSellerLabelOne() {
int sellCount = 3;
Seller seller = SellerBuilder.aSellerBuilder()
.sellCount(sellCount)
.previousSellerLabel(SellerLabel.SELLER_5)
.build();
when(sellerLabelTwentyProcessor.getSellerLabel(sellCount)).thenReturn(SellerLabel.NEW_SELLER);
when(sellerLabelFiveProcessor.getSellerLabel(sellCount)).thenReturn(SellerLabel.NEW_SELLER);
View SellerCenterServiceTest.java
@RunWith(MockitoJUnitRunner.class)
public class SellerCenterServiceTest {
@Mock
private SellerLabelOneProcessor sellerLabelOneProcessor;
@Mock
private SellerLabelFiveProcessor sellerLabelFiveProcessor;
@Mock
View SellerLabelOneProcessor.java
@Service
public class SellerLabelOneProcessor implements SellerLabelProcessor {
@Override
public SellerLabel getSellerLabel(int sellCount) {
return sellCount >= 1 && sellCount < 5 ? SellerLabel.SELLER_1 : SellerLabel.NEW_SELLER;
}
}
View SellerLabelFiveProcessor.java
@Service
public class SellerLabelFiveProcessor implements SellerLabelProcessor {
@Override
public SellerLabel getSellerLabel(int sellCount) {
return sellCount >= 5 && sellCount < 20 ? SellerLabel.SELLER_5 : SellerLabel.NEW_SELLER;
}
}
@yusufcakal
yusufcakal / SellerLabelTwentyProcessor.java
Last active Aug 24, 2020
SellerLabelTwentyProcessor
View SellerLabelTwentyProcessor.java
@Service
public class SellerLabelTwentyProcessor implements SellerLabelProcessor {
@Override
public SellerLabel getSellerLabel(int sellCount) {
return sellCount >= 20 ? SellerLabel.SELLER_20 : SellerLabel.NEW_SELLER;
}
}
View SellerLabel.java
public enum SellerLabel {
NEW_SELLER,
SELLER_1,
SELLER_5,
SELLER_20;
public boolean isSellerLabelNotNewSeller() {
return SellerLabel.NEW_SELLER != this;
}