FullUpdateModifier { private static void createDatabase(Map<String, Collection<String>> image, NotificationEvent event, MessageDeserializer deserializer) { SentryJSONCreateDatabaseMessage message = (SentryJSONCreateDatabaseMessage) deserializer .getCreateDatabaseMessage(event.getMessage()); String dbName = message.getDB(); if ((dbName == null) || dbName.isEmpty()) { LOGGER.error("Create database event is missing database name"); return; } dbName = dbName.toLowerCase(); String location = message.getLocation(); if ((location == null) || location.isEmpty()) { LOGGER.error("Create database event is missing database location"); return; } String path = FullUpdateInitializer.pathFromURI(location); if (path == null) { return; } if (!image.containsKey(dbName)) { LOGGER.debug("create database {} with location {}", dbName, location); image.put(dbName.intern(), Collections.singleton(path)); } else { Set<String> oldLocations = (Set<String>)image.get(dbName); LOGGER.debug("database {} already exists, ignored", dbName); if (!oldLocations.contains(location)) { LOGGER.warn("database {} exists but location is different from {}", dbName, location); } } } private  FullUpdateModifier();   }
@Test public void testCreateDatabase() throws Exception { Map<String, Collection<String>> update = new HashMap<>(); NotificationEvent event = new NotificationEvent(0, 0, CREATE_DATABASE.toString(), ""); MessageDeserializer deserializer = Mockito.mock(SentryJSONMessageDeserializer.class); SentryJSONCreateDatabaseMessage message = new SentryJSONCreateDatabaseMessage(SERVER, PRINCIPAL, DB, 0L, LOCATION); Mockito.when(deserializer.getCreateDatabaseMessage("")).thenReturn(message); FullUpdateModifier.applyEvent(update, event, deserializer); Map<String, Set<String>> expected = new HashMap<>(); expected.put(DB.toLowerCase(), Collections.singleton(PATH)); assertEquals(expected, update); }