### Question:
SwrveMultiLayerLocalStorage { public LinkedHashMap<LocalStorage, LinkedHashMap<Long, String>> getCombinedFirstNEvents(Integer n, String userId) { synchronized (EVENT_LOCK) { LinkedHashMap<LocalStorage, LinkedHashMap<Long, String>> result = new LinkedHashMap<>(); int eventCount = 0; if (secondaryStorage != null) { LinkedHashMap<Long, String> events = secondaryStorage.getFirstNEvents(n, userId); eventCount = events.size(); if (eventCount > 0) { result.put(secondaryStorage, events); } } if (n - eventCount > 0) { LinkedHashMap<Long, String> events = primaryStorage.getFirstNEvents(n - eventCount, userId); int remainingEventCount = events.size(); if (remainingEventCount > 0) { result.put(primaryStorage, events); } } return result; } } SwrveMultiLayerLocalStorage(LocalStorage primaryStorage); LocalStorage getPrimaryStorage(); LocalStorage getSecondaryStorage(); void setSecondaryStorage(LocalStorage secondaryStorage); String getCacheEntry(String userId, String category); String getSecureCacheEntryForUser(String userId, String category, String uniqueKey); boolean hasQueuedEvents(String userId); LinkedHashMap<LocalStorage, LinkedHashMap<Long, String>> getCombinedFirstNEvents(Integer n, String userId); long addEvent(String userId, String eventJSON); void setAndFlushSecureSharedEntryForUser(String userId, String category, String rawData, String uniqueKey); void setCacheEntry(String userId, String category, String rawData); void flush(); SwrveUser getUserBySwrveUserId(String swrveUserId); SwrveUser getUserByExternalUserId(String externalUserId); void saveUser(SwrveUser swrveUser); void deleteUser(String swrveUserId); void saveNotificationAuthenticated(int notificationId); List<Integer> getNotificationsAuthenticated(); void deleteNotificationsAuthenticated(); void saveOfflineCampaign(String userId, String campaignId, String campaignData); String getOfflineCampaign(String userId, String campaignId); static final Object EVENT_LOCK; }### Answer:
@Test public void testGetCombinedFirstNEvents() throws Exception { String userId = "userId"; for (int i = 0; i < 20; i++) { primaryLocalStorage.addEvent(userId, "primary event" + i); } for (int i = 0; i < 20; i++) { secondaryLocalStorage.addEvent(userId, "secondary event" + i); } LinkedHashMap<LocalStorage, LinkedHashMap<Long, String>> events = multiLayerLocalStorage.getCombinedFirstNEvents(30, userId); int primaryCount = events.get(primaryLocalStorage).size(); int secondaryCount = events.get(secondaryLocalStorage).size(); assertEquals(10, primaryCount); assertEquals(20, secondaryCount); }