Skip to content

Commit

Permalink
fix spotless
Browse files Browse the repository at this point in the history
  • Loading branch information
naruepracht-s committed Mar 23, 2024
1 parent d2525ac commit 5f6de03
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
12 changes: 7 additions & 5 deletions kbazaar/src/main/java/com/kampus/kbazaar/cart/CartService.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public CartService(
this.shopperRepository = shopperRepository;
}

//story_6
// story_6
public ApplyCodeResponse applyCode(String username, ApplyCodeRequest request) {
Optional<Shopper> shopper = shopperRepository.findByUsername(username);
if (shopper.isPresent()) {
Expand All @@ -37,12 +37,14 @@ public ApplyCodeResponse applyCode(String username, ApplyCodeRequest request) {
promotion.get().getMaxDiscountAmount());
}

boolean skuMatch = request.getProductSkus().stream().anyMatch(x->promotion.get().getProductSkus().contains(x));
boolean skuMatch =
request.getProductSkus().stream()
.anyMatch(x -> promotion.get().getProductSkus().contains(x));
if (skuMatch) {
return new ApplyCodeResponse(
request.getCode(),
promotion.get().getDiscountAmount(),
promotion.get().getMaxDiscountAmount());
request.getCode(),
promotion.get().getDiscountAmount(),
promotion.get().getMaxDiscountAmount());
}
throw new BadRequestException("Cannot use discount code.");
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.MockitoAnnotations;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
Expand All @@ -18,7 +17,6 @@
import org.springframework.http.MediaType;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;

@ExtendWith(SpringExtension.class)
@AutoConfigureMockMvc(addFilters = false)
Expand All @@ -32,15 +30,14 @@ public class CartControllerTest {

@Autowired private MockMvc mockMvc;

// @InjectMocks private CartController cartController;
// @InjectMocks private CartController cartController;

@MockBean
private CartService cartService;
@MockBean private CartService cartService;

@BeforeEach
public void setup() {
MockitoAnnotations.openMocks(this);
// this.mockMvc = MockMvcBuilders.standaloneSetup(cartController).build();
// this.mockMvc = MockMvcBuilders.standaloneSetup(cartController).build();
}

@Test
Expand All @@ -49,11 +46,12 @@ public void getCart_ReturnsOk() throws Exception {
.andExpect(status().isOk());
}

// @Test
// public void applyCodeIfSuccess_ShouldReturnOk() throws Exception {
// String username = "TechNinja";
// when(cartService.applyCode(anyString(), any())).thenReturn(new ApplyCodeResponse());
// mockMvc.perform(post("/api/v1/carts/{username}/promotions", username).contentType(MediaType.APPLICATION_JSON))
// .andExpect(status().isOk());
// }
// @Test
// public void applyCodeIfSuccess_ShouldReturnOk() throws Exception {
// String username = "TechNinja";
// when(cartService.applyCode(anyString(), any())).thenReturn(new ApplyCodeResponse());
// mockMvc.perform(post("/api/v1/carts/{username}/promotions",
// username).contentType(MediaType.APPLICATION_JSON))
// .andExpect(status().isOk());
// }
}

0 comments on commit 5f6de03

Please sign in to comment.