/*
 * 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;


import ru.ming13.gambit.R;
import ru.ming13.gambit.local.ExampleDeckWriter;
import ru.ming13.gambit.local.model.Deck;


public class ExampleDeckWriterTests extends DatabaseTestCase
{
	@Override
	protected void setUp() throws Exception {
		super.setUp();

		new ExampleDeckWriter(getContext(), decks).writeDeck();
	}

	public void testWritingDeck() {
		assertFalse(decks.getDecksList().isEmpty());

		assertEquals(1, decks.getDecksList().size());
	}

	public void testDeckTitle() {
		String expectedDeckTitlePrefix = getContext().getString(R.string.example_deck_title);
		String actualDeckTitle = decks.getDecksList().get(0).getTitle();

		assertTrue(actualDeckTitle.startsWith(expectedDeckTitlePrefix));
	}

	public void testDeckCards() {
		Deck deck = decks.getDecksList().get(0);

		int cardsListSize = deck.getCardsList().size();
		assertEquals(ExampleDeckWriter.ANDROID_VERSIONS_RESOURCES.length, cardsListSize);

		for (int cardIndex = 0; cardIndex < cardsListSize; cardIndex++) {
			assertTrue(isCardCorrect(deck, cardIndex));
		}
	}

	private boolean isCardCorrect(Deck deck, int cardIndex) {
		String expectedBackSideText = getContext().getString(
			ExampleDeckWriter.ANDROID_VERSIONS_RESOURCES[cardIndex]);
		String actualBackSideText = deck.getCardsList().get(cardIndex).getBackSideText();

		return expectedBackSideText.equals(actualBackSideText);
	}
}

@@ -1733,36 +1733,37 @@
 %09String expected
-Back
+Front
 SideText = getCo
@@ -1853,28 +1853,29 @@
 tring actual
-Back
+Front
 SideText = d
@@ -1911,20 +1911,21 @@
 dex).get
-Back
+Front
 SideText
@@ -1946,20 +1946,21 @@
 expected
-Back
+Front
 SideText
@@ -1977,12 +1977,13 @@
 tual
-Back
+Front
 Side

Fix example deck writer test.