Mensagens enviadas por: marthian_2
Índice dos Fóruns » Perfil de marthian_2 » Mensagens enviadas por marthian_2
Autor Mensagem
Pessoal tenho q implementar um teste de unidade para a classe DaoEmail( q esta aí em baixo) mas o JUnit deve rodar independente do estado do banco de dados. Alguem pode dar alguma dica de como fazer?

public class DaoEmail {
private Connection conexao;

public ResultSet res = null;

public DaoEmail() throws SQLException {
this.conexao = ConexaoHSQLDB.getConnection();
}

public boolean inserir(Email mail) {

boolean testa = false;

try {

Statement stmt = this.conexao.createStatement();
String query = "INSERT INTO EMAIL(id,email,id_contato)VALUES("
+ null + ",'" + mail.getEmail() + "','"
+ mail.getId_contato() + "')";
res = stmt.executeQuery(query);
stmt.close();
testa = true;
} catch (SQLException e) {
System.out.println("Erro duranta a inserção:" + e.getMessage());
}

return testa;
}

public boolean excluir(int id) {

boolean testa = false;

try {

Statement stmt = this.conexao.createStatement();
String query = "DELETE FROM EMAIL WHERE id_contato=" + id;
res = stmt.executeQuery(query);
stmt.close();
testa = true;
} catch (SQLException e) {
System.out.println("Erro duranta a exclusão:" + e.getMessage());
}

return testa;

}

public boolean listar() {

boolean testa = false;

try {

Statement stmt = this.conexao.createStatement();
String query = "SELECT EMAIL FROM EMAIL;";
res = stmt.executeQuery(query);
while (res.next()) {
String e = res.getString("email");
System.out.println(e);
System.out.println();
}
stmt.close();

if (res.next()) {
testa = true;
} else {
testa = false;
}

} catch (SQLException e) {
System.out.println("Erro duranta a pesquisa:" + e.getMessage());
}

return testa;
}

public boolean listar_por_id(int id) {

boolean testa = false;

try {

Statement stmt = this.conexao.createStatement();
String query = "SELECT EMAIL FROM EMAIL WHERE id_contato=" + id;
res = stmt.executeQuery(query);
while (res.next()) {
String e = res.getString("email");
System.out.println(e);
System.out.println();
}
stmt.close();

if (res.next()) {
testa = true;
} else {
testa = false;
}

} catch (SQLException e) {
System.out.println("Erro duranta a pesquisa:" + e.getMessage());
}

return testa;
}
}
Pessoal tenho q implementar um teste de unidade para a classe DaoEmail( q esta aí em baixo) mas o JUnit deve rodar independente do estado do banco de dados. Alguem pode dar alguma dica de como fazer?

public class DaoEmail {
private Connection conexao;

public ResultSet res = null;

public DaoEmail() throws SQLException {
this.conexao = ConexaoHSQLDB.getConnection();
}

public boolean inserir(Email mail) {

boolean testa = false;

try {

Statement stmt = this.conexao.createStatement();
String query = "INSERT INTO EMAIL(id,email,id_contato)VALUES("
+ null + ",'" + mail.getEmail() + "','"
+ mail.getId_contato() + "')";
res = stmt.executeQuery(query);
stmt.close();
testa = true;
} catch (SQLException e) {
System.out.println("Erro duranta a inserção:" + e.getMessage());
}

return testa;
}

public boolean excluir(int id) {

boolean testa = false;

try {

Statement stmt = this.conexao.createStatement();
String query = "DELETE FROM EMAIL WHERE id_contato=" + id;
res = stmt.executeQuery(query);
stmt.close();
testa = true;
} catch (SQLException e) {
System.out.println("Erro duranta a exclusão:" + e.getMessage());
}

return testa;

}

public boolean listar() {

boolean testa = false;

try {

Statement stmt = this.conexao.createStatement();
String query = "SELECT EMAIL FROM EMAIL;";
res = stmt.executeQuery(query);
while (res.next()) {
String e = res.getString("email");
System.out.println(e);
System.out.println();
}
stmt.close();

if (res.next()) {
testa = true;
} else {
testa = false;
}

} catch (SQLException e) {
System.out.println("Erro duranta a pesquisa:" + e.getMessage());
}

return testa;
}

public boolean listar_por_id(int id) {

boolean testa = false;

try {

Statement stmt = this.conexao.createStatement();
String query = "SELECT EMAIL FROM EMAIL WHERE id_contato=" + id;
res = stmt.executeQuery(query);
while (res.next()) {
String e = res.getString("email");
System.out.println(e);
System.out.println();
}
stmt.close();

if (res.next()) {
testa = true;
} else {
testa = false;
}

} catch (SQLException e) {
System.out.println("Erro duranta a pesquisa:" + e.getMessage());
}

return testa;
}
}
 
Índice dos Fóruns » Perfil de marthian_2 » Mensagens enviadas por marthian_2
Ir para:   
Powered by JForum 2.1.8 © JForum Team