org.mockito.Mockito.atLeast()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(10.4k)|赞(0)|评价(0)|浏览(266)

本文整理了Java中org.mockito.Mockito.atLeast()方法的一些代码示例,展示了Mockito.atLeast()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Mockito.atLeast()方法的具体详情如下:
包路径:org.mockito.Mockito
类名称:Mockito
方法名:atLeast

Mockito.atLeast介绍

[英]Allows at-least-x verification. E.g:

verify(mock, atLeast(3)).someMethod("some arg");

See examples in javadoc for Mockito class
[中]允许至少x次验证。例如:

verify(mock, atLeast(3)).someMethod("some arg");

参见javadoc中Mockito类的示例

代码示例

代码示例来源:origin: google/guava

public void testStandardValues() throws InvocationTargetException {
 @SuppressWarnings("unchecked")
 final Map<String, Boolean> map = mock(Map.class);
 Map<String, Boolean> forward =
   new ForwardingMap<String, Boolean>() {
    @Override
    protected Map<String, Boolean> delegate() {
     return map;
    }
    @Override
    public Collection<Boolean> values() {
     return new StandardValues();
    }
   };
 callAllPublicMethods(new TypeToken<Collection<Boolean>>() {}, forward.values());
 // These are the methods specified by StandardValues
 verify(map, atLeast(0)).clear();
 verify(map, atLeast(0)).containsValue(anyObject());
 verify(map, atLeast(0)).isEmpty();
 verify(map, atLeast(0)).size();
 verify(map, atLeast(0)).entrySet();
 verifyNoMoreInteractions(map);
}

代码示例来源:origin: google/guava

public void testStandardKeySet() throws InvocationTargetException {
 @SuppressWarnings("unchecked")
 final Map<String, Boolean> map = mock(Map.class);
 Map<String, Boolean> forward =
   new ForwardingMap<String, Boolean>() {
    @Override
    protected Map<String, Boolean> delegate() {
     return map;
    }
    @Override
    public Set<String> keySet() {
     return new StandardKeySet();
    }
   };
 callAllPublicMethods(new TypeToken<Set<String>>() {}, forward.keySet());
 // These are the methods specified by StandardKeySet
 verify(map, atLeast(0)).clear();
 verify(map, atLeast(0)).containsKey(anyObject());
 verify(map, atLeast(0)).isEmpty();
 verify(map, atLeast(0)).remove(anyObject());
 verify(map, atLeast(0)).size();
 verify(map, atLeast(0)).entrySet();
 verifyNoMoreInteractions(map);
}

代码示例来源:origin: Netflix/zuul

@Test
  public void testFileManagerInit() throws Exception
  {
    FilterFileManagerConfig config = new FilterFileManagerConfig(new String[]{"test", "test1"}, new String[]{"com.netflix.blah.SomeFilter"}, 1);
    FilterFileManager manager = new FilterFileManager(config, filterLoader);
    manager = spy(manager);
    doNothing().when(manager).manageFiles();
    manager.init();
    verify(manager, atLeast(1)).manageFiles();
    verify(manager, times(1)).startPoller();
    assertNotNull(manager.poller);
  }
}

代码示例来源:origin: google/guava

public void testStandardEntrySet() throws InvocationTargetException {
 @SuppressWarnings("unchecked")
 final Map<String, Boolean> map = mock(Map.class);
 Map<String, Boolean> forward =
   new ForwardingMap<String, Boolean>() {
    @Override
    protected Map<String, Boolean> delegate() {
     return map;
    }
    @Override
    public Set<Entry<String, Boolean>> entrySet() {
     return new StandardEntrySet() {
      @Override
      public Iterator<Entry<String, Boolean>> iterator() {
       return Iterators.emptyIterator();
      }
     };
    }
   };
 callAllPublicMethods(new TypeToken<Set<Entry<String, Boolean>>>() {}, forward.entrySet());
 // These are the methods specified by StandardEntrySet
 verify(map, atLeast(0)).clear();
 verify(map, atLeast(0)).containsKey(anyObject());
 verify(map, atLeast(0)).get(anyObject());
 verify(map, atLeast(0)).isEmpty();
 verify(map, atLeast(0)).remove(anyObject());
 verify(map, atLeast(0)).size();
 verifyNoMoreInteractions(map);
}

代码示例来源:origin: apache/hbase

@Override
 public void verify(MasterKeepAliveConnection masterAdmin, int count) throws Exception {
  Mockito.verify(masterAdmin, Mockito.atLeast(count))
   .getTableDescriptors((RpcController)Mockito.any(),
    (GetTableDescriptorsRequest)Mockito.any());
 }
});

代码示例来源:origin: apache/hbase

@Override
 public void verify(MasterKeepAliveConnection masterAdmin, int count) throws Exception {
  Mockito.verify(masterAdmin, Mockito.atLeast(count))
   .getTableNames((RpcController)Mockito.any(),
    (GetTableNamesRequest)Mockito.any());
 }
});

代码示例来源:origin: apache/hbase

@Override
 public void verify(MasterKeepAliveConnection masterAdmin, int count) throws Exception {
  Mockito.verify(masterAdmin, Mockito.atLeast(count))
   .isCatalogJanitorEnabled((RpcController)Mockito.any(),
    (IsCatalogJanitorEnabledRequest)Mockito.any());
 }
});

代码示例来源:origin: apache/hbase

@Override
 public void verify(MasterKeepAliveConnection masterAdmin, int count) throws Exception {
  Mockito.verify(masterAdmin, Mockito.atLeast(count))
   .setBalancerRunning((RpcController)Mockito.any(),
    (SetBalancerRunningRequest)Mockito.any());
 }
});

代码示例来源:origin: apache/hbase

@Override
 public void verify(MasterKeepAliveConnection masterAdmin, int count) throws Exception {
  Mockito.verify(masterAdmin, Mockito.atLeast(count))
   .balance((RpcController)Mockito.any(),
    (BalanceRequest)Mockito.any());
 }
});

代码示例来源:origin: apache/hbase

@Override
 public void verify(MasterKeepAliveConnection masterAdmin, int count) throws Exception {
  Mockito.verify(masterAdmin, Mockito.atLeast(count))
   .enableCatalogJanitor((RpcController)Mockito.any(),
    (EnableCatalogJanitorRequest)Mockito.any());
 }
});

代码示例来源:origin: apache/hbase

/**
  * Verify the cohort controller got called once per expected node to start the operation
  */
 private void verifyCohort(ProcedureMember member, int cohortSize,
   String operationName, byte[] data) {
//    verify(member, Mockito.times(cohortSize)).submitSubprocedure(Mockito.eq(operationName),
//      (byte[]) Mockito.argThat(new ArrayEquals(data)));
  Mockito.verify(member,
   Mockito.atLeast(cohortSize)).submitSubprocedure(Mockito.any());

 }

代码示例来源:origin: apache/hbase

@Override
 public void verify(MasterKeepAliveConnection masterAdmin, int count) throws Exception {
  Mockito.verify(masterAdmin, Mockito.atLeast(count))
   .getTableDescriptors((RpcController)Mockito.any(),
    (GetTableDescriptorsRequest)Mockito.any());
 }
});

代码示例来源:origin: apache/hbase

@Override
 public void verify(MasterKeepAliveConnection masterAdmin, int count) throws Exception {
  Mockito.verify(masterAdmin, Mockito.atLeast(count))
   .moveRegion((RpcController)Mockito.any(),
    (MoveRegionRequest)Mockito.any());
 }
});

代码示例来源:origin: apache/hbase

@Override
 public void verify(MasterKeepAliveConnection masterAdmin, int count) throws Exception {
  Mockito.verify(masterAdmin, Mockito.atLeast(count))
   .getTableDescriptors((RpcController)Mockito.any(),
    (GetTableDescriptorsRequest)Mockito.any());
 }
});

代码示例来源:origin: neo4j/neo4j

@Test
public void shouldResumeWhenWritableOnceAgain() throws Exception
{
  // given
  TransportThrottle throttle = newThrottleAndInstall( channel );
  when( channel.isWritable() ).thenReturn( false ).thenReturn( true );
  // when
  throttle.acquire( channel );
  // expect
  verify( lock, atLeast( 1 ) ).lock( any(), anyLong() );
  verify( lock, never() ).unlock( any() );
}

代码示例来源:origin: Netflix/zuul

@Test
  public void testFileManagerInit() throws Exception
  {
    FilterFileManagerConfig config = new FilterFileManagerConfig(new String[]{"test", "test1"}, new String[]{"com.netflix.blah.SomeFilter"}, 1);
    FilterFileManager manager = new FilterFileManager(config, filterLoader);
    manager = spy(manager);
    doNothing().when(manager).manageFiles();
    manager.init();
    verify(manager, atLeast(1)).manageFiles();
    verify(manager, times(1)).startPoller();
    assertNotNull(manager.poller);
  }
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void readInactivity() throws Exception {
  this.messageHandler.setHeartbeatValue(new long[] {0, 1});
  this.messageHandler.setTaskScheduler(this.taskScheduler);
  this.messageHandler.start();
  ArgumentCaptor<Runnable> taskCaptor = ArgumentCaptor.forClass(Runnable.class);
  verify(this.taskScheduler).scheduleWithFixedDelay(taskCaptor.capture(), eq(1L));
  Runnable heartbeatTask = taskCaptor.getValue();
  assertNotNull(heartbeatTask);
  String id = "sess1";
  TestPrincipal user = new TestPrincipal("joe");
  Message<String> connectMessage = createConnectMessage(id, user, new long[] {1, 0});
  this.messageHandler.handleMessage(connectMessage);
  Thread.sleep(10);
  heartbeatTask.run();
  verify(this.clientOutChannel, atLeast(2)).send(this.messageCaptor.capture());
  List<Message<?>> messages = this.messageCaptor.getAllValues();
  assertEquals(2, messages.size());
  MessageHeaders headers = messages.get(0).getHeaders();
  assertEquals(SimpMessageType.CONNECT_ACK, headers.get(SimpMessageHeaderAccessor.MESSAGE_TYPE_HEADER));
  headers = messages.get(1).getHeaders();
  assertEquals(SimpMessageType.DISCONNECT_ACK, headers.get(SimpMessageHeaderAccessor.MESSAGE_TYPE_HEADER));
  assertEquals(id, headers.get(SimpMessageHeaderAccessor.SESSION_ID_HEADER));
  assertEquals(user, headers.get(SimpMessageHeaderAccessor.USER_HEADER));
}

代码示例来源:origin: neo4j/neo4j

@Test
void shouldHaveMultipleEndConditions() throws Throwable
{
  // GIVEN
  ControlledBooleanSupplier endCondition1 = spy( new ControlledBooleanSupplier( false ) );
  ControlledBooleanSupplier endCondition2 = spy( new ControlledBooleanSupplier( false ) );
  ControlledBooleanSupplier endCondition3 = spy( new ControlledBooleanSupplier( false ) );
  Race race = new Race().withEndCondition( endCondition1, endCondition2, endCondition3 );
  race.addContestant( () -> endCondition2.set( true ) );
  race.addContestants( 3, Runnables.EMPTY_RUNNABLE );
  // WHEN
  race.go();
  // THEN
  verify( endCondition1, atLeast( 4 ) ).getAsBoolean();
  verify( endCondition2, atLeast( 4 ) ).getAsBoolean();
}

代码示例来源:origin: neo4j/neo4j

private void defrag( int nodeCount, RecordStore<RelationshipGroupRecord> groupStore )
{
  Monitor monitor = mock( Monitor.class );
  RelationshipGroupDefragmenter defragmenter = new RelationshipGroupDefragmenter( CONFIG,
      ExecutionMonitors.invisible(), monitor, AUTO_WITHOUT_PAGECACHE );
  // Calculation below correlates somewhat to calculation in RelationshipGroupDefragmenter.
  // Anyway we verify below that we exercise the multi-pass bit, which is what we want
  long memory = groupStore.getHighId() * 15 + 200;
  defragmenter.run( memory, stores, nodeCount );
  // Verify that we exercise the multi-pass functionality
  verify( monitor, atLeast( 2 ) ).defragmentingNodeRange( anyLong(), anyLong() );
  verify( monitor, atMost( 10 ) ).defragmentingNodeRange( anyLong(), anyLong() );
}

代码示例来源:origin: real-logic/aeron

@Test
public void shouldRetransmitNakForMissingData()
{
  final long rebuildPosition = ACTIVE_TERM_POSITION;
  final long hwmPosition = ACTIVE_TERM_POSITION + (ALIGNED_FRAME_LENGTH * 3);
  insertDataFrame(offsetOfMessage(0));
  insertDataFrame(offsetOfMessage(2));
  lossDetector.scan(termBuffer, rebuildPosition, hwmPosition, currentTime, MASK, POSITION_BITS_TO_SHIFT, TERM_ID);
  currentTime = TimeUnit.MILLISECONDS.toNanos(30);
  lossDetector.scan(termBuffer, rebuildPosition, hwmPosition, currentTime, MASK, POSITION_BITS_TO_SHIFT, TERM_ID);
  currentTime = TimeUnit.MILLISECONDS.toNanos(60);
  lossDetector.scan(termBuffer, rebuildPosition, hwmPosition, currentTime, MASK, POSITION_BITS_TO_SHIFT, TERM_ID);
  verify(lossHandler, atLeast(2)).onGapDetected(TERM_ID, offsetOfMessage(1), gapLength());
}

相关文章