package app.android.gambit.test;


import android.test.AndroidTestCase;
import android.test.suitebuilder.annotation.Suppress;
import app.android.gambit.local.DbProvider;
import app.android.gambit.local.Deck;
import app.android.gambit.local.Decks;


@Suppress
public abstract class DatabaseTestCase extends AndroidTestCase
{
	private static final int DECKS_COUNT = 5;
	private static final int CARDS_COUNT = 5;

	protected Decks decks;

	@Override
	protected void setUp() throws Exception {
		super.setUp();

		decks = DbProvider.getInstance(getContext()).getDecks();
		decks.beginTransaction();

		emptyDatabase();
	}

	protected void emptyDatabase() {
		for (Deck deck : decks.getDecksList()) {
			decks.deleteDeck(deck);
		}
	}

	@Override
	protected void tearDown() throws Exception {
		decks.endTransaction();

		super.tearDown();
	}

	protected void fillDatabaseWithEmptyDecks() {
		if (decks.getDecksList().size() != 0) {
			return;
		}

		for (int deckIndex = 1; deckIndex <= DECKS_COUNT; deckIndex++) {
			decks.createDeck(String.format("Deck %d", deckIndex));
		}
	}

	protected void fillDeckWithCards(Deck deck) {
		if (deck.getCardsCount() != 0) {
			return;
		}

		for (int cardIndex = 1; cardIndex <= CARDS_COUNT; cardIndex++) {
			String frontSideText = String.format("Card %d in deck %d front", cardIndex, deck.getId());
			String backSideText = String.format("Card %d in deck %d back", cardIndex, deck.getId());

			deck.createCard(frontSideText, backSideText);
		}
	}

	protected void fillDatabase() {
		for (int deckIndex = 1; deckIndex <= DECKS_COUNT; deckIndex++) {
			Deck newDeck = decks.createDeck(String.format("Deck %s", deckIndex + 1));

			for (int cardIndex = 1; cardIndex <= CARDS_COUNT; cardIndex++) {
				String frontSideText = String.format("Card %s in deck %s front", cardIndex, deckIndex);
				String backSideText = String.format("Card %s in deck %s back", cardIndex, deckIndex);

				newDeck.createCard(frontSideText, backSideText);
			}
		}
	}
}

@@ -595,136 +595,22 @@
 %0A%0A%09%09
-emptyDatabase();%0A%09%7D%0A%0A%09protected void emptyDatabase() %7B%0A%09%09for (Deck deck : decks.getDecksList()) %7B%0A%09%09%09decks.deleteDeck(deck);%0A%09%09%7D
+decks.clear();
 %0A%09%7D%0A
@@ -1367,502 +1367,7 @@
 %7D%0A%09%7D
-%0A%0A%09protected void fillDatabase() %7B%0A%09%09for (int deckIndex = 1; deckIndex %3C= DECKS_COUNT; deckIndex++) %7B%0A%09%09%09Deck newDeck = decks.createDeck(String.format(%22Deck %25s%22, deckIndex + 1));%0A%0A%09%09%09for (int cardIndex = 1; cardIndex %3C= CARDS_COUNT; cardIndex++) %7B%0A%09%09%09%09String frontSideText = String.format(%22Card %25s in deck %25s front%22, cardIndex, deckIndex);%0A%09%09%09%09String backSideText = String.format(%22Card %25s in deck %25s back%22, cardIndex, deckIndex);%0A%0A%09%09%09%09newDeck.createCard(frontSideText, backSideText);%0A%09%09%09%7D%0A%09%09%7D%0A%09%7D
 %0A%7D%0A

Remove unused method from database test case.