Hey i have an assignment that get Junit error codes. Ive tried everything i can think of, asking chatgpt, google bard and friends with some knowledge without resolving this issue:C
below is the code that needs to be modified and test cases that failed
code=java
@Test
@Order(70)
@DisplayName("It is not possible to add a dog that already has a different owner")
public void addingDogAlreadyOwnedByOtherOwner() {
var dog = newDog();
var owner = newOwner();
var otherOwner = newOwner("Otherowner");
otherOwner.addDog(dog);
var rv = owner.addDog(dog);
assertDogsOwned(false, rv, owner);
}
@Test
@Order(140)
@DisplayName("It is not possible to remove a dog that has a different owner when you do not own any dogs")
public void removingDogOwnedByOtherOwnerWhenOwningNoDogs() {
var dog = newDog();
var owner = newOwner();
var otherOwner = newOwner("Otherowner");
otherOwner.addDog(dog);
var rv = owner.addDog(dog);
assertDogsOwned(false, rv, owner);
}
@Test
@Order(150)
@DisplayName("It is not possible to remove a dog that has a different owner when you own at least one dog")
public void removingDogOwnedByOtherOwnerWhenOwningAtLeastOneOt herDog() {
var dog = newDog();
var otherDog = newDog("Otherdog");
var owner = newOwner();
var otherOwner = newOwner("Otherowner");
owner.addDog(otherDog);
otherOwner.addDog(dog);
var rv = owner.addDog(dog);
assertDogsOwned(false, rv, owner, otherDog);
}
public boolean removeDog(String dogName) {
Dog dogToRemove = getDog(dogName);
if (dogToRemove != null) {
dogs.remove(dogToRemove);
if (dogToRemove.getOwner() != null) {
dogToRemove.getOwner().removeDog(dogToRemove);
}
return true;
}
return false;
}
public boolean removeDog(Dog dog) {
if (!containsDog(dog)) {
return false;
}
if (dogs.remove(dog)) {
if (dog.getOwner() != null) {
dog.getOwner().removeDog(dog);
}
return true;
} else {
return false;
}
}
public boolean removeOwner(String ownerName) {
for (int i = 0; i < size; i++) {
if (owners[i].getName().equals(ownerName)) {
removeOwnerAtIndex(i);
return true;
}
}
return false;
}
public boolean removeOwner(Owner owner) {
for (int i = 0; i < size; i++) {
if (owners[i].equals(owner)) {
removeOwnerAtIndex(i);
return true;
}
}
return false;
}
/code