Ajuda para testes

1 resposta
Jrmanzini

Ola pessoal…queria fazer alguns testes para verificar se meu sistema esta ok…até o momento, preciso de caixas de diálogo no main para inserir no bd e verificar se esta tudo ok com as DAOs…não pretendo criar telas para isso…

classe Cliente

public class Cliente {

    private int idCliente;
    private String cliNome;
    private String cliFone;
    private Double cliDivida;
    private Conexao conecta;
 

    
public Cliente(){
}
    @Override
    public String toString() {
      return this.mostrar_nome();
}

    public int getIdCliente() {
        return idCliente;
    }
public void setCodigo(int idCliente) {
        this.idCliente= idCliente;
    }
    public int mostrar_id() {
        return (idCliente);
    }

    public Double getCliDivida() {
        return cliDivida;
    }

    public void setCliDivida(Double cliDivida) {
        this.cliDivida = cliDivida;
    }

    public String getCliFone() {
        return cliFone;
    }

    public void setCliFone(String cliFone) {
        this.cliFone = cliFone;
    }

    public String getCliNome() {
        return cliNome;
    }

    public void setCliNome(String cliNome) {
        this.cliNome = cliNome;
    }

    public Conexao getConecta() {
        return conecta;
    }

    public void setConecta(Conexao conecta) {
        this.conecta = conecta;
    }

    public String mostrar_nome() {
        return (cliNome);
    }

    public String mostrar_fone() {
        return (cliFone);
    }
 public void setNome(String cliNome) {
        this.cliNome= cliNome;
    }
    public Double mostrar_divida() {
        return (cliDivida);
    }
}

Cliente DAO

public class ClienteDAO {

    public boolean save(Cliente cliente){

        String sql = "insert into cliente (clinome,clifone,clidivida)values((?, ?, ?)";
        try {
            PreparedStatement pstm = (PreparedStatement) new Conexao().getConexao().prepareStatement(sql);
            pstm.setString(1, cliente.getCliNome());
            pstm.setString(2, cliente.getCliFone());
            pstm.setInt(3, 0);

            pstm.executeUpdate();
            return true;

        } catch (Exception e) {
            System.out.println("Erro ao inserir o Cliente");
            return false;
        }
    }
        public boolean delete(Cliente cliente){
        String sql = "DELETE cliente WHERE idcliente = ?";
        try {
            PreparedStatement pstm = (PreparedStatement) new Conexao().getConexao().prepareStatement(sql);
            pstm.setInt(1, cliente.mostrar_id());
            pstm.executeUpdate();
            return true;
        } catch (Exception e) {
            return false;
        }
        }
         public boolean update(Cliente cliente){
        String sql = "UPDATE cliente SET clinome = ? WHERE idcliente = ?";
        try {
            PreparedStatement pstm = (PreparedStatement) new Conexao().getConexao().prepareStatement(sql);
            pstm.setInt(1, cliente.mostrar_id());
            pstm.setString(2, cliente.mostrar_nome());
            pstm.executeUpdate();
            return true;
        } catch (Exception e) {
            return false;
        }
    }
       public Cliente recuperate(int codigo){
        Cliente cli;
        String sql = "SELECT idcliente, clinome FROM cliente WHERE idcliente = " + codigo;
        try {
            Statement stm = (Statement) new Conexao().getConexao().createStatement();
            ResultSet rs = (ResultSet) stm.executeQuery(sql);
            if(rs.next()){
                cli = new Cliente();
                cli.setCodigo(rs.getInt("idcliente"));
                cli.setNome(rs.getString("clinome"));
                return cli;
            }else{
                return null;
            }
        } catch (Exception e) {
            return null;
        }
    }
 public Cliente recuperate(String nome){
        Cliente cli;
        String sql = "SELECT idcliente, clinome FROM cliente WHERE clinome = " + nome;
        try {
            Statement stm = (Statement) new Conexao().getConexao().createStatement();
            ResultSet rs = (ResultSet) stm.executeQuery(sql);
            if(rs.next()){
                cli = new Cliente();
                cli.setCodigo(rs.getInt("idcliente"));
                cli.setNome(rs.getString("clinome"));
                return cli;
            }else{
                return null;
            }
        } catch (Exception e) {
            return null;
        }
    }
  public ArrayList<Cliente> recuperateAll(int ordem){
        ArrayList<Cliente> lista = new ArrayList<Cliente>();
        Cliente cli;
        String sql = "SELECT clicodigo, clinome FROM Cliente";
        if(ordem == 1)
            sql += " ORDER BY codigo";
        if(ordem == 2)
            sql += " ORDER BY nome";

        try {
            Statement stm = (Statement) new Conexao().getConexao().createStatement();
            ResultSet rs = (ResultSet) stm.executeQuery(sql);
            while(rs.next()){
            cli = new Cliente();
            cli.setCodigo(rs.getInt("clicodigo"));
            cli.setNome(rs.getString("clinome"));
            lista.add(cli);
            }
            return lista;
        } catch (Exception e) {
            return null;
        }


    }
}

1 Resposta

skylinedu

Para fazer testes simples eu utilizo o JUnit.

DIca: Pesquisa sobre TDD(Test Driven-Development). Uma técnica de desenvolvimento orientada a testes.

Criado 6 de novembro de 2010
Ultima resposta 6 de nov. de 2010
Respostas 1
Participantes 2