### Question:
AWSGlueMetastoreCacheDecorator extends AWSGlueMetastoreBaseDecorator { @Override public Database getDatabase(String dbName) { Database result; if(databaseCacheEnabled) { Database valueFromCache = databaseCache.getIfPresent(dbName); if(valueFromCache != null) { logger.info("Cache hit for operation [getDatabase] on key [" + dbName + "]"); result = valueFromCache; } else { logger.info("Cache miss for operation [getDatabase] on key [" + dbName + "]"); result = super.getDatabase(dbName); databaseCache.put(dbName, result); } } else { result = super.getDatabase(dbName); } return result; } AWSGlueMetastoreCacheDecorator(HiveConf conf, AWSGlueMetastore awsGlueMetastore); @Override Database getDatabase(String dbName); @Override void updateDatabase(String dbName, DatabaseInput databaseInput); @Override void deleteDatabase(String dbName); @Override Table getTable(String dbName, String tableName); @Override void updateTable(String dbName, TableInput tableInput); @Override void deleteTable(String dbName, String tableName);  }### Answer:
@Test public void testGetDatabaseWhenCacheDisabled() { when(hiveConf.getBoolean(AWS_GLUE_DB_CACHE_ENABLE, false)).thenReturn(false); Database db = new Database(); AWSGlueMetastoreCacheDecorator cacheDecorator = new AWSGlueMetastoreCacheDecorator(hiveConf, glueMetastore); when(glueMetastore.getDatabase(DB_NAME)).thenReturn(db); assertEquals(db, cacheDecorator.getDatabase(DB_NAME)); assertNull(cacheDecorator.databaseCache); verify(glueMetastore, times(1)).getDatabase(DB_NAME); }
@Test public void testGetDatabaseWhenCacheEnabledAndCacheMiss() { Database db = new Database(); AWSGlueMetastoreCacheDecorator cacheDecorator = new AWSGlueMetastoreCacheDecorator(hiveConf, glueMetastore); assertNotNull(cacheDecorator.databaseCache); Cache dbCache = mock(Cache.class); cacheDecorator.databaseCache = dbCache; when(dbCache.getIfPresent(DB_NAME)).thenReturn(null); when(glueMetastore.getDatabase(DB_NAME)).thenReturn(db); doNothing().when(dbCache).put(DB_NAME, db); assertEquals(db, cacheDecorator.getDatabase(DB_NAME)); verify(glueMetastore, times(1)).getDatabase(DB_NAME); verify(dbCache, times(1)).getIfPresent(DB_NAME); verify(dbCache, times(1)).put(DB_NAME, db); }
@Test public void testGetDatabaseWhenCacheEnabledAndCacheHit() { Database db = new Database(); AWSGlueMetastoreCacheDecorator cacheDecorator = new AWSGlueMetastoreCacheDecorator(hiveConf, glueMetastore); assertNotNull(cacheDecorator.databaseCache); Cache dbCache = mock(Cache.class); cacheDecorator.databaseCache = dbCache; when(dbCache.getIfPresent(DB_NAME)).thenReturn(db); assertEquals(db, cacheDecorator.getDatabase(DB_NAME)); verify(dbCache, times(1)).getIfPresent(DB_NAME); }