-
Notifications
You must be signed in to change notification settings - Fork 0
/
SingleMessageListener.java
32 lines (25 loc) · 1.01 KB
/
SingleMessageListener.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package com.yskang.auctionsniper.test;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.TimeUnit;
import org.hamcrest.Matcher;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.is;
import org.jivesoftware.smack.Chat;
import org.jivesoftware.smack.MessageListener;
import org.jivesoftware.smack.packet.Message;
import android.util.Log;
public class SingleMessageListener implements MessageListener {
private final ArrayBlockingQueue<Message> messages = new ArrayBlockingQueue<Message>(
1);
public void processMessage(Chat chat, Message message) {
Log.d("yskang", "Fake server receive msg: " + message.getBody());
messages.add(message);
}
public void receivesAMessage(Matcher<? super String> messageMatcher)
throws InterruptedException {
final Message message = messages.poll(5, TimeUnit.SECONDS);
assertThat(message, is(notNullValue()));
assertThat(message.getBody(), messageMatcher);
}
}