我目前正在测试中使用等待功能。我正在尝试将消息发布到我的 pubnub 控制台。然而,由于我已经实施了取消订阅拆解,这目前没有发生。我正在为等待的语法而苦苦挣扎。我有几行来告诉你我一直在做什么。有人可以指出我正确的道路吗?
import com.pubnub.api.PubnubException;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import service.PubnubService;
import static com.jayway.awaitility.Awaitility.await;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
/**
* Created by peterki on 07/09/2016.
*/
public class PublisherTest {
private PubnubService service = new PubnubService();
//Arrange method for all of the tests
@Before
public void setupConnection() throws PubnubException {
// Setup Subscriber
service.subscribe("my_channel");
// Do nothing until the subscriber has connected.
do{} while (!service.isConnected());
}
@After
public void TeardownConnection() throws PubnubException {
// Unsubscribe from channel after each test has completed. So that the next test isn't waiting so subscribe.
service.unsubscribe("my_channel");
}
@Test
public void testSportMessageType() throws PubnubException {
// Publish to External Service
service.publish("my_channel", "Hello Peter");
//Wait till we receive the message
await().until(); -> service.publish("my_channel"); == 1;
await().until(() -> service.publish("my_channel", "Hello Peter")() == 1);
// Assert the message is what we want
}
}