public void save() {
    try {
      Optional<Product> product = productDao.findByName(name);
      if (product.isPresent()) {
        productDao.update(this);
      } else {
        productDao.save(this);
      }
    } catch (SQLException ex) {
      LOGGER.error(ex.getMessage());
    }
  }
@Test
    void shouldSaveProduct() throws SQLException {
        when(productDao.findByName("product")).thenReturn(Optional.empty());

        product.save();

        verify(productDao, times(1)).save(product);

        when(productDao.findByName("product")).thenReturn(Optional.of(product));

        product.save();

        verify(productDao, times(1)).update(product);
    }