Skip to content

Commit 48aa8e6

Browse files
author
Rafael Marinho
committed
format
1 parent a5f4f24 commit 48aa8e6

File tree

1 file changed

+44
-42
lines changed

1 file changed

+44
-42
lines changed

src/test/java/io/getstream/chat/java/SharedLocationTest.java

Lines changed: 44 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,9 @@
77
import io.getstream.chat.java.models.SharedLocation;
88
import io.getstream.chat.java.models.SharedLocation.ActiveLiveLocationsResponse;
99
import io.getstream.chat.java.models.SharedLocation.SharedLocationRequest;
10-
import io.getstream.chat.java.models.SharedLocation.SharedLocationResponse;
11-
import io.getstream.chat.java.models.User.UserRequestObject;
1210
import java.text.ParseException;
1311
import java.text.SimpleDateFormat;
14-
import java.util.Collections;
1512
import java.util.Date;
16-
import java.util.HashMap;
1713
import java.util.TimeZone;
1814
import java.util.UUID;
1915
import org.junit.jupiter.api.Assertions;
@@ -24,10 +20,11 @@ public class SharedLocationTest extends BasicTest {
2420

2521
@DisplayName("Can send message with shared location and verify")
2622
@Test
27-
void whenSendingMessageWithSharedLocation_thenCanGetThroughUsersLocations() throws StreamException, ParseException {
23+
void whenSendingMessageWithSharedLocation_thenCanGetThroughUsersLocations()
24+
throws StreamException, ParseException {
2825
// Create a unique device ID for this test
2926
String deviceId = "device-" + UUID.randomUUID().toString();
30-
27+
3128
// Create shared location request
3229
SharedLocationRequest locationRequest = new SharedLocation.SharedLocationRequest();
3330
locationRequest.setCreatedByDeviceId(deviceId);
@@ -46,25 +43,27 @@ void whenSendingMessageWithSharedLocation_thenCanGetThroughUsersLocations() thro
4643
sharedLocation.setEndAt(dateFormat.parse(locationRequest.getEndAt()));
4744

4845
// Send message with shared location
49-
MessageRequestObject messageRequest = MessageRequestObject.builder()
50-
.text("I'm sharing my live location")
51-
.userId(testUserRequestObject.getId())
52-
.type(MessageType.REGULAR)
53-
.sharedLocation(sharedLocation)
54-
.build();
55-
56-
Message message = Message.send(testChannel.getType(), testChannel.getId())
57-
.message(messageRequest)
58-
.request()
59-
.getMessage();
46+
MessageRequestObject messageRequest =
47+
MessageRequestObject.builder()
48+
.text("I'm sharing my live location")
49+
.userId(testUserRequestObject.getId())
50+
.type(MessageType.REGULAR)
51+
.sharedLocation(sharedLocation)
52+
.build();
53+
54+
Message message =
55+
Message.send(testChannel.getType(), testChannel.getId())
56+
.message(messageRequest)
57+
.request()
58+
.getMessage();
6059

6160
// Verify message was sent with correct shared location
6261
Assertions.assertNotNull(message);
6362
Assertions.assertNotNull(message.getSharedLocation());
6463
Assertions.assertEquals(deviceId, message.getSharedLocation().getCreatedByDeviceId());
6564
Assertions.assertEquals(40.7128, message.getSharedLocation().getLatitude());
6665
Assertions.assertEquals(-74.0060, message.getSharedLocation().getLongitude());
67-
66+
6867
// Parse and verify the endAt date
6968
Date expectedEndAt = dateFormat.parse("2025-12-31T23:59:59Z");
7069
Assertions.assertEquals(expectedEndAt, message.getSharedLocation().getEndAt());
@@ -75,7 +74,7 @@ void whenSendingMessageWithSharedLocation_thenCanGetThroughUsersLocations() thro
7574
void whenUpdatingLiveLocation_thenCanGetUpdatedLocation() throws StreamException, ParseException {
7675
// Create a unique device ID for this test
7776
String deviceId = "device-" + UUID.randomUUID().toString();
78-
77+
7978
// Create initial shared location request
8079
SharedLocationRequest initialLocationRequest = new SharedLocation.SharedLocationRequest();
8180
initialLocationRequest.setCreatedByDeviceId(deviceId);
@@ -94,17 +93,19 @@ void whenUpdatingLiveLocation_thenCanGetUpdatedLocation() throws StreamException
9493
initialSharedLocation.setEndAt(dateFormat.parse(initialLocationRequest.getEndAt()));
9594

9695
// Send initial message with shared location
97-
MessageRequestObject initialMessageRequest = MessageRequestObject.builder()
98-
.text("I'm sharing my live location")
99-
.userId(testUserRequestObject.getId())
100-
.type(MessageType.REGULAR)
101-
.sharedLocation(initialSharedLocation)
102-
.build();
103-
104-
Message initialMessage = Message.send(testChannel.getType(), testChannel.getId())
105-
.message(initialMessageRequest)
106-
.request()
107-
.getMessage();
96+
MessageRequestObject initialMessageRequest =
97+
MessageRequestObject.builder()
98+
.text("I'm sharing my live location")
99+
.userId(testUserRequestObject.getId())
100+
.type(MessageType.REGULAR)
101+
.sharedLocation(initialSharedLocation)
102+
.build();
103+
104+
Message initialMessage =
105+
Message.send(testChannel.getType(), testChannel.getId())
106+
.message(initialMessageRequest)
107+
.request()
108+
.getMessage();
108109

109110
// Create updated location request
110111
SharedLocationRequest updatedLocationRequest = new SharedLocation.SharedLocationRequest();
@@ -116,32 +117,33 @@ void whenUpdatingLiveLocation_thenCanGetUpdatedLocation() throws StreamException
116117
updatedLocationRequest.setUserId(testUserRequestObject.getId());
117118

118119
// Update the location
119-
SharedLocation.SharedLocationResponse updateResponse = SharedLocation.updateLocation()
120-
.userId(testUserRequestObject.getId())
121-
.request(updatedLocationRequest)
122-
.request();
120+
SharedLocation.SharedLocationResponse updateResponse =
121+
SharedLocation.updateLocation()
122+
.userId(testUserRequestObject.getId())
123+
.request(updatedLocationRequest)
124+
.request();
123125

124126
// Get active live locations
125-
ActiveLiveLocationsResponse activeLocations = SharedLocation.getLocations()
126-
.userId(testUserRequestObject.getId())
127-
.request();
127+
ActiveLiveLocationsResponse activeLocations =
128+
SharedLocation.getLocations().userId(testUserRequestObject.getId()).request();
128129

129130
// Verify the updated location
130131
Assertions.assertNotNull(activeLocations);
131132
Assertions.assertNotNull(activeLocations.getActiveLiveLocations());
132133
Assertions.assertFalse(activeLocations.getActiveLiveLocations().isEmpty());
133134

134135
// Find our location in the response
135-
SharedLocation updatedLocation = activeLocations.getActiveLiveLocations().stream()
136-
.filter(loc -> deviceId.equals(loc.getCreatedByDeviceId()))
137-
.findFirst()
138-
.orElse(null);
136+
SharedLocation updatedLocation =
137+
activeLocations.getActiveLiveLocations().stream()
138+
.filter(loc -> deviceId.equals(loc.getCreatedByDeviceId()))
139+
.findFirst()
140+
.orElse(null);
139141

140142
Assertions.assertNotNull(updatedLocation);
141143
Assertions.assertEquals(deviceId, updatedLocation.getCreatedByDeviceId());
142144
Assertions.assertEquals(40.7589, updatedLocation.getLatitude());
143145
Assertions.assertEquals(-73.9851, updatedLocation.getLongitude());
144-
146+
145147
// Verify the endAt date
146148
Date expectedEndAt = dateFormat.parse("2025-12-31T23:59:59Z");
147149
Assertions.assertEquals(expectedEndAt, updatedLocation.getEndAt());

0 commit comments

Comments
 (0)