-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Task 28 : Revise CourierServiceTest with adding mapper tests
- Loading branch information
1 parent
1afc40c
commit f24658b
Showing
3 changed files
with
201 additions
and
7 deletions.
There are no files selected for viewing
95 changes: 95 additions & 0 deletions
95
...asestudy/migroscouriertracking/courier/model/mapper/CourierEntityToCourierMapperTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package com.casestudy.migroscouriertracking.courier.model.mapper; | ||
|
||
import com.casestudy.migroscouriertracking.courier.model.Courier; | ||
import com.casestudy.migroscouriertracking.courier.model.entity.CourierEntity; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.*; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
class CourierEntityToCourierMapperTest { | ||
|
||
private final CourierEntityToCourierMapper mapper = CourierEntityToCourierMapper.initialize(); | ||
|
||
@Test | ||
void testMapCourierEntityCollectionNull() { | ||
|
||
List<Courier> result = mapper.map((Collection<CourierEntity>) null); | ||
assertNull(result); | ||
|
||
} | ||
|
||
@Test | ||
void testMapCourierEntityListNull() { | ||
|
||
List<Courier> result = mapper.map((List<CourierEntity>) null); | ||
assertNull(result); | ||
} | ||
|
||
@Test | ||
void testMapCourierEntityListEmpty() { | ||
|
||
List<Courier> result = mapper.map(Collections.emptyList()); | ||
assertNotNull(result); | ||
assertTrue(result.isEmpty()); | ||
|
||
} | ||
|
||
|
||
@Test | ||
void testMapCourierEntityListWithNullElements() { | ||
|
||
List<CourierEntity> courierEntities = Arrays.asList(new CourierEntity(), null); | ||
List<Courier> result = mapper.map(courierEntities); | ||
assertNotNull(result); | ||
assertEquals(2, result.size()); | ||
assertNull(result.get(1)); | ||
|
||
} | ||
|
||
|
||
@Test | ||
void testMapSingleCourierEntity() { | ||
|
||
CourierEntity courierEntity = CourierEntity.builder() | ||
.id(UUID.randomUUID().toString()) | ||
.courierId(UUID.randomUUID().toString()) | ||
.lat(47.0) | ||
.lng(8.0) | ||
.storeName("Migros") | ||
.timestamp(LocalDateTime.now()) | ||
.build(); | ||
|
||
Courier result = mapper.map(courierEntity); | ||
|
||
assertNotNull(result); | ||
assertEquals(courierEntity.getId(), result.getId()); | ||
assertEquals(courierEntity.getCourierId(), result.getCourierId()); | ||
assertEquals(courierEntity.getLat(), result.getLat()); | ||
assertEquals(courierEntity.getLng(), result.getLng()); | ||
assertEquals(courierEntity.getStoreName(), result.getStoreName()); | ||
assertEquals(courierEntity.getTimestamp(), result.getTimestamp()); | ||
|
||
} | ||
|
||
@Test | ||
void testMapWithEdgeCaseValues() { | ||
|
||
CourierEntity courierEntity = CourierEntity.builder() | ||
.lat(Double.MAX_VALUE) | ||
.lng(Double.MIN_VALUE) | ||
.timestamp(LocalDateTime.of(2024, 9, 29, 16, 30)) | ||
.build(); | ||
|
||
Courier result = mapper.map(courierEntity); | ||
|
||
assertNotNull(result); | ||
assertEquals(Double.MAX_VALUE, result.getLat()); | ||
assertEquals(Double.MIN_VALUE, result.getLng()); | ||
assertEquals(LocalDateTime.of(2024, 9, 29, 16, 30), result.getTimestamp()); | ||
|
||
} | ||
|
||
} |
95 changes: 95 additions & 0 deletions
95
...estudy/migroscouriertracking/courier/model/mapper/CourierToCourierResponseMapperTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package com.casestudy.migroscouriertracking.courier.model.mapper; | ||
|
||
import com.casestudy.migroscouriertracking.courier.model.Courier; | ||
import com.casestudy.migroscouriertracking.courier.model.dto.response.CourierResponse; | ||
import com.casestudy.migroscouriertracking.courier.model.entity.CourierEntity; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.*; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
class CourierToCourierResponseMapperTest { | ||
|
||
private final CourierToCourierResponseMapper mapper = CourierToCourierResponseMapper.initialize(); | ||
|
||
@Test | ||
void testMapCourierCollectionNull() { | ||
|
||
List<CourierResponse> result = mapper.map((Collection<Courier>) null); | ||
assertNull(result); | ||
|
||
} | ||
|
||
@Test | ||
void testMapCourierListNull() { | ||
|
||
List<CourierResponse> result = mapper.map((List<Courier>) null); | ||
assertNull(result); | ||
|
||
} | ||
|
||
@Test | ||
void testMapCourierListEmpty() { | ||
|
||
List<CourierResponse> result = mapper.map(Collections.emptyList()); | ||
assertNotNull(result); | ||
assertTrue(result.isEmpty()); | ||
|
||
} | ||
|
||
@Test | ||
void testMapCourierListWithNullElements() { | ||
|
||
List<Courier> couriers = Arrays.asList(new Courier(), null); | ||
List<CourierResponse> result = mapper.map(couriers); | ||
assertNotNull(result); | ||
assertEquals(2, result.size()); | ||
assertNull(result.get(1)); | ||
|
||
} | ||
|
||
|
||
@Test | ||
void testMapSingleCourier() { | ||
|
||
Courier courier = Courier.builder() | ||
.id(UUID.randomUUID().toString()) | ||
.courierId("courier123") | ||
.lat(47.0) | ||
.lng(8.0) | ||
.storeName("Migros") | ||
.timestamp(LocalDateTime.now()) | ||
.build(); | ||
|
||
CourierResponse result = mapper.map(courier); | ||
|
||
assertNotNull(result); | ||
assertEquals(courier.getId(), result.getId()); | ||
assertEquals(courier.getLat(), result.getLat()); | ||
assertEquals(courier.getLng(), result.getLng()); | ||
assertEquals(courier.getStoreName(), result.getStoreName()); | ||
assertEquals(courier.getTimestamp(), result.getTimestamp()); | ||
|
||
} | ||
|
||
@Test | ||
void testMapWithEdgeCaseValues() { | ||
|
||
Courier courier = Courier.builder() | ||
.lat(Double.MAX_VALUE) | ||
.lng(Double.MIN_VALUE) | ||
.timestamp(LocalDateTime.of(2024, 9, 29, 16, 30)) | ||
.build(); | ||
|
||
CourierResponse result = mapper.map(courier); | ||
|
||
assertNotNull(result); | ||
assertEquals(Double.MAX_VALUE, result.getLat()); | ||
assertEquals(Double.MIN_VALUE, result.getLng()); | ||
assertEquals(LocalDateTime.of(2024, 9, 29, 16, 30), result.getTimestamp()); | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters