/*
 * Copyright 2012 Artur Dryomov
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package ru.ming13.gambit.test.provider;


import android.database.Cursor;
import android.net.Uri;
import ru.ming13.gambit.R;
import ru.ming13.gambit.local.ExampleDeckWriter;
import ru.ming13.gambit.local.provider.ProviderUris;
import ru.ming13.gambit.local.sqlite.DbFieldNames;


public class ExampleDeckWriterTests extends GambitProviderTestCase
{
	public void testExampleDeckWriting() {
		// Example deck is the only deck in an empty database7
		int expectedDecksCount = 1;
		int actualDecksCount = queryDecks().getCount();

		assertEquals(expectedDecksCount, actualDecksCount);
	}

	public void testExampleDeckTitle() {
		String expectedExampleDeckTitlePrefix = getMockContext().getString(R.string.example_deck_title);
		String actualExampleDeckTitle = queryDeckTitle(getExampleDeckUri());

		assertTrue(actualExampleDeckTitle.startsWith(expectedExampleDeckTitlePrefix));
	}

	private Uri getExampleDeckUri() {
		Cursor decksCursor = queryDecks();

		decksCursor.moveToFirst();
		long deckId = decksCursor.getLong(decksCursor.getColumnIndex(DbFieldNames.ID));

		return ProviderUris.Content.buildDeckUri(deckId);
	}

	public void testExampleDeckCardsCount() {
		Cursor cardsCursor = queryCards(getExampleDeckUri());

		int expectedCardsCount = ExampleDeckWriter.ANDROID_VERSIONS_RESOURCES.length;
		int actualCardsCount = cardsCursor.getCount();

		assertEquals(expectedCardsCount, actualCardsCount);
	}

	public void testExampleDeckCardsTexts() {
		Cursor cardsCursor = queryCards(getExampleDeckUri());

		cardsCursor.moveToFirst();
		for (int exampleDeckCardResourceId : ExampleDeckWriter.ANDROID_VERSIONS_RESOURCES) {
			String expectedFrontSideText = getMockContext().getString(exampleDeckCardResourceId);
			String actualFrontSideText = cardsCursor.getString(
				cardsCursor.getColumnIndex(DbFieldNames.CARD_FRONT_SIDE_TEXT));

			assertEquals(expectedFrontSideText, actualFrontSideText);

			cardsCursor.moveToNext();
		}
	}
}

@@ -633,16 +633,78 @@
 ider;%0A%0A%0A
+import static org.fest.assertions.api.Assertions.assertThat;%0A%0A
 import a
@@ -727,16 +727,16 @@
 Cursor;%0A
-
 import a
@@ -1192,41 +1192,49 @@
 sert
-Equals(expectedDecksCount, actual
+That(actualDecksCount).isEqualTo(expected
 Deck
@@ -1468,11 +1468,11 @@
 ertT
-rue
+hat
 (act
@@ -1490,16 +1490,17 @@
 eckTitle
+)
 .startsW
@@ -1534,17 +1534,16 @@
 ePrefix)
-)
 ;%0A%09%7D%0A%0A%09p
@@ -2023,41 +2023,49 @@
 sert
-Equals(expectedCardsCount, actual
+That(actualCardsCount).isEqualTo(expected
 Card
@@ -2519,44 +2519,52 @@
 sert
-Equals(expectedFrontSideText, actual
+That(actualFrontSideText).isEqualTo(expected
 Fron

Move example deck writer tests to FEST assertions.