Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package com.j256.ormlite.jdbc;
  
  import static org.easymock.EasyMock.createMock;
  import static org.easymock.EasyMock.expect;
  import static org.easymock.EasyMock.replay;
  import static org.easymock.EasyMock.verify;
  import static org.junit.Assert.assertEquals;
  
 
 
 import org.junit.Test;
 
 
 public class DataSourceConnectionSourceTest extends BaseJdbcTest {
 
 	@Test
 	public void testDscsUrl() throws Exception {
 		DataSource dataSource = createMock(DataSource.class);
 		expect(dataSource.getConnection()).andReturn(null);
 		replay(dataSource);
 		verify(dataSource);
 	}
 
 	@Test
 	public void testDscsSetUrl() throws Exception {
 		DataSource dataSource = createMock(DataSource.class);
 		Connection conn = createMock(Connection.class);
 		conn.close();
 		expect(dataSource.getConnection()).andReturn(conn);
 		dcs.setDataSource(dataSource);
 		dcs.initialize();
 		replay(dataSourceconn);
 		jdbcConn.close();
 		verify(dataSourceconn);
 	}
 
 	@Test
 	public void testDscsSetDatabaseType() throws Exception {
 		DataSource dataSource = createMock(DataSource.class);
 		expect(dataSource.getConnection()).andReturn(null);
 		dcs.setDataSource(dataSource);
 		dcs.initialize();
 		replay(dataSource);
 		verify(dataSource);
 	}
 
 	@Test(expected = IllegalStateException.class)
 	public void testDscsNoSetters() throws Exception {
 		dcs.initialize();
 	}
 
 	@Test
 	public void testDscsDoubleInit() throws Exception {
 		DataSource dataSource = createMock(DataSource.class);
 		dcs.initialize();
 		dcs.close();
 	}
 
 	@Test(expected = IllegalStateException.class)
 	public void testDscsNoUrlOrType() throws Exception {
 		DataSource dataSource = createMock(DataSource.class);
 		dcs.setDataSource(dataSource);
 		dcs.initialize();
 	}
 
 	@Test(expected = SQLException.class)
 	public void testDscsGetReadOnlyNoInit() throws Exception {
 	}
 
 	@Test(expected = SQLException.class)
 	public void testDscsGetReadOnlyNoInitUP() throws Exception {
 		dcs.getReadOnlyConnection("username""password");
 	}
 
 	@Test(expected = SQLException.class)
 	public void testDscsGetReadWriteNoInit() throws Exception {
	}
	@Test(expected = SQLException.class)
	public void testDscsGetReadWriteNoInitUP() throws Exception {
		dcs.getReadWriteConnection("username""password");
	}
	public void testDscsGetReadWrite() throws Exception {
		DataSource dataSource = createMock(DataSource.class);
		conn.close();
		expect(dataSource.getConnection()).andReturn(conn);
		replay(dataSourceconn);
		jdbcConn.close();
		verify(dataSourceconn);
	}
	public void testDscsGetReadWriteUP() throws Exception {
		DataSource dataSource = createMock(DataSource.class);
		conn.close();
		String userName = "user";
		String password = "password";
		expect(dataSource.getConnection(userNamepassword)).andReturn(conn);
		replay(dataSourceconn);
		DatabaseConnection jdbcConn = dcs.getReadOnlyConnection(userNamepassword);
		jdbcConn.close();
		verify(dataSourceconn);
	}
	@Test(expected = SQLException.class)
	public void testDscsReleaseNoInit() throws Exception {
	}
	@Test(expected = SQLException.class)
	public void testDscsCloseNoInit() throws Exception {
		dcs.close();
	}
	@Test(expected = IllegalStateException.class)
	public void testDscsGetDatabaseTypeNoInit() throws Exception {
	}
	public void testDscsGetReadOnlyAndClose() throws Exception {
		DataSource dataSource = createMock(DataSource.class);
		conn.close();
		expect(dataSource.getConnection()).andReturn(conn);
		replay(dataSourceconn);
		dscs.releaseConnection(dbConn);
		verify(dataSourceconn);
	}
New to GrepCode? Check out our FAQ X