서비스 테스트했을때 발생한 문제다.
@Test
@DisplayName("제품 등록: 회원만")
void addProductTest(){
given(memberRepository.getReferenceById(sellerId)).willReturn(member);
given(productRepository.save(any(Product.class))).willReturn(product);
// when
Long actual = productService.addProduct(name,price,quantity,sellerId);
// then
assertThat(actual).isEqualTo(product.getId());
}
@Transactional
public Long addProduct(String name, Price price, Quantity quantity, Long sellerId) {
Member seller = memberRepository.getReferenceById(sellerId);
Product product = new Product(seller,name,price,quantity);
productRepository.save(product);
return product.getId();
}
org.opentest4j.AssertionFailedError:
expected: 1L
but was: null
Expected :1L
Actual :null
@Id
@Column(name = "product_id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
Product product = new Product(1L, seller,name,price,quantity);