Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/origin/add-groseries' into…
Browse files Browse the repository at this point in the history
… add-groseries

# Conflicts:
#	backend/src/main/java/org/example/backend/ProductController.java
#	backend/src/test/java/org/example/backend/ProductControllerTest.java
#	backend/src/test/java/org/example/backend/ProductServiceTest.java
  • Loading branch information
Olgasyla committed Aug 22, 2024
2 parents 4b99bb9 + cd464d0 commit 4cc3140
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequiredArgsConstructor
Expand All @@ -20,6 +19,13 @@ public List<Product> getAllGroceries() {
public Product saveProduct(@RequestBody NewProduct newProduct) {
return productService.saveProduct(newProduct);
}

@DeleteMapping("{id}")
void delete(@PathVariable String id) {
productService.deletebyid(id);
}


@GetMapping("{id}")
public Product getGroceryProductById(@PathVariable String id){
return productService.findGroceriesById(id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ void deletebyid() throws Exception {
//Then
.andExpect(status().isOk());
}

@Test
@DirtiesContext
void addNewProduct() throws Exception {
Expand All @@ -60,7 +59,7 @@ void addNewProduct() throws Exception {
"amount": 1
}
"""))
//THEN
//THEN
.andExpect(status().isOk())
.andExpect(jsonPath("$.id").exists())
.andExpect(jsonPath("$.name").value("Milch"))
Expand Down
29 changes: 18 additions & 11 deletions backend/src/test/java/org/example/backend/ProductServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,23 @@ void addProdukt() {
verify(productRepository).save(saveProduct);
assertEquals(expected, actual);
}
@Test
void findGroceriesById() {
//GIVEN
String id = "4";
Product product = new Product("4","apple", 7);
when(productRepository.findById(id)).thenReturn(Optional.of(product));
//WHEN
Product actual = productService.findGroceriesById(id);
//THEN
verify(productRepository).findById(id);
assertEquals(product, actual);
@Test
void deleteProduct_Test() {
doNothing().when(productRepository).deleteById("2");
productService.deletebyid("2");
verify(productRepository).deleteById("2");
}

@Test
void findGroceriesById() {
//GIVEN
String id = "4";
Product product = new Product("4","apple", 7);
when(productRepository.findById(id)).thenReturn(Optional.of(product));
//WHEN
Product actual = productService.findGroceriesById(id);
//THEN
verify(productRepository).findById(id);
assertEquals(product, actual);
}
}

0 comments on commit 4cc3140

Please sign in to comment.