include sender id in tests

This commit is contained in:
Daniel Gultsch 2023-03-01 15:19:51 +01:00
parent c2bf9d0413
commit be6f4300da
No known key found for this signature in database
GPG key ID: F43D18AD2A0982C2
2 changed files with 45 additions and 8 deletions

View file

@ -71,7 +71,12 @@ public class MessageTransformationTest {
reaction.setContent("Y"); reaction.setContent("Y");
this.transformer.transform( this.transformer.transform(
MessageTransformation.of( MessageTransformation.of(
reactionMessage, Instant.now(), REMOTE, "stanza-b", null, null)); reactionMessage,
Instant.now(),
REMOTE,
"stanza-b",
reactionMessage.getFrom().asBareJid(),
null));
final var originalMessage = new Message(); final var originalMessage = new Message();
originalMessage.setId("1"); originalMessage.setId("1");
originalMessage.setTo(REMOTE); originalMessage.setTo(REMOTE);
@ -80,7 +85,12 @@ public class MessageTransformationTest {
body.setContent(GREETING); body.setContent(GREETING);
this.transformer.transform( this.transformer.transform(
MessageTransformation.of( MessageTransformation.of(
originalMessage, Instant.now(), REMOTE, "stanza-a", null, null)); originalMessage,
Instant.now(),
REMOTE,
"stanza-a",
originalMessage.getFrom().asBareJid(),
null));
final var messages = database.messageDao().getMessages(1L); final var messages = database.messageDao().getMessages(1L);
Assert.assertEquals(1, messages.size()); Assert.assertEquals(1, messages.size());
@ -151,7 +161,12 @@ public class MessageTransformationTest {
this.transformer.transform( this.transformer.transform(
MessageTransformation.of( MessageTransformation.of(
messageCorrection, Instant.now(), REMOTE, "stanza-a", null, null)); messageCorrection,
Instant.now(),
REMOTE,
"stanza-a",
messageCorrection.getFrom().asBareJid(),
null));
// the correction should not show up as a message // the correction should not show up as a message
Assert.assertEquals(0, database.messageDao().getMessages(1L).size()); Assert.assertEquals(0, database.messageDao().getMessages(1L).size());
@ -164,7 +179,12 @@ public class MessageTransformationTest {
this.transformer.transform( this.transformer.transform(
MessageTransformation.of( MessageTransformation.of(
messageWithTypo, Instant.now(), REMOTE, "stanza-b", null, null)); messageWithTypo,
Instant.now(),
REMOTE,
"stanza-b",
messageWithTypo.getFrom().asBareJid(),
null));
final var messages = database.messageDao().getMessages(1L); final var messages = database.messageDao().getMessages(1L);
@ -187,7 +207,12 @@ public class MessageTransformationTest {
this.transformer.transform( this.transformer.transform(
MessageTransformation.of( MessageTransformation.of(
messageWithTypo, Instant.now(), REMOTE, "stanza-a", null, null)); messageWithTypo,
Instant.now(),
REMOTE,
"stanza-a",
messageWithTypo.getFrom().asBareJid(),
null));
Assert.assertEquals(1, database.messageDao().getMessages(1L).size()); Assert.assertEquals(1, database.messageDao().getMessages(1L).size());
@ -200,7 +225,12 @@ public class MessageTransformationTest {
this.transformer.transform( this.transformer.transform(
MessageTransformation.of( MessageTransformation.of(
messageCorrection, Instant.now(), REMOTE, "stanza-b", null, null)); messageCorrection,
Instant.now(),
REMOTE,
"stanza-b",
messageCorrection.getFrom().asBareJid(),
null));
final var messages = database.messageDao().getMessages(1L); final var messages = database.messageDao().getMessages(1L);
@ -504,7 +534,8 @@ public class MessageTransformationTest {
m1.addExtension(new Body("It is raining outside")); m1.addExtension(new Body("It is raining outside"));
this.transformer.transform( this.transformer.transform(
MessageTransformation.of(m1, Instant.now(), REMOTE, null, null, null)); MessageTransformation.of(
m1, Instant.now(), REMOTE, null, m1.getFrom().asBareJid(), null));
final var m2 = new Message(); final var m2 = new Message();
m2.setTo(ACCOUNT); m2.setTo(ACCOUNT);
@ -512,7 +543,8 @@ public class MessageTransformationTest {
m2.addExtension(new Retract()).setId("m1"); m2.addExtension(new Retract()).setId("m1");
this.transformer.transform( this.transformer.transform(
MessageTransformation.of(m2, Instant.now(), REMOTE, null, null, null)); MessageTransformation.of(
m2, Instant.now(), REMOTE, null, m2.getFrom().asBareJid(), null));
final var messages = database.messageDao().getMessages(1L); final var messages = database.messageDao().getMessages(1L);
final var message = Iterables.getOnlyElement(messages); final var message = Iterables.getOnlyElement(messages);

View file

@ -1,6 +1,7 @@
package im.conversations.android.transformer; package im.conversations.android.transformer;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import com.google.common.base.Preconditions;
import com.google.common.collect.Collections2; import com.google.common.collect.Collections2;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
@ -114,6 +115,10 @@ public class MessageTransformation extends Transformation {
final var messageId = message.getId(); final var messageId = message.getId();
final ImmutableList.Builder<Extension> extensionListBuilder = new ImmutableList.Builder<>(); final ImmutableList.Builder<Extension> extensionListBuilder = new ImmutableList.Builder<>();
final Collection<DeliveryReceiptRequest> requests; final Collection<DeliveryReceiptRequest> requests;
if (type != Message.Type.GROUPCHAT) {
Preconditions.checkNotNull(
senderId, "senderId must not be null for anything but group chat messages");
}
if (type == Message.Type.ERROR) { if (type == Message.Type.ERROR) {
extensionListBuilder.add(message.getError()); extensionListBuilder.add(message.getError());
requests = Collections.emptyList(); requests = Collections.emptyList();