I need to write unit tests for my methods. I'm having a bit of trouble because I'm new to JUnit. I need to write a test for a getter method of an object type I created. The object type is UnitInfo, and I need to write a test for the method
@Override
public UnitInfo getInfo() {
return info;
}
in the class building. I put my building class, UnitInfo class and my buildingTest class in the code below. Any help is appreciated.
package main.model.facility;
import java.util.List;
public class UnitInfo {
private int capacity;
private String name;
private int idNumber;
private List<String> details;
public int getCapacity() {
return capacity;
}
public void setCapacity(int capacity) {
this.capacity = capacity;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getIdNumber() {
return idNumber;
}
public void setIdNumber(int idNumber) {
this.idNumber = idNumber;
}
public List<String> getDetails() {
return details;
}
public void setDetails(List<String> details) {
this.details = details;
}
public void addDetail(String detail) {
details.add(detail);
}
public void removeDetail(String detail) {
details.remove(detail);
}
}
Building class:
package main.model.facility;
import java.util.List;
public class Building extends Facility {
private List<IFacility<UnitInfo>> subunits;
private UnitInfo info;
private ScheduleManager schedule;
@Override
public UnitInfo getInfo() {
return info;
}
@Override
public ScheduleManager getScheduleManager() {
return schedule;
}
@Override
public List<IFacility<UnitInfo>> listFacilities() {
return subunits;
}
@Override
public int requestAvailableCapacity() {
int availableCapacity = 0;
for (IFacility<UnitInfo> subunit : subunits){
availableCapacity += subunit.requestAvailableCapacity();
}
return availableCapacity;
}
}
Junit
public class BuildingTest {
Building defaultBuilding = new Building();
ScheduleManager defaultSchedule = new ScheduleManager();
@Before
public void setUp() throws Exception {
}
@After
public void tearDown() throws Exception {
}
@Test
public void testGetInfo() { //this is the test I need to write
Building b = defaultBuilding;
assertEquals(b.getInfo(), null);
}
@Test
public void testGetScheduleManager() {
Building a = defaultBuilding;
assertEquals(a.getScheduleManager(), null);
}