Skip to content

Commit 87e88bc

Browse files
Изменен порядок параметров метода enterScene в RegFinishHandler для улучшения читаемости кода; обновлены тесты в RegistrationSceneTest для проверки исключений
1 parent a67a9bc commit 87e88bc

File tree

2 files changed

+23
-24
lines changed

2 files changed

+23
-24
lines changed

src/main/java/ru/untitled_devs/bot/features/registration/handlers/RegFinishHandler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
import org.telegram.telegrambots.meta.api.objects.Message;
44
import ru.untitled_devs.bot.features.registration.RegistrationService;
55
import ru.untitled_devs.bot.features.registration.RegistrationStates;
6-
import ru.untitled_devs.bot.shared.localisation.ButtonKey;
76
import ru.untitled_devs.bot.shared.localisation.BtnLocService;
7+
import ru.untitled_devs.bot.shared.localisation.ButtonKey;
88
import ru.untitled_devs.bot.shared.localisation.MessageKey;
99
import ru.untitled_devs.bot.shared.localisation.MsgLocService;
1010
import ru.untitled_devs.bot.shared.models.Profile;
@@ -59,7 +59,7 @@ void action(Message message, FSMContext ctx) {
5959

6060
regService.registerUser(userData, profileData);
6161
bot.sendMessage(chatId, MsgLocService.getLocal(MessageKey.SUCCESSFUL_REGISTRATION, loc));
62-
sceneManager.enterScene("menu", chatId, ctx);
62+
sceneManager.enterScene(chatId, "menu", ctx);
6363
return;
6464
}
6565

src/test/java/ru/untitled_devs/bot/features/registration/RegistrationSceneTest.java

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import ru.untitled_devs.bot.shared.models.Profile;
1616
import ru.untitled_devs.core.client.PollingClient;
1717
import ru.untitled_devs.core.context.UpdateContext;
18+
import ru.untitled_devs.core.exceptions.StopRoutingException;
1819
import ru.untitled_devs.core.fsm.DataKey;
1920
import ru.untitled_devs.core.fsm.FSMContext;
2021
import ru.untitled_devs.core.routers.scenes.SceneManager;
@@ -85,7 +86,8 @@ void getNameGotValidName() {
8586
DataKey<Profile> key = DataKey.of("RegistrationData", Profile.class);
8687
when(ctx.getData(key)).thenReturn(profile);
8788

88-
assertDoesNotThrow(() -> router.routeUpdate(updateContext, ctx));
89+
assertThrows(StopRoutingException.class,
90+
() -> router.routeUpdate(updateContext, ctx));
8991
assertEquals("Саня", profile.getName());
9092
}
9193

@@ -105,7 +107,8 @@ void getNameGotInvalidName() {
105107
DataKey<Profile> key = DataKey.of("RegistrationData", Profile.class);
106108
when(ctx.getData(key)).thenReturn(profile);
107109

108-
assertDoesNotThrow(() -> router.routeUpdate(updateContext, ctx));
110+
assertThrows(StopRoutingException.class,
111+
() -> router.routeUpdate(updateContext, ctx));
109112
assertNull(profile.getName());
110113
}
111114

@@ -125,7 +128,8 @@ void getAgeGotDigitString() {
125128
DataKey<Profile> key = DataKey.of("RegistrationData", Profile.class);
126129
when(ctx.getData(key)).thenReturn(profile);
127130

128-
assertDoesNotThrow(() -> router.routeUpdate(updateContext, ctx),
131+
assertThrows(StopRoutingException.class,
132+
() -> router.routeUpdate(updateContext, ctx),
129133
"Get age must do not throw any exceptions when got valid age type");
130134

131135
assertEquals(15, profile.getAge(), "Age must be changed");
@@ -196,7 +200,8 @@ void getGenderGotValidGender() {
196200
DataKey<Profile> key = DataKey.of("RegistrationData", Profile.class);
197201
when(ctx.getData(key)).thenReturn(profile);
198202

199-
assertDoesNotThrow(() -> router.routeUpdate(updateContext, ctx));
203+
assertThrows(StopRoutingException.class,
204+
() -> router.routeUpdate(updateContext, ctx));
200205
assertEquals(Gender.FEMALE, profile.getGender());
201206
}
202207

@@ -236,9 +241,8 @@ void getLocationGotValidLocation() {
236241

237242
when(ctx.getState()).thenReturn(RegistrationStates.LOCATION);
238243

239-
assertDoesNotThrow(
240-
() -> router.routeUpdate(updateContext, ctx)
241-
);
244+
assertThrows(StopRoutingException.class,
245+
() -> router.routeUpdate(updateContext, ctx));
242246

243247
assertEquals("Екатеринбург", profile.getLocation());
244248
assertEquals(Arrays.asList(123.0, 123.0), profile.getCoordinates().getCoordinates().getValues());
@@ -285,9 +289,8 @@ void getLocationGotValidCoordinates() {
285289

286290
when(ctx.getState()).thenReturn(RegistrationStates.LOCATION);
287291

288-
assertDoesNotThrow(
289-
() -> router.routeUpdate(updateContext, ctx)
290-
);
292+
assertThrows(StopRoutingException.class,
293+
() -> router.routeUpdate(updateContext, ctx));
291294

292295
assertEquals("Екатеринбург", profile.getLocation());
293296
assertEquals(Arrays.asList(123.0, 123.0), profile.getCoordinates().getCoordinates().getValues());
@@ -311,9 +314,8 @@ void getLocationGotInvalidCoordinates() {
311314

312315
when(ctx.getState()).thenReturn(RegistrationStates.LOCATION);
313316

314-
assertDoesNotThrow(
315-
() -> router.routeUpdate(updateContext, ctx)
316-
);
317+
assertThrows(StopRoutingException.class,
318+
() -> router.routeUpdate(updateContext, ctx));
317319

318320
assertNull(profile.getLocation());
319321
assertNull(profile.getCoordinates());
@@ -336,9 +338,8 @@ void getDescriptionGotValidText() {
336338
when(update.getMessage()).thenReturn(message);
337339
when(ctx.getState()).thenReturn(RegistrationStates.DESCRIPTION);
338340

339-
assertDoesNotThrow(
340-
() -> router.routeUpdate(updateContext, ctx)
341-
);
341+
assertThrows(StopRoutingException.class,
342+
() -> router.routeUpdate(updateContext, ctx));
342343

343344
assertEquals("Test description", profile.getDescription());
344345
}
@@ -384,9 +385,8 @@ void getDescriptionGotSkipText() {
384385

385386
when(ctx.getState()).thenReturn(RegistrationStates.DESCRIPTION);
386387

387-
assertDoesNotThrow(
388-
() -> router.routeUpdate(updateContext, ctx)
389-
);
388+
assertThrows(StopRoutingException.class,
389+
() -> router.routeUpdate(updateContext, ctx));
390390

391391
assertEquals("No description.", profile.getDescription());
392392
}
@@ -424,9 +424,8 @@ void getPhotoGotValidPhoto() throws TelegramApiException, IOException {
424424

425425
when(ctx.getState()).thenReturn(RegistrationStates.PHOTO);
426426

427-
assertDoesNotThrow(
428-
() -> router.routeUpdate(updateContext, ctx)
429-
);
427+
assertThrows(StopRoutingException.class,
428+
() -> router.routeUpdate(updateContext, ctx));
430429
}
431430

432431
@Test

0 commit comments

Comments
 (0)