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