### Question:
Community extends DSpaceObject { public Community[] getSubcommunities() throws SQLException { List<Community> subcommunities = new ArrayList<Community>(); TableRowIterator tri = DatabaseManager.queryTable( ourContext,"community", "SELECT community.* FROM community, community2community WHERE " + "community2community.child_comm_id=community.community_id " + "AND community2community.parent_comm_id= ? ORDER BY community.name", getID()); try { while (tri.hasNext()) { TableRow row = tri.next(); Community fromCache = (Community) ourContext.fromCache( Community.class, row.getIntColumn("community_id")); if (fromCache != null) { subcommunities.add(fromCache); } else { subcommunities.add(new Community(ourContext, row)); } } } finally { if (tri != null) { tri.close(); } } Community[] communityArray = new Community[subcommunities.size()]; communityArray = (Community[]) subcommunities.toArray(communityArray); return communityArray; } Community(Context context, TableRow row); static Community find(Context context, int id); static Community create(Community parent, Context context); static Community create(Community parent, Context context, String handle); static Community[] findAll(Context context); static Community[] findAllTop(Context context); int getID(); String getHandle(); String getMetadata(String field); void setMetadata(String field, String value); String getName(); Bitstream getLogo(); Bitstream setLogo(InputStream is); void update(); Group createAdministrators(); void removeAdministrators(); Group getAdministrators(); Collection[] getCollections(); Community[] getSubcommunities(); Community getParentCommunity(); Community[] getAllParents(); Collection createCollection(); Collection createCollection(String handle); void addCollection(Collection c); Community createSubcommunity(); Community createSubcommunity(String handle); void addSubcommunity(Community c); void removeCollection(Collection c); void removeSubcommunity(Community c); void delete(); boolean equals(Object other); int hashCode(); int getType(); boolean canEditBoolean(); void canEdit(); int countItems(); DSpaceObject getAdminObject(int action); DSpaceObject getParentObject();  }### Answer:
@Test public void testGetSubcommunities() throws Exception { new NonStrictExpectations() { AuthorizeManager authManager; { AuthorizeManager.authorizeAction((Context) any, (Community) any, Constants.ADD); result = null; AuthorizeManager.authorizeActionBoolean((Context) any, (Community) any, Constants.ADD); result = true; } }; assertThat("testGetSubcommunities 0",c.getSubcommunities(), notNullValue()); assertTrue("testGetSubcommunities 1", c.getSubcommunities().length == 0); Community son = Community.create(c, context); assertThat("testGetSubcommunities 2",c.getSubcommunities(), notNullValue()); assertTrue("testGetSubcommunities 3", c.getSubcommunities().length == 1); assertThat("testGetSubcommunities 4", c.getSubcommunities()[0], equalTo(son)); }