HashMap containsKey

时间:2018-04-08 12:58:26

标签: java testing junit hashmap

您好我试图运行一些junit测试,但我遇到了HashMaps的问题,基本上我必须为汽车创建一个RentalAgency 所以我有

  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);
   }

问题在于这个测试:

@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);
}

通过一些解决方法,我认为大小的断言是正确的,所以rentedVehicles hashmap确实有2辆车,但它似乎没有像我预期的那样,这个键是this.twingo和this.punto我无法弄清楚为什么或他们是什么

0 个答案:

没有答案