Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 84 additions & 0 deletions src/main/java/object/maxxblue/AnimalShelter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package object.maxxblue;



public class AnimalShelter {
private String shelterName;
private String location;
private String phoneNumber;
private int capacity;
private int currentAnimals;

public AnimalShelter(String shelterName, String location, String phoneNumber, int capacity, int currentAnimals) {
if (capacity > 10) {
throw new IllegalArgumentException("We are at CAPACITY!!");
}

if (currentAnimals > capacity) {
throw new IllegalArgumentException("Current animals cannot be more than capacity.");
}

this.shelterName = shelterName;
this.location = location;
this.phoneNumber = phoneNumber;
this.capacity = capacity;
this.currentAnimals = currentAnimals;
}

public String getShelterName() {
return shelterName;
}

public void setShelterName(String shelterName) {
this.shelterName = shelterName;
}

public String getLocation() {
return location;
}

public void setLocation(String location) {
this.location = location;
}

public String getPhoneNumber() {
return phoneNumber;
}

public void setPhoneNumber(String phoneNumber) {
this.phoneNumber = phoneNumber;
}

public int getCapacity() {
return capacity;
}

public void setCapacity(int capacity) {
if (capacity > 10) {
throw new IllegalArgumentException("We are at CAPACITY!!");
}
if (currentAnimals > capacity) {
throw new IllegalArgumentException("Capacity cannot be less than current animals.");
}
this.capacity = capacity;
}

public int getCurrentAnimals() {
return currentAnimals;
}

public void setCurrentAnimals(int currentAnimals) {
if (currentAnimals > capacity) {
throw new IllegalArgumentException("Current animals cannot be more than capacity.");
}
this.currentAnimals = currentAnimals;
}

public String getAddress() {
return location;
}

public boolean isAtCapacity() {
return currentAnimals >= capacity;
}
}
258 changes: 258 additions & 0 deletions src/test/java/object/maxxblue/AnimalShelterTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,258 @@
package object.maxxblue;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;




public class AnimalShelterTest {


@Test
public void constructor_shouldSetAllFields_correctly() {
// Arrange
String shelterName = "Happy Paws";
String location = "Delaware";
String phoneNumber = "302-555-1234";
int capacity = 8;
int currentAnimals = 5;

// Act
AnimalShelter shelter = new AnimalShelter(shelterName, location, phoneNumber, capacity, currentAnimals);

// Assert
assertEquals("Happy Paws", shelter.getShelterName());
assertEquals("Delaware", shelter.getLocation());
assertEquals("302-555-1234", shelter.getPhoneNumber());
assertEquals(8, shelter.getCapacity());
assertEquals(5, shelter.getCurrentAnimals());
}

@Test
public void constructor_shouldThrowException_whenCapacityIsGreaterThan10() {
// Arrange
String shelterName = "Happy Paws";
String location = "Delaware";
String phoneNumber = "302-555-1234";

// Act + Assert
assertThrows(IllegalArgumentException.class, () -> {
new AnimalShelter(shelterName, location, phoneNumber, 11, 5);
});
}

@Test
public void constructor_shouldThrowException_whenCurrentAnimalsIsGreaterThanCapacity() {
// Arrange
String shelterName = "Happy Paws";
String location = "Delaware";
String phoneNumber = "302-555-1234";

// Act + Assert
assertThrows(IllegalArgumentException.class, () -> {
new AnimalShelter(shelterName, location, phoneNumber, 5, 6);
});
}

@Test
public void getShelterName_shouldReturnShelterName() {
// Arrange
AnimalShelter shelter = new AnimalShelter("Happy Paws", "Delaware", "302-555-1234", 8, 5);

// Act
String result = shelter.getShelterName();

// Assert
assertEquals("Happy Paws", result);
}

@Test
public void setShelterName_shouldUpdateShelterName() {
// Arrange
AnimalShelter shelter = new AnimalShelter("Happy Paws", "Delaware", "302-555-1234", 8, 5);

// Act
shelter.setShelterName("Safe Haven");

// Assert
assertEquals("Safe Haven", shelter.getShelterName());
}

@Test
public void getLocation_shouldReturnLocation() {
// Arrange
AnimalShelter shelter = new AnimalShelter("Happy Paws", "Delaware", "302-555-1234", 8, 5);

// Act
String result = shelter.getLocation();

// Assert
assertEquals("Delaware", result);
}

@Test
public void setLocation_shouldUpdateLocation() {
// Arrange
AnimalShelter shelter = new AnimalShelter("Happy Paws", "Delaware", "302-555-1234", 8, 5);

// Act
shelter.setLocation("New Jersey");

// Assert
assertEquals("New Jersey", shelter.getLocation());
}

@Test
public void getPhoneNumber_shouldReturnPhoneNumber() {
// Arrange
AnimalShelter shelter = new AnimalShelter("Happy Paws", "Delaware", "302-555-1234", 8, 5);

// Act
String result = shelter.getPhoneNumber();

// Assert
assertEquals("302-555-1234", result);
}

@Test
public void setPhoneNumber_shouldUpdatePhoneNumber() {
// Arrange
AnimalShelter shelter = new AnimalShelter("Happy Paws", "Delaware", "302-555-1234", 8, 5);

// Act
shelter.setPhoneNumber("302-999-0000");

// Assert
assertEquals("302-999-0000", shelter.getPhoneNumber());
}

@Test
public void getCapacity_shouldReturnCapacity() {
// Arrange
AnimalShelter shelter = new AnimalShelter("Happy Paws", "Delaware", "302-555-1234", 8, 5);

// Act
int result = shelter.getCapacity();

// Assert
assertEquals(8, result);
}

@Test
public void setCapacity_shouldUpdateCapacity_whenValid() {
// Arrange
AnimalShelter shelter = new AnimalShelter("Happy Paws", "Delaware", "302-555-1234", 8, 5);

// Act
shelter.setCapacity(9);

// Assert
assertEquals(9, shelter.getCapacity());
}

@Test
public void setCapacity_shouldThrowException_whenGreaterThan10() {
// Arrange
AnimalShelter shelter = new AnimalShelter("Happy Paws", "Delaware", "302-555-1234", 8, 5);

// Act + Assert
assertThrows(IllegalArgumentException.class, () -> {
shelter.setCapacity(11);
});
}

@Test
public void setCapacity_shouldThrowException_whenLessThanCurrentAnimals() {
// Arrange
AnimalShelter shelter = new AnimalShelter("Happy Paws", "Delaware", "302-555-1234", 8, 5);

// Act + Assert
assertThrows(IllegalArgumentException.class, () -> {
shelter.setCapacity(4);
});
}

@Test
public void getCurrentAnimals_shouldReturnCurrentAnimals() {
// Arrange
AnimalShelter shelter = new AnimalShelter("Happy Paws", "Delaware", "302-555-1234", 8, 5);

// Act
int result = shelter.getCurrentAnimals();

// Assert
assertEquals(5, result);
}

@Test
public void setCurrentAnimals_shouldUpdateCurrentAnimals_whenValid() {
// Arrange
AnimalShelter shelter = new AnimalShelter("Happy Paws", "Delaware", "302-555-1234", 8, 5);

// Act
shelter.setCurrentAnimals(7);

// Assert
assertEquals(7, shelter.getCurrentAnimals());
}

@Test
public void setCurrentAnimals_shouldThrowException_whenGreaterThanCapacity() {
// Arrange
AnimalShelter shelter = new AnimalShelter("Happy Paws", "Delaware", "302-555-1234", 8, 5);

// Act + Assert
assertThrows(IllegalArgumentException.class, () -> {
shelter.setCurrentAnimals(9);
});
}

@Test
public void getAddress_shouldReturnLocation() {
// Arrange
AnimalShelter shelter = new AnimalShelter("Happy Paws", "Delaware", "302-555-1234", 8, 5);

// Act
String result = shelter.getAddress();

// Assert
assertEquals("Delaware", result);
}

@Test
public void isAtCapacity_shouldReturnFalse_whenShelterIsNotFull() {
// Arrange
AnimalShelter shelter = new AnimalShelter("Happy Paws", "Delaware", "302-555-1234", 8, 5);

// Act
boolean result = shelter.isAtCapacity();

// Assert
assertFalse(result);
}

@Test
public void isAtCapacity_shouldReturnTrue_whenShelterIsFull() {
// Arrange
AnimalShelter shelter = new AnimalShelter("Happy Paws", "Delaware", "302-555-1234", 8, 8);

// Act
boolean result = shelter.isAtCapacity();

// Assert
assertTrue(result);
}

@Test
public void isAtCapacity_shouldReturnTrue_whenCurrentAnimalsEquals10AndCapacityEquals10() {
// Arrange
AnimalShelter shelter = new AnimalShelter("Happy Paws", "Delaware", "302-555-1234", 10, 10);

// Act
boolean result = shelter.isAtCapacity();

// Assert
assertTrue(result);
}
}