private byte[] dropDeletesMatcher(Boolean dropDeletes, byte[] value) { return dropDeletes == null ? any() : (dropDeletes.booleanValue() ? aryEq(value) : isNull(byte[].class)); }
private void resetAndMockUserDatabase(String userId, UaaUser user) { reset(userDatabase); when(userDatabase.retrieveUserById(eq(userId))).thenReturn(user); when(userDatabase.retrieveUserById(not(eq(userId)))).thenThrow(new UsernameNotFoundException("mock")); }
@Test public void jvm_vitals() { uaaMetricsEmitter.emitJvmVitals(); Mockito.verify(statsDClient).gauge(eq("vitals.jvm.cpu.load"), and(geq(0l), leq(100l))); Mockito.verify(statsDClient).gauge(eq("vitals.jvm.thread.count"), and(gt(1l), leq(1000l))); Mockito.verify(statsDClient).gauge(eq("vitals.jvm.heap.init"), gt(0l)); Mockito.verify(statsDClient).gauge(eq("vitals.jvm.heap.committed"), gt(0l)); Mockito.verify(statsDClient).gauge(eq("vitals.jvm.heap.used"), gt(0l)); //Mockito.verify(statsDClient).gauge(eq("vitals.jvm.heap.max"), gt(0l)); Mockito.verify(statsDClient).gauge(eq("vitals.jvm.non-heap.init"), gt(0l)); Mockito.verify(statsDClient).gauge(eq("vitals.jvm.non-heap.committed"), gt(0l)); Mockito.verify(statsDClient).gauge(eq("vitals.jvm.non-heap.used"), gt(0l)); //Mockito.verify(statsDClient).gauge(eq("vitals.jvm.non-heap.max"), gt(0l)); }
@Test public void vm_vitals() { uaaMetricsEmitter.emitVmVitals(); Mockito.verify(statsDClient).gauge(eq("vitals.vm.cpu.count"), gt(0l)); Mockito.verify(statsDClient).gauge(eq("vitals.vm.cpu.load"), geq(0l)); Mockito.verify(statsDClient).gauge(eq("vitals.vm.memory.total"), geq(134217728l)); Mockito.verify(statsDClient).gauge(eq("vitals.vm.memory.committed"), geq(1l)); Mockito.verify(statsDClient).gauge(eq("vitals.vm.memory.free"), geq(1l)); }
@Test public void testResetNextBatchExpiry() throws Exception { client = spy(new MockClient(time, metadata)); setupWithTransactionState(null); accumulator.append(tp0, 0L, "key".getBytes(), "value".getBytes(), null, null, MAX_BLOCK_TIMEOUT); sender.run(time.milliseconds()); sender.run(time.milliseconds()); time.setCurrentTimeMs(time.milliseconds() + accumulator.getDeliveryTimeoutMs() + 1); sender.run(time.milliseconds()); InOrder inOrder = inOrder(client); inOrder.verify(client, atLeastOnce()).ready(any(), anyLong()); inOrder.verify(client, atLeastOnce()).newClientRequest(anyString(), any(), anyLong(), anyBoolean(), anyInt(), any()); inOrder.verify(client, atLeastOnce()).send(any(), anyLong()); inOrder.verify(client).poll(eq(0L), anyLong()); inOrder.verify(client).poll(eq(accumulator.getDeliveryTimeoutMs()), anyLong()); inOrder.verify(client).poll(geq(1L), anyLong()); }
/** * Argument that is either <code>null</code> or of the given type. * * <p> * See examples in javadoc for {@link ArgumentMatchers} class * </p> * * @param clazz Type to avoid casting * @return <code>null</code>. */ public static <T> T nullable(Class<T> clazz) { AdditionalMatchers.or(isNull(), isA(clazz)); return (T) Primitives.defaultValue(clazz); }
/** * Delegates call to {@link AdditionalMatchers#and(byte, byte)}. */ default byte and(byte first, byte second) { return AdditionalMatchers.and(first, second); }
/** * Delegates call to {@link AdditionalMatchers#leq(Comparable)}. */ default <T extends Comparable<T>> T leq(T value) { return AdditionalMatchers.leq(value); }
/** * Delegates call to {@link AdditionalMatchers#eq(float, float)}. */ default float eq(float value, float delta) { return AdditionalMatchers.eq(value, delta); } }
/** * Delegates call to {@link AdditionalMatchers#geq(Comparable)}. */ default <T extends Comparable<T>> T geq(T value) { return AdditionalMatchers.geq(value); }
@Test public void shouldReturnChangeSetsFromAPreviouslyKnownRevisionUptilTheLatest() throws Exception { Changeset[] changeSets = getChangeSets(42); when(client.queryHistory(eq(TFS_PROJECT), or(isNull(), any(ChangesetVersionSpec.class)), anyInt())).thenReturn(changeSets); TfsSDKCommand spy = spy(tfsCommand); doReturn(null).when(spy).getModifiedFiles(changeSets[0]); List<Modification> modifications = spy.modificationsSince(null, new StringRevision("2")); assertThat(modifications.isEmpty(), is(false)); verify(client, times(2)).queryHistory(eq(TFS_PROJECT), or(isNull(), any(ChangesetVersionSpec.class)), anyInt()); }
/** * Delegates call to {@link AdditionalMatchers#and(char, char)}. */ default char and(char first, char second) { return AdditionalMatchers.and(first, second); }
/** * Delegates call to {@link AdditionalMatchers#leq(byte)}. */ default byte leq(byte value) { return AdditionalMatchers.leq(value); }
/** * Delegates call to {@link AdditionalMatchers#eq(double, double)}. */ default double eq(double value, double delta) { return AdditionalMatchers.eq(value, delta); }
@Test public void perUrlGroup_request_metrics() throws Exception { Mockito.when(metricsUtils.getUaaMetrics(any())).thenReturn(uaaMetrics1); uaaMetricsEmitter.emitUrlGroupRequestMetrics(); Mockito.verify(statsDClient).gauge(eq("requests.ui.completed.count"), gt(0l)); Mockito.verify(statsDClient).gauge(eq("requests.ui.completed.time"), geq(300l)); Mockito.verify(statsDClient).gauge(eq("requests.static-content.completed.count"), gt(0l)); Mockito.verify(statsDClient).gauge(eq("requests.static-content.completed.time"), geq(23l)); }
private void setupContactProvider(String queriedAddress, String[]... contacts) { MatrixCursor cursor = new MatrixCursor(PROJECTION); for (String[] contact : contacts) { cursor.addRow(contact); } when(contentResolver .query(eq(Email.CONTENT_URI), aryEq(PROJECTION), nullable(String.class), aryEq(new String[] { queriedAddress, queriedAddress }), nullable(String.class))).thenReturn(cursor); }
@Test public void testReplacingNonNullItemWithNonNullItemUpdatesSize() { String key = getKey(); Object initialValue = new Object(); cache.put(key, initialValue); cache.put(key, new Object()); for (int i = 0; i < SIZE - 1; i++) { cache.put(getKey(), new Object()); } verify(listener).onItemRemoved(initialValue); verify(listener, never()).onItemRemoved(not(eq(initialValue))); }
/** * Delegates call to {@link AdditionalMatchers#geq(double)}. */ default double geq(double value) { return AdditionalMatchers.geq(value); }
/** * Delegates call to {@link AdditionalMatchers#or(boolean, boolean)}. */ default boolean or(boolean first, boolean second) { return AdditionalMatchers.or(first, second); }