HaloModule implements Parcelable { @Api(1.0) @NonNull public static List<HaloModule> fromCursor(@Nullable Cursor cursor, boolean close) { List<HaloModule> instances = new ArrayList<>(); if (cursor != null) { if (cursor.moveToFirst()) { do { instances.add(create(cursor)); } while (cursor.moveToNext()); } if (close) { cursor.close(); } } return instances; } HaloModule(); @Api(1.2)  HaloModule(@NonNull Integer customerId, @NonNull String id, @NonNull String name, boolean enabled, @NonNull Date creationDate, @Nullable Date lastUpdate, @NonNull String internalId, boolean isSingle, JSONArray fields); protected  HaloModule(Parcel in); @Api(1.0) @NonNull static HaloModule create(@NonNull Cursor cursor); @Api(1.0) @NonNull static List<HaloModule> fromCursor(@Nullable Cursor cursor, boolean close); @Api(1.0) @NonNull ContentValues getContentValues(); @Api(1.0) @NonNull Integer getCustomerId(); @Api(1.0) @NonNull String getId(); @Api(1.0) @NonNull String getName(); @Api(1.0) @NonNull Boolean isEnabled(); @Api(1.0) @Nullable Date getLastUpdate(); @Api(1.0) @NonNull Date getCreationDate(); @Api(1.0) String getInternalId(); @Api(2.3) JSONArray getFields(); @Api(1.0) boolean isSingleItemInstance(); @Override int describeContents(); @Override void writeToParcel(Parcel dest, int flags); @Override String toString(); static final Creator<HaloModule> CREATOR; }
@Test public void thatCreateListFromCursor() { Date createDate = new Date(); Date updateDate = new Date(); Cursor cursor = createCursor(5, createDate, updateDate); List<HaloModule> modules = HaloModule.fromCursor(cursor, false); assertThat(modules.size()).isEqualTo(5); for (HaloModule module : modules) { assertCursorModule(module, createDate, updateDate); } assertThat(cursor.isClosed()).isFalse(); cursor = createCursor(5, createDate, updateDate); modules = HaloModule.fromCursor(cursor, true); assertThat(modules.size()).isEqualTo(5); for (HaloModule module : modules) { assertCursorModule(module, createDate, updateDate); } assertThat(cursor.isClosed()).isTrue(); }