@Test public void removeString() throws DatabaseException { String name = "Bokito"; List<ObservedValue> ovs = new ArrayList<ObservedValue>(); List<Individual> inds = new ArrayList<Individual>(); inds.add(new Individual()); db = Mockito.mock(Database.class); Mockito.when(db.find(ObservedValue.class, new QueryRule(ObservedValue.TARGET_NAME, Operator.EQUALS, name))) .thenReturn(ovs); Mockito.when(db.find(Individual.class, new QueryRule(Individual.NAME, Operator.EQUALS, name))).thenReturn(inds); AnimalRemover animalRemover = new AnimalRemover(db); animalRemover.removeAnimal(name); ArgumentCaptor<List> listCaptor = ArgumentCaptor.forClass(List.class); Mockito.verify(db).remove(listCaptor.capture()); Assert.assertTrue(ovs == listCaptor.getAllValues().get(0)); Mockito.verify(db).remove(inds.get(0)); }
public boolean removeAnimal(String animalName) throws DatabaseException { List<ObservedValue> selectedObsTargetValues = db.find(ObservedValue.class, new QueryRule( ObservedValue.TARGET_NAME, Operator.EQUALS, animalName)); Individual selectedIndividual = db.find(Individual.class, new QueryRule(Individual.NAME, Operator.EQUALS, animalName)).get(0); db.remove(selectedObsTargetValues); db.remove(selectedIndividual); System.out.println("Deleted animal " + animalName); return true; }
AnimalRemover { public boolean removeAnimal(String animalName) throws DatabaseException { List<ObservedValue> selectedObsTargetValues = db.find(ObservedValue.class, new QueryRule( ObservedValue.TARGET_NAME, Operator.EQUALS, animalName)); Individual selectedIndividual = db.find(Individual.class, new QueryRule(Individual.NAME, Operator.EQUALS, animalName)).get(0); db.remove(selectedObsTargetValues); db.remove(selectedIndividual); System.out.println("Deleted animal " + animalName); return true; } }
AnimalRemover { public boolean removeAnimal(String animalName) throws DatabaseException { List<ObservedValue> selectedObsTargetValues = db.find(ObservedValue.class, new QueryRule( ObservedValue.TARGET_NAME, Operator.EQUALS, animalName)); Individual selectedIndividual = db.find(Individual.class, new QueryRule(Individual.NAME, Operator.EQUALS, animalName)).get(0); db.remove(selectedObsTargetValues); db.remove(selectedIndividual); System.out.println("Deleted animal " + animalName); return true; } AnimalRemover(Database db); }
AnimalRemover { public boolean removeAnimal(String animalName) throws DatabaseException { List<ObservedValue> selectedObsTargetValues = db.find(ObservedValue.class, new QueryRule( ObservedValue.TARGET_NAME, Operator.EQUALS, animalName)); Individual selectedIndividual = db.find(Individual.class, new QueryRule(Individual.NAME, Operator.EQUALS, animalName)).get(0); db.remove(selectedObsTargetValues); db.remove(selectedIndividual); System.out.println("Deleted animal " + animalName); return true; } AnimalRemover(Database db); boolean removeAnimal(String animalName); boolean removeAnimal(Integer animalId); }
AnimalRemover { public boolean removeAnimal(String animalName) throws DatabaseException { List<ObservedValue> selectedObsTargetValues = db.find(ObservedValue.class, new QueryRule( ObservedValue.TARGET_NAME, Operator.EQUALS, animalName)); Individual selectedIndividual = db.find(Individual.class, new QueryRule(Individual.NAME, Operator.EQUALS, animalName)).get(0); db.remove(selectedObsTargetValues); db.remove(selectedIndividual); System.out.println("Deleted animal " + animalName); return true; } AnimalRemover(Database db); boolean removeAnimal(String animalName); boolean removeAnimal(Integer animalId);  }