Skip to content

Commit

Permalink
test: mocking 삭제 및 상태 검증 테스트로 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
kokodak committed Oct 4, 2023
1 parent 071ba38 commit 6581ef9
Showing 1 changed file with 16 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
package com.now.naaga.temporaryplace.application;

import static org.mockito.Mockito.anyLong;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.assertj.core.api.Assertions.assertThat;

import com.now.naaga.common.builder.TemporaryPlaceBuilder;
import com.now.naaga.temporaryplace.domain.TemporaryPlace;
import com.now.naaga.temporaryplace.repository.TemporaryPlaceRepository;
import org.junit.jupiter.api.DisplayNameGeneration;
import org.junit.jupiter.api.DisplayNameGenerator.ReplaceUnderscores;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.jdbc.Sql;

Expand All @@ -22,21 +20,30 @@
@SpringBootTest
class TemporaryPlaceServiceTest {

@MockBean
@Autowired
private TemporaryPlaceRepository temporaryPlaceRepository;

@Autowired
private TemporaryPlaceService temporaryPlaceService;

@Autowired
private TemporaryPlaceBuilder temporaryPlaceBuilder;

@Test
void ID로_검수_장소_데이터를_삭제한다() {
// given
doNothing().when(temporaryPlaceRepository).deleteById(anyLong());
final TemporaryPlace temporaryPlace = temporaryPlaceBuilder.init()
.build();

final Long id = temporaryPlace.getId();

// when
temporaryPlaceService.deleteById(1L);
temporaryPlaceService.deleteById(id);

// then
verify(temporaryPlaceRepository, times(1)).deleteById(1L);
final TemporaryPlace actual = temporaryPlaceRepository.findById(id)
.orElse(null);

assertThat(actual).isNull();
}
}

0 comments on commit 6581ef9

Please sign in to comment.