Deduplicate code
This commit is contained in:
parent
6a2416e81e
commit
7067e1a65e
@ -19,8 +19,8 @@ import static org.telegram.abilitybots.api.bot.TestUtils.mockContext;
|
||||
import static org.telegram.abilitybots.api.db.MapDBContext.offlineInstance;
|
||||
|
||||
class AbilityBotI18nTest {
|
||||
private static final User NO_LANGUAGE_USER = new User(1L, "first", false, "last", "username", null, false, false, false);
|
||||
private static final User ITALIAN_USER = new User(2L, "first", false, "last", "username", "it-IT", false, false, false);
|
||||
private static final User NO_LANGUAGE_USER = new User(1L, "first", false, "last", "username", null, false, false, false, null, null, null, null, null);
|
||||
private static final User ITALIAN_USER = new User(2L, "first", false, "last", "username", "it-IT", false, false, false, null, null, null, null, null);
|
||||
|
||||
private DBContext db;
|
||||
private NoPublicCommandsBot bot;
|
||||
|
@ -374,7 +374,7 @@ public class AbilityBotTest {
|
||||
String newFirstName = USER.getFirstName() + "-test";
|
||||
String newLastName = USER.getLastName() + "-test";
|
||||
long sameId = USER.getId();
|
||||
User changedUser = new User(sameId, newFirstName, false, newLastName, newUsername, "en", false, false, false);
|
||||
User changedUser = new User(sameId, newFirstName, false, newLastName, newUsername, "en", false, false, false, null, null, null, null, null);
|
||||
|
||||
mockAlternateUser(update, message, changedUser);
|
||||
|
||||
|
@ -11,8 +11,8 @@ import static org.mockito.Mockito.when;
|
||||
import static org.telegram.abilitybots.api.objects.MessageContext.newContext;
|
||||
|
||||
public final class TestUtils {
|
||||
public static final User USER = new User(1L, "first", false, "last", "username", null, false, false, false);
|
||||
public static final User CREATOR = new User(1337L, "creatorFirst", false, "creatorLast", "creatorUsername", null, false, false, false);
|
||||
public static final User USER = new User(1L, "first", false, "last", "username", null, false, false, false, null, null, null, null, null);
|
||||
public static final User CREATOR = new User(1337L, "creatorFirst", false, "creatorLast", "creatorUsername", null, false, false, false, null, null, null, null, null);
|
||||
|
||||
private TestUtils() {
|
||||
|
||||
|
@ -50,8 +50,7 @@ public class RestApi {
|
||||
}
|
||||
return Response.ok(response).build();
|
||||
} catch (MalformedUpdateException e) {
|
||||
log.error("Malformed update", e.getCause());;
|
||||
return Response.status(Status.BAD_REQUEST).build();
|
||||
return handleMalformedUpdate(e);
|
||||
} catch (TooManyRequestsException e) {
|
||||
if (e.getProcessedRequestsCount().isPresent()) {
|
||||
return Response
|
||||
@ -87,8 +86,7 @@ public class RestApi {
|
||||
}
|
||||
return Response.ok(responses).build();
|
||||
} catch (MalformedUpdateException e) {
|
||||
log.error("Malformed update", e.getCause());
|
||||
return Response.status(Status.BAD_REQUEST).build();
|
||||
return handleMalformedUpdate(e);
|
||||
} catch (TooManyRequestsException e) {
|
||||
if (e.getProcessedRequestsCount().isPresent()) {
|
||||
return Response
|
||||
@ -107,6 +105,15 @@ public class RestApi {
|
||||
return Response.status(Response.Status.NOT_FOUND).build();
|
||||
}
|
||||
|
||||
private Response handleMalformedUpdate(MalformedUpdateException e) {
|
||||
log.error("Malformed update", e.getCause());;
|
||||
return Response
|
||||
.status(Status.BAD_REQUEST)
|
||||
.entity(e.getCause() == null ? "" : e.getCause().getMessage())
|
||||
.type(MediaType.TEXT_PLAIN)
|
||||
.build();
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/{botPath}")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
|
Loading…
x
Reference in New Issue
Block a user