/*
 * 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 static ru.ming13.gambit.R.string;

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


public class ExampleDeckWriterTests extends DatabaseTestCase
{
	private ExampleDeckWriter exampleDeckWriter;

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

		exampleDeckWriter = new ExampleDeckWriter(getContext(), decks);
	}

	public void testBuildDeck() {
		exampleDeckWriter.writeDeck();

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

		Deck deck = decks.getDecksList().get(0);
		assertTrue(deck.getTitle().startsWith(getContext().getString(string.example_deck_title)));

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

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

	private void assertValidCard(Deck deck, int cardIndex) {
		String expectedFrontSideText = getContext().getString(
			ExampleDeckWriter.ANDROID_VERSIONS_RESOURCES[cardIndex]);
		String actualFrontSideText = deck.getCardsList().get(cardIndex).getFrontSideText();

		assertEquals(expectedFrontSideText, actualFrontSideText);
	}
}

@@ -635,15 +635,8 @@
 ort 
-static 
 ru.m
@@ -653,17 +653,9 @@
 it.R
-.string;%0A
+;
 %0Aimp
@@ -685,18 +685,25 @@
 cal.
-model.Deck
+ExampleDeckWriter
 ;%0Aim
@@ -730,33 +730,26 @@
 t.local.
-ExampleDeckWriter
+model.Deck
 ;%0A%0A%0Apubl
@@ -811,55 +811,8 @@
 e%0A%7B%0A
-%09private ExampleDeckWriter exampleDeckWriter;%0A%0A
 %09@Ov
@@ -885,28 +885,8 @@
 %0A%0A%09%09
-exampleDeckWriter = 
 new 
@@ -923,16 +923,28 @@
 , decks)
+.writeDeck()
 ;%0A%09%7D%0A%0A%09p
@@ -962,13 +962,15 @@
 test
-Build
+Writing
 Deck
@@ -980,36 +980,50 @@
 %7B%0A%09%09
-exampleDeckWriter.writeDeck(
+assertFalse(decks.getDecksList().isEmpty()
 );%0A%0A
@@ -1074,20 +1074,155 @@
 ));%0A
-%0A%09%09Deck deck
+%09%7D%0A%0A%09public void testDeckTitle() %7B%0A%09%09String expectedDeckTitlePrefix = getContext().getString(R.string.example_deck_title);%0A%09%09String actualDeckTitle
  = d
@@ -1247,17 +1247,29 @@
 ).get(0)
-;
+.getTitle();%0A
 %0A%09%09asser
@@ -1278,23 +1278,23 @@
 rue(
-deck.get
+actualDeck
 Title
-()
 .sta
@@ -1305,58 +1305,110 @@
 ith(
-getContext().getString(string.example_deck_title))
+expectedDeckTitlePrefix));%0A%09%7D%0A%0A%09public void testDeckCards() %7B%0A%09%09Deck deck = decks.getDecksList().get(0
 );%0A%0A
@@ -1619,25 +1619,34 @@
 %09%09assert
-ValidCard
+True(isCardCorrect
 (deck, c
@@ -1654,16 +1654,17 @@
 rdIndex)
+)
 ;%0A%09%09%7D%0A%09%7D
@@ -1678,28 +1678,29 @@
 ate 
-void assertValidCard
+boolean isCardCorrect
 (Dec
@@ -1733,37 +1733,36 @@
 %09String expected
-Front
+Back
 SideText = getCo
@@ -1852,29 +1852,28 @@
 tring actual
-Front
+Back
 SideText = d
@@ -1909,21 +1909,20 @@
 dex).get
-Front
+Back
 SideText
@@ -1932,29 +1932,23 @@
 %0A%0A%09%09
-assertEquals(
+return 
 expected
 Fron
@@ -1943,29 +1943,28 @@
 expected
-Front
+Back
 SideText
 , actual
@@ -1959,21 +1959,26 @@
 Text
-, 
+.equals(
 actual
-Front
+Back
 Side

Fix example deck writer tests and replace ugly code with shiny one.