title: JUnit How to assertTrue/Equals on a Optional and a object
body: <p>How do I use assert.equals to test between a Optional and a Object? After debugging it shows the same values but my test still fails to pass. Returning error: at org.springframework.test.util.AssertionErrors.assertTrue </p>
  
  <p>My test class looks als following:</p>
  
  <pre><code>@RunWith(SpringJUnit4ClassRunner.class)
  @ActiveProfiles("test")
  @SpringBootTest
  public class DishServiceTest {
  
      private static final String DISH_NAME = "Kaas";
      private static final String DISH_TYPE = "Voorgerecht";
  
      @Autowired
      private DishService dishService;
  
      @Test
      public void findById(){
          //execute
          Dish dish = createDish(DISH_NAME, DISH_TYPE);
  
          Long dishId = dish.getId();
  
          Optional&lt;Dish&gt; dish2 = dishService.findById(dishId);
  
          //verify
          assertNotNull(dish2);
          //assertEquals(Optional.of(dish2), dish);
          assertTrue("created a dish" ,Optional.of(dish2).equals(dish));
      }
  
      private Dish createDish(String dishName, String dishType) {
          Dish dish = new Dish();
          dish.setDishName(dishName);
          dish.setDishType(dishType);
          Dish retval = dishService.save(dish);
          return retval;
      }
  </code></pre>
  
  <p>My debugging results:</p>
  
  <p><a href="https://i.stack.imgur.com/3PR5A.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/3PR5A.jpg" alt="enter image description here"></a></p>