Hajj-simulation/tests/CampaignTest.java
HeshamTB 58ed0a5df8
New test for Camp:
- test UID
	- test generateBusses()
	- test Constructor with (Dist, numberOFBusses)
2020-12-11 17:04:10 +03:00

63 lines
1.8 KiB
Java

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<Vehicle> oldVehicles = campaign.getVehicles();
assertSame(oldVehicles, campaign.getVehicles());
ArrayList<Vehicle> 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<Vehicle> 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"));
}
}