class CerberusMetadataLookup {

    public ArrayList<String> searchCerberusMetadata(ArrayList<Map<String, String>> sdbMetadata, String sdbName, String principalName) {

        if (sdbMetadata == null) {
            throw new NullPointerException("SDB Metadata is empty");
        }

        ArrayList<String> owner = new ArrayList<>();

        for (Map<String, String> entry : sdbMetadata) {

            if (entry.get("path").contains(sdbName) && !sdbName.isEmpty()) {
                owner.add(entry.get("owner"));
                if (entry.get("created_by").contains(EMAIL_SYMBOL)) owner.add(entry.get("created_by"));
                if (entry.get("last_updated_by").contains(EMAIL_SYMBOL)
                        && !entry.get("last_updated_by").equals(entry.get("created_by"))) {
                    owner.add(entry.get("last_updated_by"));
                }
                return owner;
            } else {
                if (entry.containsValue(principalName)) {
                    owner.add(entry.get("owner"));
                    if (entry.get("created_by").contains(EMAIL_SYMBOL)) owner.add(entry.get("created_by"));
                    if (entry.get("last_updated_by").contains(EMAIL_SYMBOL)
                            && !entry.get("last_updated_by").equals(entry.get("created_by"))) {
                        owner.add(entry.get("last_updated_by"));
                    }
                    return owner;
                }
            }
        }

        owner.add("No owner found");
        return owner;
    }

}

class CerberusMetadataLookupTest {

    private static final String ERROR_RESPONSE;
    private static final String mockResponseBodyString;
    private static final String emptyMetadataResponseBodyString;
    private CerberusMetadataLookup cerberusMetadataLookup;

    @Test
    public void test_search_cerberus_metadata_parameters_empty() throws IOException {

        HashMap result = new ObjectMapper().readValue(mockResponseBodyString, HashMap.class);
        ArrayList<Map<String, String>> sdbMetadata = (ArrayList<Map<String, String>>) result.get("safe_deposit_box_metadata");

        ArrayList<String> results = cerberusMetadataLookup.searchCerberusMetadata(sdbMetadata, "", "");
        assertTrue(results.contains("No owner found"));
    }

}