SWE1-MTCG/src/test/java/StoreTest.java

146 lines
6.7 KiB
Java

import at.reisinger.*;
import at.reisinger.Package;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class StoreTest {
private TradingDeal tradingDeal;
private Cards newCards, cards, nochNewCards;
private Card newCard, card;
private ArrayList<Card> cardsArrayList, cardsArrayList2, cardsArrayList3;
private Stack stack;
private User user, userNew;
private Store store;
@BeforeEach
void setUp() {
//at.reisinger.Stack
card = new Card("Name", 100, ElementTyp.WATER, CardType.MONSTER);
newCard = new Card("NameNew", 10, ElementTyp.WATER, CardType.SPELL);
cardsArrayList = new ArrayList<Card>();
cardsArrayList2 = new ArrayList<Card>();
cardsArrayList3 = new ArrayList<Card>();
cardsArrayList.add(card);
cardsArrayList2.add(newCard);
cards = new Cards(cardsArrayList);
newCards = new Cards(cardsArrayList2);
nochNewCards = new Cards(cardsArrayList3);
stack = new Stack(cards, nochNewCards);
//at.reisinger.Coins
Coins coins = new Coins(10);
//at.reisinger.User
Credentials credentials = new Credentials("username", "passwort");
user = new User(credentials, "name", "nachname", "email", stack, coins);
userNew = new User(credentials, "nameNew", "nachnameNew", "emailNew", stack, coins);
//Trading Deal
Card cardToTrade = card;
ElementTyp requiredElementType = ElementTyp.FIRE;
double requiredMinDamage = 100;
CardType requiredCardType = CardType.MONSTER;
tradingDeal = new TradingDeal(user, cardToTrade, requiredElementType, requiredMinDamage, requiredCardType);
}
@Test
void test_addTradingDeal() {
Card c1 = new Card("Name", 10, ElementTyp.FIRE, CardType.MONSTER);
Card c2 = new Card("Name1", 12, ElementTyp.FIRE, CardType.SPELL);
Card c3 = new Card("Name2", 13, ElementTyp.WATER, CardType.MONSTER);
Card c4 = new Card("Name3", 14, ElementTyp.WATER, CardType.SPELL);
Card c5 = new Card("Name4", 15, ElementTyp.FIRE, CardType.MONSTER);
ArrayList<Card> deckArrList = new ArrayList<Card>();
ArrayList<Card> stackArrList = new ArrayList<Card>();
deckArrList.add(c1);
deckArrList.add(c2);
stackArrList.add(c3);
stackArrList.add(c4);
stackArrList.add(c5);
Cards deck = new Cards(deckArrList);
Cards stack = new Cards(stackArrList);
User user = new User(new Credentials("username", "passwort"), "Name", "Nachname", "Email", new Stack(stack, deck), new Coins(1000));
ArrayList<TradingDeal> tradingDeals = new ArrayList<TradingDeal>();
ArrayList<Package> packages = new ArrayList<at.reisinger.Package>();
tradingDeals.add(new TradingDeal(user, c1, ElementTyp.FIRE, 10, CardType.MONSTER));
packages.add(new at.reisinger.Package(stack, "Test at.reisinger.Package", 100));
System.out.println(user.getTradingDeals().toString());
user.addTradingDeal(new TradingDeal(user, c1, ElementTyp.FIRE, 10, CardType.MONSTER));
System.out.println(user.getTradingDeals().toString());
System.out.println(tradingDeals.toString());
assertTrue(user.getTradingDeals().get(0).dealOk(tradingDeals.get(0)));
}
@Test
void test_doTrade() {
Card cardtest = new Card("Name", 100, ElementTyp.FIRE, CardType.MONSTER);
TradingDeal tradingDealtest = new TradingDeal(user, cardtest, ElementTyp.WATER, 100, CardType.MONSTER);
boolean result = user.doTrading(tradingDeal, tradingDealtest);
assertTrue(result);
}
@Test
void test_getTradingDeals() {
ArrayList<TradingDeal> result = user.getTradingDeals();
ArrayList<TradingDeal> expected = new ArrayList<TradingDeal>();
Card c1 = new Card("Name", 10, ElementTyp.FIRE, CardType.MONSTER);
Card c2 = new Card("Name1", 12, ElementTyp.FIRE, CardType.SPELL);
Card c3 = new Card("Name2", 13, ElementTyp.WATER, CardType.MONSTER);
Card c4 = new Card("Name3", 14, ElementTyp.WATER, CardType.SPELL);
Card c5 = new Card("Name4", 15, ElementTyp.FIRE, CardType.MONSTER);
ArrayList<Card> deckArrList = new ArrayList<Card>();
ArrayList<Card> stackArrList = new ArrayList<Card>();
deckArrList.add(c1);
deckArrList.add(c2);
stackArrList.add(c3);
stackArrList.add(c4);
stackArrList.add(c5);
Cards deck = new Cards(deckArrList);
Cards stack = new Cards(stackArrList);
User user = new User(new Credentials("username", "passwort"), "Name", "Nachname", "Email", new Stack(stack, deck), new Coins(1000));
ArrayList<TradingDeal> tradingDeals = new ArrayList<TradingDeal>();
ArrayList<at.reisinger.Package> packages = new ArrayList<at.reisinger.Package>();
tradingDeals.add(new TradingDeal(user, c1, ElementTyp.FIRE, 10, CardType.MONSTER));
packages.add(new at.reisinger.Package(stack, "Test at.reisinger.Package", 100));
assertTrue(result.get(0).dealOk(new TradingDeal(user, c1, ElementTyp.FIRE, 10, CardType.MONSTER)));
}
@Test
void test_getPossibleTradingDeals() {
Card testCard = new Card("Test", 10, ElementTyp.FIRE, CardType.MONSTER);
ArrayList<TradingDeal> result = user.getPossibleTradingDeals(testCard);
ArrayList<TradingDeal> expected = new ArrayList<TradingDeal>();
Card c1 = new Card("Name", 10, ElementTyp.FIRE, CardType.MONSTER);
Card c2 = new Card("Name1", 12, ElementTyp.FIRE, CardType.SPELL);
Card c3 = new Card("Name2", 13, ElementTyp.WATER, CardType.MONSTER);
Card c4 = new Card("Name3", 14, ElementTyp.WATER, CardType.SPELL);
Card c5 = new Card("Name4", 15, ElementTyp.FIRE, CardType.MONSTER);
ArrayList<Card> deckArrList = new ArrayList<Card>();
ArrayList<Card> stackArrList = new ArrayList<Card>();
deckArrList.add(c1);
deckArrList.add(c2);
stackArrList.add(c3);
stackArrList.add(c4);
stackArrList.add(c5);
Cards deck = new Cards(deckArrList);
Cards stack = new Cards(stackArrList);
TradingDeal vonDB = new TradingDeal(new User(new Credentials("username", "passwort"), "DerName", "Nachname", "Email", new Stack(stack, deck), new Coins(1000)), c1, ElementTyp.FIRE, 10, CardType.SPELL);
expected.add(vonDB);
System.out.println(result.get(0).getCardToTrade().getName());
System.out.println(expected.get(0).getCardToTrade().getName());
assertTrue(result.get(0).getCardToTrade().equals(expected.get(0).getCardToTrade()));
}
}