use of com.thoughtworks.go.database.Database in project gocd by gocd.
the class H2DatabaseTest method shouldThrowUpWhenBackupFails.
@Test
public void shouldThrowUpWhenBackupFails() throws Exception {
File destDir = new File(".");
SystemEnvironment systemEnvironment = mock(SystemEnvironment.class);
Database database = new H2Database(systemEnvironment);
Database spy = spy(database);
BasicDataSource dataSource = mock(BasicDataSource.class);
Connection connection = mock(Connection.class);
Statement statement = mock(Statement.class);
doReturn(dataSource).when(spy).createDataSource();
when(dataSource.getConnection()).thenReturn(connection);
when(connection.createStatement()).thenReturn(statement);
when(statement.execute(anyString())).thenThrow(new SQLException("i failed"));
try {
spy.backup(destDir);
} catch (RuntimeException e) {
assertThat(e.getMessage(), is("i failed"));
}
verify(statement).execute(anyString());
}
use of com.thoughtworks.go.database.Database in project gocd by gocd.
the class H2DatabaseTest method shouldBackupDatabase.
@Test
public void shouldBackupDatabase() throws Exception {
File destDir = new File(".");
SystemEnvironment systemEnvironment = mock(SystemEnvironment.class);
Database database = new H2Database(systemEnvironment);
Database spy = spy(database);
BasicDataSource dataSource = mock(BasicDataSource.class);
Connection connection = mock(Connection.class);
Statement statement = mock(Statement.class);
doReturn(dataSource).when(spy).createDataSource();
when(dataSource.getConnection()).thenReturn(connection);
when(connection.createStatement()).thenReturn(statement);
when(statement.execute(anyString())).thenReturn(true);
spy.backup(destDir);
verify(statement).execute(anyString());
}
Aggregations