import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import java.util.ArrayList; import static org.junit.jupiter.api.Assertions.*; public class CampaignTest { private Campaign campaign; @BeforeEach void setUp() { int numberOfBusses = 50; campaign = new Campaign(District.ALAZIZIYA, numberOfBusses); } @Test void VehicleSettersGettersWorkCorrcectly() { ArrayList oldVehicles = campaign.getVehicles(); assertSame(oldVehicles, campaign.getVehicles()); ArrayList newVehicles = new ArrayList<>(); for (int i = 0; i < 150; i++) { newVehicles.add(new Bus(5)); } campaign.setVehicles(newVehicles); assertNotSame(oldVehicles, newVehicles); assertSame(campaign.getVehicles(), newVehicles); } @Test void GenerateBussesToSameValAsParam() { campaign.generateBusses(50); assertEquals(campaign.getVehicles().size(), 50); } @Test void ConstructorWithNumberOfBusses() { campaign = new Campaign(District.ALAZIZIYA, 60); assertNotNull(campaign.getVehicles()); ArrayList list = new ArrayList<>(); list.add(new Bus(5)); list.add(new Bus(7)); campaign = new Campaign(District.ALAZIZIYA, list); assertNotNull(campaign.getVehicles()); } /* This test depends on order of tests in this file. It tests a var related to a static member. The Junit way is to run setUp() for every test case; thus, making the static car count up to how many times the object is constructed. */ @Test void UID_AsExpected(){ String uid = campaign.getUID(); assertTrue(campaign.getUID().matches("CAMP0006")); } }