@Test
  public void zoekPloegenCategorie() throws Exception {
    Ploeg a = new Ploeg();
    a.setNaam("hd");
    a.setCategorie(Categorie.U6);

    Ploeg b = new Ploeg();
    b.setNaam("hdeee");
    b.setCategorie(Categorie.U6);

    Ploeg c = new Ploeg();
    c.setNaam("haadeee");
    c.setCategorie(Categorie.U7);

    ploegDB.toevoegenPloeg(a);
    ploegDB.toevoegenPloeg(b);
    ploegDB.toevoegenPloeg(c);

    ArrayList ploegen = new ArrayList();
    ploegen = ploegDB.zoekPloegenCategorie(Categorie.U6);

    for (int i = 0; i < ploegen.size(); i++) {
      System.out.println(ploegen.get(i));
    }
  }
  @Test
  public void SpelersZoekenVanPLoeg() throws Exception {
    Persoon a = new Persoon();
    a.setGeboortedatum(1980, 3, 21);
    a.setNaam("Visiao");
    a.setVoornaam("Messi");

    Persoon b = new Persoon();
    b.setGeboortedatum(1979, 6, 13);
    b.setNaam("Plumita");
    b.setVoornaam("Ronaldo");

    persoonDB.toevoegenPersoon(a);
    persoonDB.toevoegenPersoon(b);

    Ploeg p = new Ploeg();
    p.setNaam("Los farsantes");
    p.setCategorie(Categorie.U9);
    ploegDB.toevoegenPloeg(p);
    ploegDB.toevoegenSpelerPloeg(p, a);
    ploegDB.toevoegenSpelerPloeg(p, b);

    ArrayList array = ploegDB.zoekSpelersPloeg(p);

    for (int i = 0; i < array.size(); i++) {
      System.out.println(array.get(i));
    }
  }
  @Test
  public void koppelenSpeler() throws Exception {
    Persoon een = new Persoon();
    een.setVoornaam("Davisito");
    een.setNaam("Claesito");
    een.setGeboortedatum(1960, 4, 12);

    Persoon twee = new Persoon();
    twee.setVoornaam("Cristinita");
    twee.setNaam("Claesita");
    twee.setGeboortedatum(1966, 5, 12);

    persoonDB.toevoegenPersoon(een);
    persoonDB.toevoegenPersoon(twee);

    Ploeg ploeg = new Ploeg();
    ploeg.setCategorie(Categorie.U11);
    ploeg.setNaam("aburido");

    ploegDB.toevoegenPloeg(ploeg);

    ploegDB.toevoegenSpelerPloeg(
        ploegDB.zoekPloeg(ploeg.getNaam()),
        persoonDB.zoekPersoon(een.getNaam(), een.getVoornaam()));

    ploegDB.toevoegenSpelerPloeg(
        ploegDB.zoekPloeg(ploeg.getNaam()),
        persoonDB.zoekPersoon(twee.getNaam(), twee.getVoornaam()));
  }
  @Test
  public void toevoegenPloeg() throws Exception {
    Ploeg ploeg = new Ploeg();
    ploeg.setNaam("Yaah");
    ploeg.setCategorie(Categorie.U7);

    ploegDB.toevoegenPloeg(ploeg);
  }
  @Test
  public void verwijderenPloeg() throws Exception {
    Ploeg a = new Ploeg();
    a.setCategorie(Categorie.U7);
    a.setNaam("U7a");

    ploegDB.toevoegenPloeg(a);

    ploegDB.verwijderPloeg(a);
  }
  @Test
  public void koppelenTrainerAanPloeg() throws Exception {
    Ploeg ploeg = new Ploeg();
    ploeg.setCategorie(Categorie.U8);
    ploeg.setNaam("Apllesiitos");
    ploegDB.toevoegenPloeg(ploeg);
    Persoon drie = new Persoon();
    drie.setVoornaam("Rubensito");
    drie.setNaam("Chulito");

    drie.setGeboortedatum(1998, 8, 1);

    drie.setTrainer(true);

    persoonDB.toevoegenPersoon(drie);

    ploeg = ploegDB.zoekPloeg(ploeg.getNaam());
    ploegDB.toevoegenTrainerPloeg(persoonDB.zoekPersoon("Chulito", "Rubensito"), ploeg);
  }
  /**
   * deze methode geeft een ArrayList terug waarin alle ploegen zitten met de opgegeven categorie
   *
   * @param categorie de opgegegeven categorie
   * @return
   * @throws ApplicationException
   * @throws DBException
   */
  public ArrayList<Ploeg> zoekPloegenCategorie(Categorie categorie)
      throws ApplicationException, DBException {
    ArrayList<Ploeg> kl = new ArrayList<>();
    // connectie tot stand brengen (en automatisch sluiten)
    try (Connection conn = ConnectionManager.getConnection(); ) {
      // preparedStatement opstellen (en automtisch sluiten)
      try (PreparedStatement stmt =
          conn.prepareStatement(
              "select id, naam, niveau, trainer_id from ploeg where niveau=?"); ) {
        stmt.setString(1, categorie.getTekst());
        // execute voert elke sql-statement uit, executeQuery enkel de eenvoudige
        stmt.execute();
        // result opvragen (en automatisch sluiten)
        try (ResultSet r = stmt.getResultSet()) {
          // van alle spelers uit de database Ploeg-objecten maken

          while (r.next()) {
            Ploeg k = new Ploeg();
            k.setId(r.getInt("id"));
            k.setNaam(r.getString("naam"));
            k.setCategorie(r.getString("niveau"));
            if (r.getObject("trainer_id") == null) {
              k.setTrainer(null);
            } else {
              k.setTrainer(r.getInt("trainer_id"));
            }

            kl.add(k);
          }
          return kl;
        } catch (SQLException sqlEx) {
          throw new DBException(
              "SQL-exception in zoekPloegenCategorie(Categorie categorie) - resultset" + sqlEx);
        }
      } catch (SQLException sqlEx) {
        throw new DBException(
            "SQL-exception in zoekPloegenCategorie(Categorie categorie) - statement" + sqlEx);
      }
    } catch (SQLException sqlEx) {
      throw new DBException(
          "SQL-exception in zoekPloegenCategorie(Categorie categorie) - connection" + sqlEx);
    }
  }
  @Test
  public void verwijderenPloegMetTrainer() throws Exception {
    Ploeg a = new Ploeg();
    a.setCategorie(Categorie.U9);
    a.setNaam("U7a");

    ploegDB.toevoegenPloeg(a);

    Persoon b = new Persoon();
    b.setTrainer(true);
    b.setGeboortedatum(1940, 4, 11);
    b.setNaam("Viernesito");
    b.setVoornaam("Vientesito");

    persoonDB.toevoegenPersoon(b);

    ploegDB.toevoegenTrainerPloeg(b, a);

    ploegDB.verwijderPloeg(a);
  }
  /**
   * @param id het id van de ploeg die je wilt zoeken
   * @return De te zoeken ploeg wordt geretourneerd.
   * @throws DBException
   * @throws ApplicationException
   */
  public Ploeg zoekPloeg(int id) throws DBException, ApplicationException {
    Ploeg returnPloeg = null;
    // connectie tot stand brengen (en automatisch sluiten)
    try (Connection conn = ConnectionManager.getConnection(); ) {
      // preparedStatement opstellen (en automtisch sluiten)
      try (PreparedStatement stmt =
          conn.prepareStatement("select id, naam,niveau,trainer_id from ploeg where id = ?"); ) {
        stmt.setInt(1, id);
        // execute voert het SQL-statement uit
        stmt.execute();
        // result opvragen (en automatisch sluiten)
        try (ResultSet r = stmt.getResultSet()) {
          // van de ploeg uit de database een Ploeg-object maken
          Ploeg k = new Ploeg();

          // er werd een ploeg gevonden
          if (r.next()) {
            k.setId(r.getInt("id"));
            k.setNaam(r.getString("naam"));
            k.setCategorie(r.getString("niveau"));
            if (r.getObject("trainer_id") == null) {
              k.setTrainer(null);
            } else {
              k.setTrainer(r.getInt("trainer_id"));
            }

            returnPloeg = k;
          }

          return returnPloeg;
        } catch (SQLException sqlEx) {
          throw new DBException("SQL-exception in zoekPloeg(int id) - resultset" + sqlEx);
        }
      } catch (SQLException sqlEx) {
        throw new DBException("SQL-exception in zoekPloeg(int id) - statement" + sqlEx);
      }
    } catch (SQLException sqlEx) {
      throw new DBException("SQL-exception in zoekPloeg(int id) - connection");
    }
  }
  // TODO add test methods here.
  // The methods must be annotated with annotation @Test. For example:
  //
  // @Test
  // public void hello() {}
  @Test
  public void toevoegenPloegMetTrainer() throws Exception {

    Persoon drie = new Persoon();
    drie.setVoornaam("Marnisito");
    drie.setNaam("Chulo");

    drie.setGeboortedatum(1989, 8, 1);

    drie.setTrainer(true);

    persoonDB.toevoegenPersoon(drie);

    Ploeg ploeg = new Ploeg();
    ploeg.setCategorie(Categorie.U6);
    ploeg.setNaam("las mamasitas");

    Persoon p = persoonDB.zoekPersoon(drie.getNaam(), drie.getVoornaam());
    ploeg.setTrainer(p.getId());

    ploegDB.toevoegenPloeg(ploeg);
  }
  @Test
  public void ontkoppelenSpeler() throws Exception {
    Persoon een = new Persoon();
    een.setVoornaam("stevisito");
    een.setNaam("rikisito");
    een.setGeboortedatum(1995, 4, 13);
    een.setTrainer(false);

    persoonDB.toevoegenPersoon(een);

    Ploeg ploeg = new Ploeg();
    ploeg.setCategorie(Categorie.U10);
    ploeg.setNaam("vivesito");

    ploegDB.toevoegenPloeg(ploeg);

    //
    ploegDB.toevoegenSpelerPloeg(
        ploegDB.zoekPloeg(ploeg.getNaam()),
        persoonDB.zoekPersoon(een.getNaam(), een.getVoornaam()));

    ploegDB.verwijderSpelerPloeg(een.getNaam(), een.getVoornaam());
  }
  /**
   * @return ArrayList met alle ploegen
   * @throws DBException
   * @throws ApplicationException
   */
  public ArrayList<Ploeg> zoekAllePloegen() throws DBException, ApplicationException {
    ArrayList ploegen = new ArrayList();
    // connectie tot stand brengen (en automatisch sluiten)
    try (Connection conn = ConnectionManager.getConnection(); ) {
      // preparedStatement opstellen (en automtisch sluiten)
      try (PreparedStatement stmt =
          conn.prepareStatement("select id, naam,niveau,trainer_id from ploeg"); ) {

        // execute voert het SQL-statement uit
        stmt.execute();
        // result opvragen (en automatisch sluiten)
        try (ResultSet r = stmt.getResultSet()) {
          for (int i = 0; i < ploegen.size(); i++) {
            Ploeg p = new Ploeg();
            if (r.next()) {
              p.setId(r.getInt("id"));
              p.setNaam(r.getString("naam"));
              p.setCategorie(r.getString("niveau"));
              p.setTrainer(r.getInt("trainer_id"));

              ploegen.add(p);
            }
          }

          return ploegen;

        } catch (SQLException sqlEx) {
          throw new DBException("SQL-exception in zoekAllePloegen() - resultset" + sqlEx);
        }
      } catch (SQLException sqlEx) {
        throw new DBException("SQL-exception in zoekAllePloegen() - statement" + sqlEx);
      }
    } catch (SQLException sqlEx) {
      throw new DBException("SQL-exception in zoekPloeg(String naam) - connection");
    }
  }