@Override public Object getAsObject(FacesContext contex, UIComponent component, String obj) { Telefone t = null; if (obj.length() == 12) { t = new Telefone(); t.setDdd(Integer.parseInt(obj.substring(1, 3))); t.setNumero(Integer.parseInt(obj.substring(4, 12))); } return t; }
public void addTelefone(Telefone t) throws InvalidNumberException { if (!t.ehTelefoneValido() || telefones.contains(t)) { throw new InvalidNumberException(); } telefones.add(t); quantidadeTelefones++; }
public static void main(String args[]) { List<Telefone> lista; // = new LinkedList<>(); TelefoneDAO dao = new TelefoneDAO(); Telefone aaa = new Telefone(); aaa.setDdd(38); aaa.setNumero(123); try { lista = dao.ListarTodos(1); dao.Salvar(aaa, 1); System.out.print(lista); } catch (SQLException ex) { Logger.getLogger(Teste.class.getName()).log(Level.SEVERE, null, ex); } }
@Override public String getAsString(FacesContext contex, UIComponent component, Object obj) { Telefone t = (Telefone) obj; return t.toString(); }
@Test public void buscaFaxSemMascara() { telefone = new Telefone("123321-123321", TipoTelefone.TELEFONE); assertEquals("123321123321", telefone.getNumero(false)); }
@Test public void inicializaTelefoneValido() { telefone = new Telefone("123-321", TipoTelefone.TELEFONE); assertEquals("123-321", telefone.getNumero()); }