title: How to embed in memory MariaDB4j to replace default Spring DataSource in JUnit Tests?
body: <p>I am writing tests for <code>Service</code> that uses several data Jpa repositories. The problem is that some repositories use a lot of native queries with <code>MySQL</code> specific functions such as <code>str_to_date()</code>. So when I tried to test the service's method using <code>H2</code> I got an error saying that H2 doesn't recognize function. I have tried using H2 in MySQL mode, but got the same error.</p>
  
  <p><a href="https://stackoverflow.com/questions/6734410/is-there-a-way-to-run-mysql-in-memory-for-junit-test-cases">here</a> mariaDB4j was proposed as a work-around. I have added dependency into Maven </p>
  
  <pre><code>&lt;dependency&gt;
      &lt;groupId&gt;ch.vorburger.mariaDB4j&lt;/groupId&gt;
      &lt;artifactId&gt;mariaDB4j&lt;/artifactId&gt;
      &lt;version&gt;2.3.0&lt;/version&gt;
      &lt;scope&gt;test&lt;/scope&gt;
  &lt;/dependency&gt;
  </code></pre>
  
  <p>But getting <code>IllegalStateException : Failed to replace DataSource with an embedded database for tests. If you want an embedded database please put a supported one on the classpath or tune the replace attribute of @AutoConfigureTestDatabase</code>.</p>
  
  <p>My Test file looks this way: </p>
  
  <pre><code>@RunWith(SpringRunner.class)
  @DataJpaTest
  @AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.ANY)
  public class TestPay {
  
      @TestConfiguration
      static class PaymentServiceTestContextConfiguration {
          @Bean
          public PaymentService paymentService(){
              return new PaymentService();
          }
      }
  
      @Autowired
      private PaymentService paymentService;
      @Autowired
      private TarifRepository firstRepository;
      @Autowired
      private BuildingRepository secondRepository;
      @Autowired
      private ApartmentRepository thirdRepository;
  
      /* Test cases here*/
  }
  </code></pre>
  
  <p>The project is build with Annotation driven Spring Boot.</p>