本文整理匯總了Java中org.hamcrest.Matchers.not方法的典型用法代碼示例。如果您正苦於以下問題:Java Matchers.not方法的具體用法?Java Matchers.not怎麽用?Java Matchers.not使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.hamcrest.Matchers
的用法示例。
在下文中一共展示了Matchers.not方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: addMatcher_doesNotNegateMatcher_when_negateNextMatcher_isFalse
import org.hamcrest.Matchers; //導入方法依賴的package包/類
@Test
public void addMatcher_doesNotNegateMatcher_when_negateNextMatcher_isFalse() {
final Start.Matcher matcher = Cortado.view();
final Cortado cortado = matcher.getCortado();
assertThat(cortado.matchers).hasSize(0);
assertThat(cortado.negateNextMatcher).isFalse();
// no matchers added, negateNextMatcher is false
org.hamcrest.Matcher<View> viewMatcher = ViewMatchers.withText("test");
org.hamcrest.Matcher<View> negatedViewMatcher = Matchers.not(viewMatcher);
cortado.negateNextMatcher = false;
cortado.addMatcher(viewMatcher);
assertThat(cortado.matchers).hasSize(1);
// one matcher added
assertThat(cortado.negateNextMatcher).isFalse();
// negateNextMatcher is still false
final Matcher<? super View> addedMatcher = cortado.matchers.get(0);
Utils.assertThat(addedMatcher).isEqualTo(viewMatcher);
Utils.assertThat(addedMatcher).isNotEqualTo(negatedViewMatcher);
}
示例2: addMatcher_negatesMatcher_when_negateNextMatcher_isTrue
import org.hamcrest.Matchers; //導入方法依賴的package包/類
@Test
public void addMatcher_negatesMatcher_when_negateNextMatcher_isTrue() {
final Start.Matcher matcher = Cortado.view();
final Cortado cortado = matcher.getCortado();
assertThat(cortado.matchers).hasSize(0);
assertThat(cortado.negateNextMatcher).isFalse();
// no matchers added, negateNextMatcher is false
org.hamcrest.Matcher<View> viewMatcher = ViewMatchers.withText("test");
org.hamcrest.Matcher<View> negatedViewMatcher = Matchers.not(viewMatcher);
cortado.negateNextMatcher = true;
cortado.addMatcher(viewMatcher);
assertThat(cortado.matchers).hasSize(1);
// one matcher added
assertThat(cortado.negateNextMatcher).isFalse();
// negateNextMatcher is back to false
final Matcher<? super View> addedMatcher = cortado.matchers.get(0);
Utils.assertThat(addedMatcher).isNotEqualTo(viewMatcher);
Utils.assertThat(addedMatcher).isEqualTo(negatedViewMatcher);
}
示例3: testMasterFaultDetectionConnectOnDisconnect
import org.hamcrest.Matchers; //導入方法依賴的package包/類
public void testMasterFaultDetectionConnectOnDisconnect() throws InterruptedException {
Settings.Builder settings = Settings.builder();
boolean shouldRetry = randomBoolean();
ClusterName clusterName = new ClusterName(randomAsciiOfLengthBetween(3, 20));
// make sure we don't ping
settings.put(FaultDetection.CONNECT_ON_NETWORK_DISCONNECT_SETTING.getKey(), shouldRetry)
.put(FaultDetection.PING_INTERVAL_SETTING.getKey(), "5m").put("cluster.name", clusterName.value());
final ClusterState state = ClusterState.builder(clusterName).nodes(buildNodesForA(false)).build();
setState(clusterServiceA, state);
MasterFaultDetection masterFD = new MasterFaultDetection(settings.build(), threadPool, serviceA,
clusterServiceA);
masterFD.restart(nodeB, "test");
final String[] failureReason = new String[1];
final DiscoveryNode[] failureNode = new DiscoveryNode[1];
final CountDownLatch notified = new CountDownLatch(1);
masterFD.addListener((masterNode, cause, reason) -> {
failureNode[0] = masterNode;
failureReason[0] = reason;
notified.countDown();
});
// will raise a disconnect on A
serviceB.stop();
notified.await(30, TimeUnit.SECONDS);
CircuitBreaker inFlightRequestsBreaker = circuitBreakerService.getBreaker(CircuitBreaker.IN_FLIGHT_REQUESTS);
assertThat(inFlightRequestsBreaker.getTrippedCount(), equalTo(0L));
assertEquals(nodeB, failureNode[0]);
Matcher<String> matcher = Matchers.containsString("verified");
if (!shouldRetry) {
matcher = Matchers.not(matcher);
}
assertThat(failureReason[0], matcher);
}
示例4: addMatcher
import org.hamcrest.Matchers; //導入方法依賴的package包/類
@VisibleForTesting
final void addMatcher(org.hamcrest.Matcher<View> matcher) {
if (negateNextMatcher) {
negateNextMatcher = false;
matcher = Matchers.not(matcher);
}
matchers.add(matcher);
}
示例5: testNodesFaultDetectionConnectOnDisconnect
import org.hamcrest.Matchers; //導入方法依賴的package包/類
public void testNodesFaultDetectionConnectOnDisconnect() throws InterruptedException {
boolean shouldRetry = randomBoolean();
// make sure we don't ping again after the initial ping
final Settings pingSettings = Settings.builder()
.put(FaultDetection.CONNECT_ON_NETWORK_DISCONNECT_SETTING.getKey(), shouldRetry)
.put(FaultDetection.PING_INTERVAL_SETTING.getKey(), "5m").build();
ClusterState clusterState = ClusterState.builder(new ClusterName("test")).nodes(buildNodesForA(true)).build();
NodesFaultDetection nodesFDA = new NodesFaultDetection(Settings.builder().put(settingsA).put(pingSettings).build(),
threadPool, serviceA, clusterState.getClusterName());
nodesFDA.setLocalNode(nodeA);
NodesFaultDetection nodesFDB = new NodesFaultDetection(Settings.builder().put(settingsB).put(pingSettings).build(),
threadPool, serviceB, clusterState.getClusterName());
nodesFDB.setLocalNode(nodeB);
final CountDownLatch pingSent = new CountDownLatch(1);
nodesFDB.addListener(new NodesFaultDetection.Listener() {
@Override
public void onPingReceived(NodesFaultDetection.PingRequest pingRequest) {
pingSent.countDown();
}
});
nodesFDA.updateNodesAndPing(clusterState);
// wait for the first ping to go out, so we will really respond to a disconnect event rather then
// the ping failing
pingSent.await(30, TimeUnit.SECONDS);
final String[] failureReason = new String[1];
final DiscoveryNode[] failureNode = new DiscoveryNode[1];
final CountDownLatch notified = new CountDownLatch(1);
nodesFDA.addListener(new NodesFaultDetection.Listener() {
@Override
public void onNodeFailure(DiscoveryNode node, String reason) {
failureNode[0] = node;
failureReason[0] = reason;
notified.countDown();
}
});
// will raise a disconnect on A
serviceB.stop();
notified.await(30, TimeUnit.SECONDS);
CircuitBreaker inFlightRequestsBreaker = circuitBreakerService.getBreaker(CircuitBreaker.IN_FLIGHT_REQUESTS);
assertThat(inFlightRequestsBreaker.getTrippedCount(), equalTo(0L));
assertEquals(nodeB, failureNode[0]);
Matcher<String> matcher = Matchers.containsString("verified");
if (!shouldRetry) {
matcher = Matchers.not(matcher);
}
assertThat(failureReason[0], matcher);
}