|
5 | 5 | import java.util.List;
|
6 | 6 | import jakarta.persistence.EntityManager;
|
7 | 7 | import jakarta.persistence.PersistenceContext;
|
8 |
| -import org.hibernate.boot.model.source.internal.hbm.XmlElementMetadata; |
9 |
| -import org.junit.jupiter.api.BeforeAll; |
10 | 8 | import org.junit.jupiter.api.BeforeEach;
|
11 | 9 | import org.junit.jupiter.api.DisplayName;
|
12 | 10 | import org.junit.jupiter.api.Nested;
|
@@ -44,7 +42,7 @@ class StaccatoRepositoryTest extends RepositoryTest {
|
44 | 42 | class FindAllStaccatosBy {
|
45 | 43 | private static final BigDecimal MIN_LATITUDE = new BigDecimal("37.4");
|
46 | 44 | private static final BigDecimal MAX_LATITUDE = new BigDecimal("37.5");
|
47 |
| - private static final BigDecimal MIN_LONGITUDE= new BigDecimal("127.1"); |
| 45 | + private static final BigDecimal MIN_LONGITUDE = new BigDecimal("127.1"); |
48 | 46 | private static final BigDecimal MAX_LONGITUDE = new BigDecimal("127.2");
|
49 | 47 |
|
50 | 48 | Member member;
|
@@ -72,67 +70,107 @@ void init() {
|
72 | 70 | .buildAndSave(staccatoRepository);
|
73 | 71 | }
|
74 | 72 |
|
75 |
| - @DisplayName("아무 조건 없음 (staccatoInCategory1, staccatoInCategory2)") |
76 |
| - @Test |
77 |
| - void findAllStaccatoByMemberWithoutAnyCondition() { |
78 |
| - // given |
79 |
| - Member anotherMember = MemberFixtures.defaultMember().buildAndSave(memberRepository); |
80 |
| - Category anotherCategory = CategoryFixtures.defaultCategory() |
81 |
| - .buildAndSaveWithMember(anotherMember, categoryRepository); |
82 |
| - Staccato anotherStaccato = StaccatoFixtures.defaultStaccato() |
83 |
| - .withCategory(anotherCategory) |
84 |
| - .buildAndSave(staccatoRepository); |
| 73 | + @Nested |
| 74 | + @DisplayName("findByMemberAndLocationRange()") |
| 75 | + class FindByMemberAndLocationRange { |
| 76 | + @DisplayName("아무 조건 없음 (staccatoInCategory1, staccatoInCategory2)") |
| 77 | + @Test |
| 78 | + void findAllStaccatoByMemberWithoutAnyCondition() { |
| 79 | + // given |
| 80 | + Member anotherMember = MemberFixtures.defaultMember().buildAndSave(memberRepository); |
| 81 | + Category anotherCategory = CategoryFixtures.defaultCategory() |
| 82 | + .buildAndSaveWithMember(anotherMember, categoryRepository); |
| 83 | + Staccato anotherStaccato = StaccatoFixtures.defaultStaccato() |
| 84 | + .withCategory(anotherCategory) |
| 85 | + .buildAndSave(staccatoRepository); |
85 | 86 |
|
86 |
| - // when |
87 |
| - List<Staccato> result = staccatoRepository.findByMemberAndLocationRangeAndCategory(member, null, null, null, null, null); |
| 87 | + // when |
| 88 | + List<Staccato> result = staccatoRepository.findByMemberAndLocationRange(member, null, null, null, null); |
88 | 89 |
|
89 |
| - // then |
90 |
| - assertThat(result).hasSize(2).containsExactlyInAnyOrder(staccatoInCategory1, staccatoInCategory2) |
91 |
| - .doesNotContain(anotherStaccato); |
92 |
| - } |
| 90 | + // then |
| 91 | + assertThat(result).hasSize(2).containsExactlyInAnyOrder(staccatoInCategory1, staccatoInCategory2) |
| 92 | + .doesNotContain(anotherStaccato); |
| 93 | + } |
93 | 94 |
|
94 |
| - @DisplayName("위경도 범위 내 (staccatoInCategory1, staccatoInCategory2)") |
95 |
| - @Test |
96 |
| - void findAllStaccatoByMemberWithLocationRange() { |
97 |
| - // given |
98 |
| - BigDecimal threshold = new BigDecimal("0.01"); |
99 |
| - Staccato underMinLatitude = StaccatoFixtures.defaultStaccato() |
100 |
| - .withCategory(category1ByMember) |
101 |
| - .withSpot(MIN_LATITUDE.subtract(threshold), MAX_LONGITUDE) |
102 |
| - .buildAndSave(staccatoRepository); |
103 |
| - Staccato overMaxLatitude = StaccatoFixtures.defaultStaccato() |
104 |
| - .withCategory(category1ByMember) |
105 |
| - .withSpot(MAX_LATITUDE.add(threshold), MIN_LONGITUDE) |
106 |
| - .buildAndSave(staccatoRepository); |
107 |
| - Staccato underMinLongitude = StaccatoFixtures.defaultStaccato() |
108 |
| - .withCategory(category1ByMember) |
109 |
| - .withSpot(MAX_LATITUDE, MIN_LONGITUDE.subtract(threshold)) |
110 |
| - .buildAndSave(staccatoRepository); |
111 |
| - Staccato overMaxLongitude = StaccatoFixtures.defaultStaccato() |
112 |
| - .withCategory(category1ByMember) |
113 |
| - .withSpot(MIN_LATITUDE, MAX_LONGITUDE.add(threshold)) |
114 |
| - .buildAndSave(staccatoRepository); |
| 95 | + @DisplayName("위경도 범위 내 (staccatoInCategory1, staccatoInCategory2)") |
| 96 | + @Test |
| 97 | + void findAllStaccatoByMemberWithLocationRange() { |
| 98 | + // given |
| 99 | + BigDecimal threshold = new BigDecimal("0.01"); |
| 100 | + Staccato underMinLatitude = StaccatoFixtures.defaultStaccato() |
| 101 | + .withCategory(category1ByMember) |
| 102 | + .withSpot(MIN_LATITUDE.subtract(threshold), MAX_LONGITUDE) |
| 103 | + .buildAndSave(staccatoRepository); |
| 104 | + Staccato overMaxLatitude = StaccatoFixtures.defaultStaccato() |
| 105 | + .withCategory(category1ByMember) |
| 106 | + .withSpot(MAX_LATITUDE.add(threshold), MIN_LONGITUDE) |
| 107 | + .buildAndSave(staccatoRepository); |
| 108 | + Staccato underMinLongitude = StaccatoFixtures.defaultStaccato() |
| 109 | + .withCategory(category1ByMember) |
| 110 | + .withSpot(MAX_LATITUDE, MIN_LONGITUDE.subtract(threshold)) |
| 111 | + .buildAndSave(staccatoRepository); |
| 112 | + Staccato overMaxLongitude = StaccatoFixtures.defaultStaccato() |
| 113 | + .withCategory(category1ByMember) |
| 114 | + .withSpot(MIN_LATITUDE, MAX_LONGITUDE.add(threshold)) |
| 115 | + .buildAndSave(staccatoRepository); |
115 | 116 |
|
116 |
| - // when |
117 |
| - List<Staccato> result = staccatoRepository.findByMemberAndLocationRangeAndCategory( |
118 |
| - member, MIN_LATITUDE, MAX_LATITUDE, MIN_LONGITUDE, MAX_LONGITUDE, null |
119 |
| - ); |
| 117 | + // when |
| 118 | + List<Staccato> result = staccatoRepository.findByMemberAndLocationRange( |
| 119 | + member, MIN_LATITUDE, MAX_LATITUDE, MIN_LONGITUDE, MAX_LONGITUDE |
| 120 | + ); |
120 | 121 |
|
121 |
| - // then |
122 |
| - assertThat(result).hasSize(2).containsExactlyInAnyOrder(staccatoInCategory1, staccatoInCategory2) |
123 |
| - .doesNotContain(underMinLatitude, overMaxLatitude, underMinLongitude, overMaxLongitude); |
| 122 | + // then |
| 123 | + assertThat(result).hasSize(2).containsExactlyInAnyOrder(staccatoInCategory1, staccatoInCategory2) |
| 124 | + .doesNotContain(underMinLatitude, overMaxLatitude, underMinLongitude, overMaxLongitude); |
| 125 | + } |
124 | 126 | }
|
125 | 127 |
|
126 |
| - @DisplayName("특정 카테고리(category1ByMember)에 속한 모든 스타카토 (staccatoInCategory1)") |
127 |
| - @Test |
128 |
| - void findAllStaccatoByMemberWithCategory() { |
129 |
| - // when |
130 |
| - List<Staccato> result = staccatoRepository.findByMemberAndLocationRangeAndCategory(member, null, null, null, null, category1ByMember.getId()); |
| 128 | + @Nested |
| 129 | + @DisplayName("findByMemberAndLocationRangeAndCategory()") |
| 130 | + class FindByMemberAndLocationRangeAndCategory { |
| 131 | + @DisplayName("특정 카테고리(category1ByMember)에 속한 모든 스타카토 (staccatoInCategory1)") |
| 132 | + @Test |
| 133 | + void findAllStaccatoByMemberWithCategory() { |
| 134 | + // when |
| 135 | + List<Staccato> result = staccatoRepository.findByMemberAndLocationRangeAndCategory(member, null, null, null, null, category1ByMember.getId()); |
| 136 | + |
| 137 | + // then |
| 138 | + assertThat(result).hasSize(1) |
| 139 | + .containsExactlyInAnyOrder(staccatoInCategory1) |
| 140 | + .doesNotContain(staccatoInCategory2); |
| 141 | + } |
| 142 | + |
| 143 | + @DisplayName("특정 카테고리(category1ByMember)에 속하면서 위경도 범위 내 모든 스타카토 (staccatoInCategory1)") |
| 144 | + @Test |
| 145 | + void findAllStaccatoByMemberWithCategoryAndInRange() { |
| 146 | + // given |
| 147 | + BigDecimal threshold = new BigDecimal("0.01"); |
| 148 | + Staccato underMinLatitude = StaccatoFixtures.defaultStaccato() |
| 149 | + .withCategory(category1ByMember) |
| 150 | + .withSpot(MIN_LATITUDE.subtract(threshold), MAX_LONGITUDE) |
| 151 | + .buildAndSave(staccatoRepository); |
| 152 | + Staccato overMaxLatitude = StaccatoFixtures.defaultStaccato() |
| 153 | + .withCategory(category1ByMember) |
| 154 | + .withSpot(MAX_LATITUDE.add(threshold), MIN_LONGITUDE) |
| 155 | + .buildAndSave(staccatoRepository); |
| 156 | + Staccato underMinLongitude = StaccatoFixtures.defaultStaccato() |
| 157 | + .withCategory(category1ByMember) |
| 158 | + .withSpot(MAX_LATITUDE, MIN_LONGITUDE.subtract(threshold)) |
| 159 | + .buildAndSave(staccatoRepository); |
| 160 | + Staccato overMaxLongitude = StaccatoFixtures.defaultStaccato() |
| 161 | + .withCategory(category1ByMember) |
| 162 | + .withSpot(MIN_LATITUDE, MAX_LONGITUDE.add(threshold)) |
| 163 | + .buildAndSave(staccatoRepository); |
| 164 | + |
| 165 | + // when |
| 166 | + List<Staccato> result = staccatoRepository.findByMemberAndLocationRangeAndCategory( |
| 167 | + member, MIN_LATITUDE, MAX_LATITUDE, MIN_LONGITUDE, MAX_LONGITUDE, category1ByMember.getId()); |
131 | 168 |
|
132 |
| - // then |
133 |
| - assertThat(result).hasSize(1) |
134 |
| - .containsExactlyInAnyOrder(staccatoInCategory1) |
135 |
| - .doesNotContain(staccatoInCategory2); |
| 169 | + // then |
| 170 | + assertThat(result).hasSize(1) |
| 171 | + .containsExactlyInAnyOrder(staccatoInCategory1) |
| 172 | + .doesNotContain(staccatoInCategory2, underMinLatitude, overMaxLatitude, underMinLongitude, overMaxLongitude); |
| 173 | + } |
136 | 174 | }
|
137 | 175 | }
|
138 | 176 |
|
|
0 commit comments