use of email.schaal.ocreader.database.model.Feed in project ocreader by schaal.
the class DatabaseTest method testItemInsert.
@Test
public void testItemInsert() {
Realm realm = null;
try {
Feed feed = getTestFeed();
Item item = getTestItem();
realm = Realm.getDefaultInstance();
Queries.insert(realm, feed);
Queries.insert(realm, item);
item = realm.where(Item.class).findFirst();
assertEquals(item.getId(), 1);
assertEquals(item.getTitle(), ITEM_TITLE);
assertEquals(item.getBody(), BODY);
assertEquals(item.getAuthor(), AUTHOR);
assertNull(item.getEnclosureLink());
} finally {
assertNotNull(realm);
realm.close();
}
}
use of email.schaal.ocreader.database.model.Feed in project ocreader by schaal.
the class FeedTypeAdapter method fromJson.
@Override
public Feed fromJson(@NonNull JsonReader in) throws IOException {
if (in.peek() == JsonReader.Token.NULL) {
in.nextNull();
return null;
}
final NullableJsonReader reader = new NullableJsonReader(in);
final Feed feed = new Feed();
in.beginObject();
while (in.hasNext()) {
String name = in.nextName();
switch(name) {
case "id":
feed.setId(in.nextLong());
break;
case "url":
feed.setUrl(reader.nextString());
break;
case "link":
feed.setLink(reader.nextString());
break;
case "faviconLink":
String faviconLink = reader.nextString();
if (faviconLink != null && TextUtils.getTrimmedLength(faviconLink) == 0)
faviconLink = null;
feed.setFaviconLink(faviconLink);
break;
// title in API v1-2, name in API v2
case "title":
case "name":
feed.setName(StringUtils.cleanString(in.nextString()));
break;
case "added":
in.skipValue();
break;
case "folderId":
feed.setFolderId(in.nextLong());
break;
case "unreadCount":
// skip unreadCount, calculated later in SyncService
in.skipValue();
break;
case "ordering":
// createFeed returns a feed with ordering set to NULL
feed.setOrdering(reader.nextInt(0));
break;
case "pinned":
// createFeed returns a feed with pinned set to NULL
feed.setPinned(reader.nextBoolean(false));
break;
case "updateErrorCount":
feed.setUpdateErrorCount(reader.nextInt(0));
break;
case "lastUpdateError":
feed.setLastUpdateError(reader.nextString());
break;
case "error":
parseError(reader, feed);
break;
default:
Log.w(TAG, "Unknown value in feed json: " + name);
in.skipValue();
break;
}
}
in.endObject();
return feed;
}
use of email.schaal.ocreader.database.model.Feed in project ocreader by schaal.
the class FaviconLoaderTest method testGetDrawable.
@Test
public void testGetDrawable() throws Exception {
Feed feed = new Feed();
feed.setName("Test");
feed.setUrl("http://example.com");
feed.setFaviconLink(null);
assertTrue(FaviconLoader.getDrawable(RuntimeEnvironment.application, feed) instanceof TextDrawable);
assertEquals(AppCompatResources.getDrawable(RuntimeEnvironment.application, R.drawable.ic_feed_icon), FaviconLoader.getDrawable(RuntimeEnvironment.application, null));
// TODO: 01.08.16 Test feed with favicon
}
Aggregations