All Downloads are FREE. Search and download functionalities are using the official Maven repository.

generator.server.springboot.cache.ehcache.test.CacheConfigurationTest.mustache Maven / Gradle / Ivy

There is a newer version: 1.22.0
Show newest version
package {{packageName}}.wire.cache.infrastructure.secondary;

import static org.mockito.Mockito.*;

import javax.cache.Cache;
import javax.cache.CacheManager;
import javax.cache.configuration.Configuration;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import {{packageName}}.UnitTest;

@UnitTest
@ExtendWith(MockitoExtension.class)
class CacheConfigurationTest {

  private static final CacheConfiguration cacheConfiguration = new CacheConfiguration(new EhcacheProperties());

  @Mock
  private CacheManager cm;

  @Mock
  private Cache cache;

  @Mock
  private Configuration customConfig;

  @Test
  void shouldCreateDefaultCache() {
    cacheConfiguration.createCache(cm, "shouldCreateDefaultCache");
    verify(cm).createCache(eq("shouldCreateDefaultCache"), any());
  }

  @Test
  void shouldCreateCustomCache() {
    CacheConfiguration.createCache(cm, "shouldCreateCustomCache", customConfig);
    verify(cm).createCache("shouldCreateCustomCache", customConfig);
  }

  @Test
  void shouldClearExistingCache() {
    // given an existing cache "test"
    doReturn(cache).when(cm).getCache("shouldClearExistingCache");

    // when attempting to create a new cache "test"
    CacheConfiguration.createCache(cm, "shouldClearExistingCache", customConfig);

    // then destroy and create cache "test"
    verify(cache).clear();
    verify(cm, never()).createCache("shouldClearExistingCache", customConfig);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy