public void testNoRetryAllowedDisposesPushOperation() throws Exception { mockConsumer_.isRetryAllowed(); controlConsumer_.setDefaultReturnValue(false); controlConsumer_.replay(); mockPushOperation_.dispose(); controlPushOperation_.replay(); objectUnderTest_.retry(); controlConsumer_.verify(); controlPushOperation_.verify(); }
@Test public void testGetModifications() throws ModzRegistryException { Modifications mods = new Modifications(); final MockControl mockModzDetectorControl = MockClassControl.createControl(ModzDetector.class); final ModzDetector mockModzDetector = (ModzDetector) mockModzDetectorControl.getMock(); mockModzDetector.getModifiedFiles(); mockModzDetectorControl.setDefaultReturnValue(mods); mockModzDetectorControl.replay(); HashRegistryCacheImpl registry = new HashRegistryCacheImpl(mockModzDetector, new SoftReference(null)); assertSame(mods, registry.getModifications()); }
@Test public void testFormatEmailAsLinkEncoding() { MockControl mockApplicationPropertiesControl = MockControl.createControl(ApplicationProperties.class); ApplicationProperties mockApplicationProperties = (ApplicationProperties) mockApplicationPropertiesControl.getMock(); mockApplicationProperties.getString("jira.option.emailvisible"); mockApplicationPropertiesControl.setDefaultReturnValue("show"); mockApplicationPropertiesControl.replay(); EmailFormatterImpl emailFormatter = new EmailFormatterImpl(mockApplicationProperties); String email = emailFormatter.formatEmailAsLink("*****@*****.**", null); assertEquals("<a href=\"mailto:[email protected]\">[email protected]</a>", email); email = emailFormatter.formatEmailAsLink("\"<script>alert('owned')</script>\"@localhost", null); assertEquals( "<a href=\"mailto:"<script>alert('owned')</script>"@localhost\">"<script>alert('owned')</script>"@localhost</a>", email); mockApplicationPropertiesControl.verify(); }
@Override public void setDefaultReturnValue(final Object value) { delegate.setDefaultReturnValue(value); }
protected void setUp() throws SQLException { conControl = MockControl.createControl(Connection.class); con = (Connection) conControl.getMock(); con.isClosed(); conControl.setDefaultReturnValue(false); rsmdControl = MockControl.createControl(ResultSetMetaData.class); rsmd = (ResultSetMetaData) rsmdControl.getMock(); rsmd.getColumnCount(); rsmdControl.setReturnValue(4, 1); rsmd.getColumnLabel(1); rsmdControl.setReturnValue("name", 1); rsmd.getColumnType(1); rsmdControl.setReturnValue(Types.VARCHAR, 1); rsmd.getColumnLabel(2); rsmdControl.setReturnValue("age", 1); rsmd.getColumnType(2); rsmdControl.setReturnValue(Types.NUMERIC, 1); rsmd.getColumnLabel(3); rsmdControl.setReturnValue("birth_date", 1); rsmd.getColumnType(3); rsmdControl.setReturnValue(Types.TIMESTAMP, 1); rsmd.getColumnLabel(4); rsmdControl.setReturnValue("balance", 1); rsmd.getColumnType(4); rsmdControl.setReturnValue(Types.DECIMAL, 1); rsmdControl.replay(); rsControl = MockControl.createControl(ResultSet.class); rs = (ResultSet) rsControl.getMock(); rs.getMetaData(); rsControl.setReturnValue(rsmd, 1); rs.next(); rsControl.setReturnValue(true, 1); rs.getString("name"); rsControl.setReturnValue("Bubba", 1); rs.getLong("age"); rsControl.setReturnValue(22, 1); rs.findColumn("birth_date"); rsControl.setReturnValue(3, 1); rs.getObject(3); rsControl.setReturnValue(new java.sql.Timestamp(1221222L), 1); rs.getBigDecimal("balance"); rsControl.setReturnValue(new BigDecimal("1234.56"), 1); rs.next(); rsControl.setReturnValue(false, 1); rs.close(); rsControl.setVoidCallable(1); rsControl.replay(); stmtControl = MockControl.createControl(Statement.class); stmt = (Statement) stmtControl.getMock(); con.createStatement(); conControl.setReturnValue(stmt, 1); stmt.executeQuery("select name, age, birth_date, balance from people"); stmtControl.setReturnValue(rs, 1); stmt.getWarnings(); stmtControl.setReturnValue(null, 1); stmt.close(); stmtControl.setVoidCallable(1); conControl.replay(); stmtControl.replay(); jdbcTemplate = new JdbcTemplate(); jdbcTemplate.setDataSource(new SingleConnectionDataSource(con, false)); jdbcTemplate.setExceptionTranslator(new SQLStateSQLExceptionTranslator()); jdbcTemplate.afterPropertiesSet(); }