本文整理了Java中org.mockito.Mockito.startsWith()
方法的一些代码示例,展示了Mockito.startsWith()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Mockito.startsWith()
方法的具体详情如下:
包路径:org.mockito.Mockito
类名称:Mockito
方法名:startsWith
暂无
代码示例来源:origin: SonarSource/sonarqube
@Test
public void log_error() {
underTest.error("message");
underTest.error("message {}", "foo");
underTest.error("message {} {}", "foo", "bar");
underTest.error("message {} {} {}", "foo", "bar", "baz");
underTest.error("message with exception", new IllegalArgumentException());
verify(stream, times(5)).println(startsWith("ERROR "));
assertThat(tester.logs(LoggerLevel.ERROR)).containsExactly(
"message", "message foo", "message foo bar", "message foo bar baz", "message with exception");
}
代码示例来源:origin: entando/entando-core
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
when(this.dataSource.getConnection()).thenReturn(conn);
when(this.conn.prepareStatement(Mockito.startsWith("SELECT api_oauth_tokens.accesstoken"))).thenReturn(statForSearchId);
when(this.conn.prepareStatement(Mockito.startsWith("SELECT * "))).thenReturn(stat);
when(this.conn.prepareStatement(Mockito.startsWith("INSERT "))).thenReturn(stat);
when(this.conn.prepareStatement(Mockito.startsWith("DELETE "))).thenReturn(stat);
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.SECOND, 200);
Mockito.when(res.getTimestamp("expiresin")).thenReturn(new Timestamp(calendar.getTime().getTime()));
}
代码示例来源:origin: addthis/hydra
private PreparedStatement doDelete(String key) throws SQLException {
//set up mocks
final PreparedStatement deletePreparedStatement = Mockito.mock(PreparedStatement.class);
Mockito.doReturn(deletePreparedStatement).when(connection).prepareStatement(Mockito.startsWith("DELETE FROM "));
//run method under test
cachedDataStore.delete(key);
return deletePreparedStatement;
}
代码示例来源:origin: addthis/hydra
@Test
public void testDeleteChild() throws SQLException {
//set up mocks
final PreparedStatement deletePreparedStatement = Mockito.mock(PreparedStatement.class);
Mockito.doReturn(deletePreparedStatement).when(connection).prepareStatement(Mockito.startsWith("DELETE FROM "));
//run method under test
cachedDataStore.deleteChild("key", "childId");
//verifications
Mockito.verify(deletePreparedStatement, Mockito.atLeastOnce()).execute();
Mockito.verify(deletePreparedStatement).setString(Mockito.eq(1), Mockito.eq("key"));
Mockito.verify(deletePreparedStatement).setString(Mockito.eq(2), Mockito.eq("childId"));
}
代码示例来源:origin: addthis/hydra
@Test
public void testDeleteChild() throws SQLException {
//set up mocks
final PreparedStatement deletePreparedStatement = Mockito.mock(PreparedStatement.class);
Mockito.doReturn(deletePreparedStatement).when(connection).prepareStatement(Mockito.startsWith("DELETE FROM "));
//run method under test
mysqlDataStore.deleteChild("key", "childId");
//verifications
Mockito.verify(deletePreparedStatement, Mockito.atLeastOnce()).execute();
Mockito.verify(deletePreparedStatement).setString(Mockito.eq(1), Mockito.eq("key"));
Mockito.verify(deletePreparedStatement).setString(Mockito.eq(2), Mockito.eq("childId"));
}
代码示例来源:origin: addthis/hydra
@Test
public void testDelete() throws SQLException {
//set up mocks
final PreparedStatement deletePreparedStatement = Mockito.mock(PreparedStatement.class);
Mockito.doReturn(deletePreparedStatement).when(connection).prepareStatement(
Mockito.startsWith("DELETE FROM "));
//run method under test
postgresDataStore.delete("key");
//verifications
Mockito.verify(deletePreparedStatement, Mockito.atLeastOnce()).execute();
Mockito.verify(deletePreparedStatement).setString(Mockito.eq(1), Mockito.eq("key"));
}
代码示例来源:origin: addthis/hydra
@Test
public void testDelete() throws SQLException {
//set up mocks
final PreparedStatement deletePreparedStatement = Mockito.mock(PreparedStatement.class);
Mockito.doReturn(deletePreparedStatement).when(connection).prepareStatement(Mockito.startsWith("DELETE FROM "));
//run method under test
mysqlDataStore.delete("key");
//verifications
Mockito.verify(deletePreparedStatement, Mockito.atLeastOnce()).execute();
Mockito.verify(deletePreparedStatement).setString(Mockito.eq(1), Mockito.eq("key"));
}
代码示例来源:origin: addthis/hydra
@Test
public void testPut() throws Exception {
//set up mocks
final PreparedStatement insertPreparedStatement = Mockito.mock(PreparedStatement.class);
Mockito.doReturn(insertPreparedStatement).when(connection).prepareStatement(
Mockito.startsWith("select * from replace_entry(?,?,?)"));
//run method under test
postgresDataStore.put("key", "value");
//verifications
Mockito.verify(insertPreparedStatement).setString(Mockito.eq(1), Mockito.eq("key"));
Mockito.verify(insertPreparedStatement).setString(Mockito.eq(2), Mockito.eq("value"));
Mockito.verify(insertPreparedStatement).setString(Mockito.eq(3), Mockito.eq("_root"));
Mockito.verify(insertPreparedStatement, Mockito.atLeastOnce()).execute();
}
代码示例来源:origin: addthis/hydra
@Test
public void testPutAsChild() throws Exception {
//set up mocks
final PreparedStatement insertPreparedStatement = Mockito.mock(PreparedStatement.class);
Mockito.doReturn(insertPreparedStatement).when(connection).prepareStatement(
Mockito.startsWith("select * from replace_entry(?,?,?)"));
//run method under test
postgresDataStore.putAsChild("key", "childId", "value");
//verifications
Mockito.verify(insertPreparedStatement).setString(Mockito.eq(1), Mockito.eq("key"));
Mockito.verify(insertPreparedStatement).setString(Mockito.eq(2), Mockito.eq("value"));
Mockito.verify(insertPreparedStatement).setString(Mockito.eq(3), Mockito.eq("childId"));
Mockito.verify(insertPreparedStatement, Mockito.atLeastOnce()).execute();
}
代码示例来源:origin: addthis/hydra
@Test
public void testDeleteChild() throws SQLException {
//set up mocks
final PreparedStatement deletePreparedStatement = Mockito.mock(PreparedStatement.class);
Mockito.doReturn(deletePreparedStatement).when(connection).prepareStatement(
Mockito.startsWith("DELETE FROM "));
//run method under test
postgresDataStore.deleteChild("key", "childId");
//verifications
Mockito.verify(deletePreparedStatement, Mockito.atLeastOnce()).execute();
Mockito.verify(deletePreparedStatement).setString(Mockito.eq(1), Mockito.eq("key"));
Mockito.verify(deletePreparedStatement).setString(Mockito.eq(2), Mockito.eq("childId"));
}
代码示例来源:origin: addthis/hydra
private PreparedStatement doPut(String key, String value) throws Exception {
//set up mocks
final PreparedStatement insertPreparedStatement = Mockito.mock(PreparedStatement.class);
Mockito.doReturn(insertPreparedStatement).when(connection).prepareStatement(Mockito.startsWith("REPLACE INTO "));
Mockito.doAnswer((Answer) (InvocationOnMock invocation) -> {
final Blob blob = (Blob)invocation.getArguments()[1];
assertEquals(new String(blob.getBytes(1l, (int) blob.length())), value);
return null;
}).when(insertPreparedStatement).setBlob(Mockito.eq(2), Mockito.any(Blob.class));
//run method under test
cachedDataStore.put(key, value);
return insertPreparedStatement;
}
代码示例来源:origin: addthis/hydra
@Test
public void testPutAsChild() throws Exception {
//set up mocks
final PreparedStatement insertPreparedStatement = Mockito.mock(PreparedStatement.class);
Mockito.doReturn(insertPreparedStatement).when(connection).prepareStatement(Mockito.startsWith("REPLACE INTO "));
Mockito.doAnswer((Answer) (InvocationOnMock invocation) -> {
final Blob blob = (Blob)invocation.getArguments()[1];
assertEquals(new String(blob.getBytes(1l, (int) blob.length())), "value");
return null;
}).when(insertPreparedStatement).setBlob(Mockito.eq(2), Mockito.any(Blob.class));
//run method under test
cachedDataStore.putAsChild("key", "childId", "value");
//verifications
Mockito.verify(insertPreparedStatement).setString(Mockito.eq(1), Mockito.eq("key"));
Mockito.verify(insertPreparedStatement).setBlob(Mockito.eq(2), Mockito.any(Blob.class));
Mockito.verify(insertPreparedStatement).setString(Mockito.eq(3), Mockito.eq("childId"));
Mockito.verify(insertPreparedStatement, Mockito.atLeastOnce()).execute();
}
代码示例来源:origin: addthis/hydra
@Test
public void testPutAsChild() throws Exception {
//set up mocks
final PreparedStatement insertPreparedStatement = Mockito.mock(PreparedStatement.class);
Mockito.doReturn(insertPreparedStatement).when(connection).prepareStatement(Mockito.startsWith("REPLACE INTO "));
Mockito.doAnswer((Answer) (InvocationOnMock invocation) -> {
final Blob blob = (Blob)invocation.getArguments()[1];
assertEquals(new String(blob.getBytes(1l, (int) blob.length())), "value");
return null;
}).when(insertPreparedStatement).setBlob(Mockito.eq(2), Mockito.any(Blob.class));
//run method under test
mysqlDataStore.putAsChild("key", "childId", "value");
//verifications
Mockito.verify(insertPreparedStatement).setString(Mockito.eq(1), Mockito.eq("key"));
Mockito.verify(insertPreparedStatement).setBlob(Mockito.eq(2), Mockito.any(Blob.class));
Mockito.verify(insertPreparedStatement).setString(Mockito.eq(3), Mockito.eq("childId"));
Mockito.verify(insertPreparedStatement, Mockito.atLeastOnce()).execute();
}
代码示例来源:origin: addthis/hydra
@Test
public void testPut() throws Exception {
//set up mocks
final PreparedStatement insertPreparedStatement = Mockito.mock(PreparedStatement.class);
Mockito.doReturn(insertPreparedStatement).when(connection).prepareStatement(Mockito.startsWith("REPLACE INTO "));
Mockito.doAnswer((Answer) (InvocationOnMock invocation) -> {
final Blob blob = (Blob)invocation.getArguments()[1];
assertEquals(new String(blob.getBytes(1l, (int) blob.length())), "value");
return null;
}).when(insertPreparedStatement).setBlob(Mockito.eq(2), Mockito.any(Blob.class));
//run method under test
mysqlDataStore.put("key", "value");
//verifications
Mockito.verify(insertPreparedStatement).setString(Mockito.eq(1), Mockito.eq("key"));
Mockito.verify(insertPreparedStatement).setBlob(Mockito.eq(2), Mockito.any(Blob.class));
Mockito.verify(insertPreparedStatement).setString(Mockito.eq(3), Mockito.eq("_root"));
Mockito.verify(insertPreparedStatement, Mockito.atLeastOnce()).execute();
}
代码示例来源:origin: entando/entando-core
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
Map<String, Date> map = new HashMap<>();
Mockito.when(valueWrapperForExpirationTime.get()).thenReturn(map);
Mockito.when(cache.get(Mockito.startsWith(ICacheInfoManager.EXPIRATIONS_CACHE_NAME_PREFIX))).thenReturn(valueWrapperForExpirationTime);
Map<String, List<String>> groupsMap = new HashMap<>();
List<String> list_a = Arrays.asList("key_a1", "key_a2", "key_a3");
List<String> list_b = Arrays.asList("key_b1", "key_b2", "key_b3", "key_b4");
groupsMap.put("group_1", new ArrayList<>(list_a));
groupsMap.put("group_2", new ArrayList<>(list_b));
Mockito.when(valueWrapperForGroups.get()).thenReturn(groupsMap);
Mockito.when(cache.get(Mockito.startsWith(ICacheInfoManager.GROUP_CACHE_NAME_PREFIX))).thenReturn(valueWrapperForGroups);
Mockito.when(cacheManager.getCache(Mockito.anyString())).thenReturn(this.cache);
}
代码示例来源:origin: entando/entando-core
private void flushGroup(String groupName, int expectedEvict) {
String targetCache = "targetCacheName5";
cacheInfoManager.flushGroup(targetCache, groupName);
Mockito.verify(cacheManager, Mockito.times(1)).getCache(ICacheInfoManager.CACHE_INFO_MANAGER_CACHE_NAME);
Mockito.verify(cacheManager, Mockito.times(expectedEvict)).getCache(targetCache);
Mockito.verify(cache, Mockito.times(expectedEvict)).evict(Mockito.any(Object.class));
Mockito.verify(cache, Mockito.times(1)).put(Mockito.startsWith(ICacheInfoManager.GROUP_CACHE_NAME_PREFIX), Mockito.any(Object.class));
}
代码示例来源:origin: addthis/hydra
@After
public void tearDown() throws SQLException {
//run some verifications
Mockito.verify(driver).acceptsURL(Mockito.startsWith(DB_URL));
//shut down the connection pooling
if (cachedDataStore != null) {
cachedDataStore.close();
Mockito.verify(connection, Mockito.atLeastOnce()).close(); //this tests the close method as well
}
//clear the mocks
Mockito.reset(driver, connection);
//deregister the driver we started out with
DriverManager.deregisterDriver(mockDriver);
}
代码示例来源:origin: addthis/hydra
@After
public void tearDown() throws SQLException {
//run some verifications
Mockito.verify(driver).acceptsURL(Mockito.startsWith(DB_URL));
//shut down the connection pooling
if (mysqlDataStore != null) {
mysqlDataStore.close();
Mockito.verify(connection, Mockito.atLeastOnce()).close(); //this tests the close method as well
}
//clear the mocks
Mockito.reset(driver, connection);
//deregister the driver we started out with
DriverManager.deregisterDriver(mockDriver);
}
代码示例来源:origin: addthis/hydra
@After
public void tearDown() throws SQLException {
//run some verifications
Mockito.verify(driver).acceptsURL(Mockito.startsWith(DB_URL));
//shut down the connection pooling
if (postgresDataStore != null) {
postgresDataStore.close();
}
//clear the mocks
Mockito.reset(driver, connection);
//deregister the driver we started out with
DriverManager.deregisterDriver(mockDriver);
}
代码示例来源:origin: blurpy/kouchat-android
/**
* Tests sendClient().
*
* Expects: 13132531!CLIENT#Christian:(KouChat v0.9.9-dev null)[134]{Linux}<2222>/4444\
*/
@Test
public void testSendClientMessage() {
final String startsWith = "(" + me.getClient() + ")[";
final String middle = ".+\\)\\[\\d+\\]\\{.+"; // like:)[134[{
final String endsWidth = "]{" + me.getOperatingSystem() + "}<2222>/4444\\";
messages.sendClient();
verify(service).sendMessageToAllUsers(startsWith(createMessage("CLIENT") + startsWith));
verify(service).sendMessageToAllUsers(matches(middle));
verify(service).sendMessageToAllUsers(endsWith(endsWidth));
}
内容来源于网络,如有侵权,请联系作者删除!