/** * Not <code>null</code> argument. * * <p> * Alias to {@link ArgumentMatchers#notNull()} * </p> * * <p> * See examples in javadoc for {@link ArgumentMatchers} class * </p> * * @return <code>null</code>. * @see #isNotNull(Class) * @see #isNull() * @see #isNull(Class) */ public static <T> T isNotNull() { return notNull(); }
/** * Not <code>null</code> argument, not necessary of the given class. * * <p> * The class argument is provided to avoid casting. * Alias to {@link ArgumentMatchers#notNull(Class)} * </p> * * <p> * See examples in javadoc for {@link ArgumentMatchers} class * </p> * * @param clazz Type to avoid casting * @return <code>null</code>. * @deprecated With Java 8 this method will be removed in Mockito 3.0. This method is only used for generic * friendliness to avoid casting, this is not anymore needed in Java 8. */ @Deprecated public static <T> T isNotNull(Class<T> clazz) { return notNull(clazz); }
/** * Not <code>null</code> argument, not necessary of the given class. * * <p> * The class argument is provided to avoid casting. * * Alias to {@link ArgumentMatchers#isNotNull(Class)} * <p> * * <p> * See examples in javadoc for {@link ArgumentMatchers} class * </p> * * @param clazz Type to avoid casting * @return <code>null</code>. * @see #isNotNull() * @see #isNull() * @see #isNull(Class) * @deprecated With Java 8 this method will be removed in Mockito 3.0. This method is only used for generic * friendliness to avoid casting, this is not anymore needed in Java 8. */ @Deprecated public static <T> T notNull(Class<T> clazz) { return notNull(); }
@Override protected CliCommandExecutor getCliCommandExecutor() throws IOException { CliCommandExecutor mockCli = mock(CliCommandExecutor.class); when(mockCli.execute((String) notNull())).thenReturn(null); return mockCli; } }
@Test public void testInterceptorPartitionSetOnTooLargeRecord() { Map<String, Object> configs = new HashMap<>(); configs.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:9999"); configs.put(ProducerConfig.MAX_REQUEST_SIZE_CONFIG, "1"); String topic = "topic"; ProducerRecord<String, String> record = new ProducerRecord<>(topic, "value"); Metadata metadata = new Metadata(0, 90000, true); MetadataResponse initialUpdateResponse = TestUtils.metadataUpdateWith(1, singletonMap(topic, 1)); metadata.update(initialUpdateResponse, Time.SYSTEM.milliseconds()); @SuppressWarnings("unchecked") // it is safe to suppress, since this is a mock class ProducerInterceptors<String, String> interceptors = mock(ProducerInterceptors.class); KafkaProducer<String, String> producer = new KafkaProducer<>(configs, new StringSerializer(), new StringSerializer(), metadata, null, interceptors, Time.SYSTEM); when(interceptors.onSend(any())).then(invocation -> invocation.getArgument(0)); producer.send(record); verify(interceptors).onSend(record); verify(interceptors).onSendError(eq(record), notNull(), notNull()); producer.close(Duration.ofMillis(0)); }
@Test public void updateWithCacheWriter() { DeclarableType newCacheWriterDeclarable = mock(DeclarableType.class); when(newCacheWriterDeclarable.getClassName()).thenReturn(MyCacheWriter.class.getName()); regionAttributes.setCacheWriter(newCacheWriterDeclarable); function.alterRegion(cache, config); verify(mutator).setCacheWriter(notNull()); verify(mutator, times(0)).setCacheLoader(any()); }
@Test public void updateWithCustomExpiry() { RegionAttributesType.ExpirationAttributesType expiration = new RegionAttributesType.ExpirationAttributesType(); regionAttributes.setEntryIdleTime(expiration); DeclarableType mockExpiry = mock(DeclarableType.class); when(mockExpiry.getClassName()).thenReturn(MyCustomExpiry.class.getName()); expiration.setCustomExpiry(mockExpiry); function.alterRegion(cache, config); verify(mutator, times(0)).setEntryIdleTimeout(any()); verify(mutator).setCustomEntryIdleTimeout(notNull()); }
@Test public void testAppendSemantics() throws Exception { //1 try to append to an open file Path file1 = new Path(dir.toString() + Path.SEPARATOR_CHAR + "file1"); try (FSDataOutputStream os1 = fs.create(file1, false)) { fs.append(file1); // should fail fail("Append did not throw an exception"); } catch (RemoteException e) { // expecting AlreadyBeingCreatedException inside RemoteException Assert.assertEquals(AlreadyBeingCreatedException.class, e.unwrapRemoteException().getClass()); } //2 try to append to a closed file try (FSDataOutputStream os2 = fs.append(file1)) { assertThat(os2, notNull()); } }
@Test public void dispatchTaskEnd_withUnValidModel() { final Listener4SpeedAssistExtend.Listener4SpeedModel invalidModel = new Listener4SpeedAssistExtend.Listener4SpeedModel(1); assertThat(invalidModel.blockSpeeds).isEqualTo(null); assertThat(invalidModel.taskSpeed).isEqualTo(null); final boolean result = assistExtend.dispatchTaskEnd( task, EndCause.CANCELED, null, invalidModel); assertThat(result).isTrue(); verify(callback).taskEnd(eq(task), eq(EndCause.CANCELED), nullable(Exception.class), (SpeedCalculator) notNull()); } }
@Test public void testCallbackV8ObjectVarArgs() { ICallback callback = mock(ICallback.class); v8.registerJavaMethod(callback, "voidMethodV8ObjectVarArgs", "foo", new Class<?>[] { V8Object[].class }); v8.executeVoidScript("foo({});"); verify(callback).voidMethodV8ObjectVarArgs(any(V8Object.class)); verify(callback).voidMethodV8ObjectVarArgs((V8Object[]) notNull()); }
@Test public void testCallbackV8ArrayVarArgs() { ICallback callback = mock(ICallback.class); v8.registerJavaMethod(callback, "voidMethodV8ObjectVarArgs", "foo", new Class<?>[] { V8Object[].class }); v8.executeVoidScript("foo([]);"); verify(callback).voidMethodV8ObjectVarArgs(any(V8Array.class)); verify(callback).voidMethodV8ObjectVarArgs((V8Object[]) notNull()); }
/** * Delegates call to {@link ArgumentMatchers#notNull()}. */ default <T> T notNull() { return ArgumentMatchers.notNull(); }
/** * Delegates call to {@link ArgumentMatchers#notNull()}. */ default <T> T notNull() { return ArgumentMatchers.notNull(); }
/** * Delegates call to {@link ArgumentMatchers#notNull(Class)}. * * @deprecated This will be removed in Mockito 3.0. */ @Deprecated default <T> T notNull(Class<T> clazz) { return ArgumentMatchers.notNull(clazz); }
/** * Delegates call to {@link ArgumentMatchers#notNull(Class)}. * * @deprecated This will be removed in Mockito 3.0. */ @Deprecated default <T> T notNull(Class<T> clazz) { return ArgumentMatchers.notNull(clazz); }
@SuppressWarnings("unchecked") private AttachedBlockHeaderValidationRule<Void> createFailingAttachedRule() { final AttachedBlockHeaderValidationRule<Void> rule = mock(AttachedBlockHeaderValidationRule.class); when(rule.validate(notNull(), notNull(), eq(protocolContext))).thenReturn(false); return rule; }
@SuppressWarnings("unchecked") private AttachedBlockHeaderValidationRule<Void> createPassingAttachedRule() { final AttachedBlockHeaderValidationRule<Void> rule = mock(AttachedBlockHeaderValidationRule.class); when(rule.validate(notNull(), notNull(), eq(protocolContext))).thenReturn(true); return rule; }
private void initCacheData(Map<Object, Object> data) { try { tm.begin(); cache.putAll(data); tm.commit(); } catch (Exception e) { throw new RuntimeException(e); } expectTransactionBoundaries(true); verify(mockNotifier, atLeastOnce()).notifyCacheEntryCreated(notNull(), notNull(), any(Metadata.class), anyBoolean(), any(InvocationContext.class), any(PutMapCommand.class)); reset(mockNotifier); }
@BeforeEach public void setUp() { managerMock = mock(TorrentManager.class); torrentClient = mock(TorrentClient.class); phaseMock = mock(IDownloadPhase.class); phaseMock.onPhaseEnter(); phaseRegulatorMock = mock(PhaseRegulator.class); executorServiceMock = mock(ScheduledExecutorService.class); futureMock = mock(ScheduledFuture.class); when(torrentClient.getPhaseRegulator()).thenReturn(phaseRegulatorMock); when(torrentClient.getExecutorService()).thenReturn(executorServiceMock); when(phaseRegulatorMock.createInitialPhase(notNull(), notNull())).thenReturn(phaseMock); when(executorServiceMock.scheduleAtFixedRate(notNull(), anyLong(), anyLong(), notNull())).thenReturn(futureMock); }
@Test public void testDegradeConnection() throws Exception { TestClock clock = new TestClock(Clock.systemDefaultZone()); cut = new NioPeerConnector(clock, torrentClient, 4); BitTorrentHandshakeHandler handshakeHandler = mock(BitTorrentHandshakeHandler.class); when(torrentClient.getHandshakeHandler()).thenReturn(handshakeHandler); PeerConnectInfo infoOne = mock(PeerConnectInfo.class); when(infoOne.getAddress()) .thenReturn(InetSocketAddress.createUnresolved("localhost", DummyEntity.findAvailableTcpPort())); cut.enqueuePeer(infoOne); cut.pollReadyConnections(); verify(socketTypeOne).connect(notNull()); clock.setClock(Clock.offset(Clock.systemDefaultZone(), Duration.ofSeconds(15))); cut.pollReadyConnections(); verify(socketTypeOne).close(); verify(socketTypeTwo).connect(notNull()); }