Hi I'm trying to run some junit tests but I have a problem with HashMaps, basically I have to create a RentalAgency for cars So I have
public class RentalAgencyTest{
private List<Vehicle> theVehicles;
private Map<Client,Vehicle> rentedVehicles;
private RentalAgency renault;
private Vehicle twingo;
private Vehicle punto;
private Client client1;
private Client client2;
}
@Before
public void before(){
this.theVehicles = new ArrayList<Vehicle>();
this.rentedVehicles = new HashMap <Client,Vehicle>();
this.renault = new RentalAgency(theVehicles, rentedVehicles);
this.punto = new Vehicle("Fiat", "punto", 2000, 6);
this.twingo = new Vehicle("Renault", "twingo", 1998, 4);
this.client1 = new Client("Pignon", 21);
this.client2 = new Client("Leblanc", 21);
}
And the problem is with this Test :
@Test
public void testAllRentedVehicles(){
this.rentedVehicles.put(this.client1, this.punto);
this.rentedVehicles.put(this.client2, this.twingo);
assertTrue(this.rentedVehicles.containsKey(this.twingo));
assertTrue(this.rentedVehicles.containsKey(this.punto));
assertTrue(this.rentedVehicles.size() == 2);
}
With some workaround I figured that the assert on the size is true, so the rentedVehicles hashmap has 2 vehicles indeed but it doesn't seems like the keys are this.twingo and this.punto as I expected it to be and I can't figure out why or what are they
Aucun commentaire:
Enregistrer un commentaire