title: Why am I getting an assertion error when there should be a match JUnit?
body: <p>The problem is that the test not be recognizing the car object even though they are identical. I am getting a <code>java.lang.assertion</code> error. Are they of the wrong type or is this from another error? Please comment if more code is required.</p>
  <p>The error:
  <img src="https://i.stack.imgur.com/DmBvb.png" alt="error" /></p>
  <p>Testing class:</p>
  <pre><code>import DAO.CarDAO;
  import DAO.CarJdbcDAO;
  import Domain.Car;
  import java.math.BigDecimal;
  import static org.hamcrest.CoreMatchers.hasItem;
  import static org.hamcrest.CoreMatchers.not;
  import static org.hamcrest.Matchers.hasSize;
  import static org.junit.Assert.assertThat;
  import org.junit.jupiter.api.AfterEach;
  import org.junit.jupiter.api.BeforeEach;
  import org.junit.jupiter.api.Test;
  
  /**
   *
   * @author shika823
   */
  public class CarJdbcDAOTest {
  
      public CarJdbcDAOTest() {
      }
  
      /**
       *
       * @author shika823
       */
      private CarDAO dao = new CarJdbcDAO(&quot;jdbc:h2:mem:test;INIT=runscript from 'src/main/java/DAO/schema.sql'&quot;);
  
      private Car car1;
  
      private Car car2;
  
      private Car car3;
  
  //    String carName, int carId, String carType, String seatNumber, BigDecimal hourlyCharge, String location) {
      @BeforeEach
      public void setUp() {
          car1 = new Car();
          car1.setCarId(&quot;12412&quot;);
          car1.setCarName(&quot;Car sokmet&quot;);
          car1.setCarType(&quot;A type&quot;);
          car1.setSeatNumber(&quot;1&quot;);
          car1.setHourlyCharge(new BigDecimal(&quot;4.00&quot;));
          car1.setLocation(&quot;30 Duke Street&quot;);
  
          car2 = new Car();
          car2.setCarId(&quot;12902&quot;);
          car2.setCarName(&quot;Car sething&quot;);
          car2.setCarType(&quot;A tyjksspe&quot;);
          car2.setSeatNumber(&quot;2&quot;);
          car2.setHourlyCharge(new BigDecimal(&quot;3.00&quot;));
          car2.setLocation(&quot;28 Duke Street&quot;);
  //        
          car3 = new Car();
          car3.setCarId(&quot;1862&quot;);
          car3.setCarName(&quot;Car setng&quot;);
          car3.setCarType(&quot;yjksspe&quot;);
          car3.setSeatNumber(&quot;8&quot;);
          car3.setHourlyCharge(new BigDecimal(&quot;3.00&quot;));
          car3.setLocation(&quot;98 Duke Street&quot;);
          
          
          dao.saveCar(car1);
          dao.saveCar(car2);
  
      }
  
      @AfterEach
      public void tearDown() {
          dao.removeCar(car1);
          dao.removeCar(car2);
      }
  
      @Test
      public void testSaveCar() {
          dao.saveCar(car3);
  
          assertThat(dao.getCars(), hasItem(car1));
          assertThat(dao.getCars(), hasItem(car2));
          assertThat(dao.getCars(), hasItem(car3));
          dao.removeCar(car3);
  
      }
  
      @Test
      public void testGetCars() {
          assertThat(dao.getCars(), hasItem(car1));
   
      }
  
      @Test
      public void testRemoveCar() {
          dao.removeCar(car1);
          assertThat(dao.getCars(), hasSize(1));
          assertThat(dao.getCars(), not(hasItem(car1)));
      }
  
  }
   
  </code></pre>
  <p>Here is my jdbc dao class:</p>
  <pre><code>[enter image description here][1]import Domain.Car;
  import java.math.BigDecimal;
  import java.sql.Connection;
  import java.sql.PreparedStatement;
  import java.sql.ResultSet;
  import java.sql.SQLException;
  import java.util.ArrayList;
  import java.util.Collection;
  import java.util.HashSet;
  import java.util.List;
  
  /**
   *
   * @author jamespettitt
   */
  public class CarJdbcDAO implements CarDAO {
  
      private String url = JdbcConnection.getDefaultConnectionUri();
  
      public CarJdbcDAO() {
      }
  
      public CarJdbcDAO(String uri) {
          this.url = uri;
      }
  
      @Override
      public void saveCar(Car car) {
          String sql = &quot;merge into car (car_id, car_Name, car_Type, Seat_Number, Hourly_Charge, Location) values (?, ?, ?, ?, ?, ?)&quot;;
  
          try (
              Connection dbCon = JdbcConnection.getConnection(url);
              PreparedStatement stmt = dbCon.prepareStatement(sql);) {
              stmt.setString(1, car.getCarId());
              stmt.setString(2, car.getCarName());
              stmt.setString(3, car.getCarType());
              stmt.setString(4, car.getSeatNumber());
              stmt.setBigDecimal(5, car.getHourlyCharge());
              stmt.setString(6, car.getLocation());
  
              stmt.executeUpdate();
  
          } catch (SQLException ex) {
              throw new DAOException(ex.getMessage(), ex);
          }
      }
  
      @Override
      public Collection&lt;Car&gt; getCars() {
          
  
          String sql = &quot;select * from Car&quot;;
          try (
              Connection dbCon = JdbcConnection.getConnection(url); //get connection to db
              PreparedStatement stmt = dbCon.prepareStatement(sql); //create stmt
              ) {
              ResultSet rs = stmt.executeQuery(); 
  
              ArrayList&lt;Car&gt; cars = new ArrayList&lt;&gt;(); 
  
              //iterate through query results
              while (rs.next()) {
                              
  
                  
                      String carId = rs.getString(&quot;Car_Id&quot;);
                      String carName = rs.getString(&quot;Car_Name&quot;);
                      
                      String carType = rs.getString(&quot;Car_Type&quot;);
                      String seatNumber = rs.getString(&quot;Seat_Number&quot;);
                      BigDecimal hourlyCharge = rs.getBigDecimal(&quot;Hourly_Charge&quot;);
                      String location = rs.getString(&quot;Location&quot;);
                                                  
                                                  Car car = new Car(carId, carName, carType, seatNumber, hourlyCharge, location);
                                                  
  
                  cars.add(car); 
  
              }
  
              return cars;
  
          } catch (SQLException ex) {
              throw new DAOException(ex.getMessage(), ex);
          }
      }
  
      @Override
      public void removeCar(Car car) {
  
          String sql = &quot;delete from car where car_ID = ?&quot;;
  
          try (
              Connection dbCon = JdbcConnection.getConnection(url);
              PreparedStatement stmt = dbCon.prepareStatement(sql);) {
              stmt.setString(1, car.getCarId());
              stmt.executeUpdate();
  
          } catch (SQLException ex) {
              throw new DAOException(ex.getMessage(), ex);
          }
      }
  
      @Override
  
      public Collection&lt;Car&gt; filterByType(String carType) {
          String sql = &quot;select * from car where Type = ?&quot;;
          System.out.println(carType);
          try (
              Connection dbCon = JdbcConnection.getConnection(url);
              PreparedStatement stmt = dbCon.prepareStatement(sql);) {
              stmt.setString(1, carType);
              ResultSet rs = stmt.executeQuery();
  
              List&lt;Car&gt; typeList = new ArrayList&lt;&gt;();
  
              while (rs.next()) {
                  Car car = new Car(
                      rs.getString(&quot;Car_id&quot;),
                      rs.getString(&quot;car_Name&quot;),
                      
                      rs.getString(&quot;car_Type&quot;),
                      rs.getString(&quot;Seat_Number&quot;),
                      rs.getBigDecimal(&quot;Hourly_Charge&quot;),
                      rs.getString(&quot;Location&quot;)
                  );
                  System.out.println(car);
                  typeList.add(car);
              }
              return typeList;
          } catch (SQLException ex) {
              throw new DAOException(ex.getMessage(), ex);
          }
      }
  
      @Override
      public Collection&lt;Car&gt; filterBySeatNumber(String seatNumber) {
          String sql = &quot;select * from car where Seat_Number = ?&quot;;
          System.out.println(seatNumber);
          try (
              Connection dbCon = JdbcConnection.getConnection(url);
              PreparedStatement stmt = dbCon.prepareStatement(sql);) {
              stmt.setString(1, seatNumber);
              ResultSet rs = stmt.executeQuery();
  
              ArrayList&lt;Car&gt; seatNumberList = new ArrayList&lt;&gt;();
  
              while (rs.next()) {
                  Car car = new Car(
                      rs.getString(&quot;Car_id&quot;),
                      rs.getString(&quot;car_Name&quot;),
                      
                      rs.getString(&quot;car_Type&quot;),
                      rs.getString(&quot;Seat_Number&quot;),
                      rs.getBigDecimal(&quot;Hourly_Charge&quot;),
                      rs.getString(&quot;Location&quot;)
                  );
                  System.out.println(car);
                  seatNumberList.add(car);
              }
              return seatNumberList;
          } catch (SQLException ex) {
              throw new DAOException(ex.getMessage(), ex);
          }
      }
  
  }
   
  </code></pre>