Merchant once again doesn't sell a card it does not have in stock.
This commit is contained in:
@@ -27,7 +27,7 @@ public class StorageBasedMerchant implements Merchant {
|
||||
private static final int DOUBLE_AFTER_DAYS_LOW_STOCK = 10;
|
||||
private static final int HALVE_AFTER_DAYS_IN_STOCK = 30;
|
||||
|
||||
private static final double PRICE_SHIFT_AFTER_TRANSACTION_PERC = 15;
|
||||
private static final double PRICE_SHIFT_AFTER_TRANSACTION_PERC = 10;
|
||||
|
||||
private LotroCardBlueprintLibrary _library;
|
||||
private MerchantDAO _merchantDao;
|
||||
@@ -65,6 +65,10 @@ public class StorageBasedMerchant implements Merchant {
|
||||
|
||||
boolean outOfStock = (lastTransaction == null || lastTransaction.getStock() <= OUT_OF_STOCK_MIN);
|
||||
|
||||
// If card is out of stock, do not sell it
|
||||
if (outOfStock)
|
||||
return null;
|
||||
|
||||
Double normalPrice = getNormalPrice(lastTransaction, blueprintId, currentTime);
|
||||
if (normalPrice == null)
|
||||
return null;
|
||||
|
||||
@@ -24,7 +24,7 @@ public class SealedLeagueDataTest {
|
||||
CollectionType collectionType = new CollectionType("test", "Test Collection");
|
||||
for (int i = 20120101; i < 20120108; i++) {
|
||||
CollectionsManager collectionsManager = Mockito.mock(CollectionsManager.class);
|
||||
Player player = new Player(1, "Test", "A", null);
|
||||
Player player = new Player(1, "Test", "pass", "u", null, null, null, null);
|
||||
data.joinLeague(collectionsManager, player, i);
|
||||
Mockito.verify(collectionsManager, new Times(1)).addPlayerCollection(Mockito.anyBoolean(), Mockito.anyString(), Mockito.eq(player), Mockito.eq(collectionType), Mockito.argThat(
|
||||
new BaseMatcher<CardCollection>() {
|
||||
@@ -59,7 +59,7 @@ public class SealedLeagueDataTest {
|
||||
CollectionType collectionType = new CollectionType("test", "Test Collection");
|
||||
for (int i = 20120108; i < 20120115; i++) {
|
||||
CollectionsManager collectionsManager = Mockito.mock(CollectionsManager.class);
|
||||
Player player = new Player(1, "Test", "A", null);
|
||||
Player player = new Player(1, "Test", "pass", "u", null, null, null, null);
|
||||
data.joinLeague(collectionsManager, player, i);
|
||||
Mockito.verify(collectionsManager, new Times(1)).addPlayerCollection(Mockito.anyBoolean(), Mockito.anyString(), Mockito.eq(player), Mockito.eq(collectionType), Mockito.argThat(
|
||||
new BaseMatcher<CardCollection>() {
|
||||
@@ -126,7 +126,7 @@ public class SealedLeagueDataTest {
|
||||
for (int i = 20120108; i < 20120115; i++) {
|
||||
CollectionsManager collectionsManager = Mockito.mock(CollectionsManager.class);
|
||||
Map<Player, CardCollection> playersInLeague = new HashMap<Player, CardCollection>();
|
||||
Player player = new Player(1, "Test", "A", null);
|
||||
Player player = new Player(1, "Test", "pass", "u", null, null, null, null);
|
||||
playersInLeague.put(player, new DefaultCardCollection());
|
||||
Mockito.when(collectionsManager.getPlayersCollection("test")).thenReturn(playersInLeague);
|
||||
int result = data.process(collectionsManager, null, 1, i);
|
||||
|
||||
@@ -3,12 +3,13 @@ package com.gempukku.lotro.merchant;
|
||||
import com.gempukku.lotro.cards.CardSets;
|
||||
import com.gempukku.lotro.db.MerchantDAO;
|
||||
import com.gempukku.lotro.game.LotroCardBlueprintLibrary;
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class StorageBasedMerchantTest {
|
||||
private StorageBasedMerchant _merchant;
|
||||
private CardSets _cardSets = new CardSets();
|
||||
@@ -26,7 +27,7 @@ public class StorageBasedMerchantTest {
|
||||
@Test
|
||||
public void cardTradingWithNoStock() {
|
||||
// Now merchant sells also cards out of stock, but at double price
|
||||
assertNotNull(_merchant.getCardSellPrice("1_1", new Date(0)));
|
||||
assertNull(_merchant.getCardSellPrice("1_1", new Date(0)));
|
||||
assertNotNull(_merchant.getCardBuyPrice("1_1", new Date(0)));
|
||||
}
|
||||
|
||||
@@ -49,7 +50,7 @@ public class StorageBasedMerchantTest {
|
||||
public void cardPriceLowersAfterMerchantBuys() {
|
||||
_merchant.cardBought("1_1", new Date(0), 700);
|
||||
int cardInitialPrice = _merchant.getCardSellPrice("1_1", new Date(0));
|
||||
assertEqualsMoreOrLess((int) (1000 / 1.15f), cardInitialPrice);
|
||||
assertEqualsMoreOrLess((int) (1000 / 1.1f), cardInitialPrice);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -60,7 +61,7 @@ public class StorageBasedMerchantTest {
|
||||
|
||||
_merchant.cardSold("1_1", new Date(0), 1000);
|
||||
int cardInitialPrice = _merchant.getCardSellPrice("1_1", new Date(0));
|
||||
assertEqualsMoreOrLess((int) (1000*1.15f), cardInitialPrice);
|
||||
assertEqualsMoreOrLess((int) (1000*1.1f), cardInitialPrice);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -79,8 +80,9 @@ public class StorageBasedMerchantTest {
|
||||
|
||||
@Test
|
||||
public void buyAndSellLosesOnValue() {
|
||||
_merchantDao.setStock("1_1", 2);
|
||||
|
||||
_merchantDao.addTransaction("1_1", 1000, new Date(0), MerchantDAO.TransactionType.BUY);
|
||||
_merchantDao.setStock("1_1", 5);
|
||||
|
||||
long time = 0;
|
||||
// Buy 5 times the same card every 10 seconds, then sell the 5, also every 10 sec
|
||||
int moneySpent = 0;
|
||||
|
||||
@@ -4,12 +4,13 @@ import com.gempukku.lotro.collection.CollectionsManager;
|
||||
import com.gempukku.lotro.db.vo.CollectionType;
|
||||
import com.gempukku.lotro.game.Player;
|
||||
import com.gempukku.lotro.logic.vo.LotroDeck;
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class SingleEliminationRecurringQueueTest {
|
||||
@Test
|
||||
public void joiningQueue() {
|
||||
@@ -18,7 +19,7 @@ public class SingleEliminationRecurringQueueTest {
|
||||
ImmediateRecurringQueue queue = new ImmediateRecurringQueue(10, "format", CollectionType.MY_CARDS,
|
||||
"id-", "name-", 2, false, tournamentService, new NoPrizes(), new SingleEliminationPairing("singleElimination"));
|
||||
|
||||
Player player = new Player(1, "p1", "u", null);
|
||||
Player player = new Player(1, "p1", "pass", "u", null, null, null, null);
|
||||
|
||||
CollectionsManager collectionsManager = Mockito.mock(CollectionsManager.class);
|
||||
Mockito.when(collectionsManager.removeCurrencyFromPlayerCollection(Mockito.anyString(), Mockito.eq(player), Mockito.eq(CollectionType.MY_CARDS), Mockito.eq(10)))
|
||||
@@ -40,7 +41,7 @@ public class SingleEliminationRecurringQueueTest {
|
||||
ImmediateRecurringQueue queue = new ImmediateRecurringQueue(10, "format", CollectionType.MY_CARDS,
|
||||
"id-", "name-", 2, false, tournamentService, new NoPrizes(), new SingleEliminationPairing("singleElimination"));
|
||||
|
||||
Player player = new Player(1, "p1", "u", null);
|
||||
Player player = new Player(1, "p1", "pass", "u", null, null, null, null);
|
||||
|
||||
CollectionsManager collectionsManager = Mockito.mock(CollectionsManager.class);
|
||||
Mockito.when(collectionsManager.removeCurrencyFromPlayerCollection(Mockito.anyString(), Mockito.eq(player), Mockito.eq(CollectionType.MY_CARDS), Mockito.eq(10)))
|
||||
@@ -65,7 +66,7 @@ public class SingleEliminationRecurringQueueTest {
|
||||
ImmediateRecurringQueue queue = new ImmediateRecurringQueue(10, "format", CollectionType.MY_CARDS,
|
||||
"id-", "name-", 2, false, tournamentService, new NoPrizes(), new SingleEliminationPairing("singleElimination"));
|
||||
|
||||
Player player = new Player(1, "p1", "u", null);
|
||||
Player player = new Player(1, "p1", "pass", "u", null, null, null, null);
|
||||
|
||||
CollectionsManager collectionsManager = Mockito.mock(CollectionsManager.class);
|
||||
Mockito.when(collectionsManager.removeCurrencyFromPlayerCollection(Mockito.anyString(), Mockito.eq(player), Mockito.eq(CollectionType.MY_CARDS), Mockito.eq(10)))
|
||||
@@ -96,8 +97,8 @@ public class SingleEliminationRecurringQueueTest {
|
||||
"id-", "name-", 2, false, tournamentService, new NoPrizes(), new SingleEliminationPairing("singleElimination"));
|
||||
|
||||
|
||||
Player player1 = new Player(1, "p1", "u", null);
|
||||
Player player2 = new Player(2, "p2", "u", null);
|
||||
Player player1 = new Player(1, "p1", "pass", "u", null, null, null, null);
|
||||
Player player2 = new Player(2, "p2", "pass", "u", null, null, null, null);
|
||||
|
||||
CollectionsManager collectionsManager = Mockito.mock(CollectionsManager.class);
|
||||
Mockito.when(collectionsManager.removeCurrencyFromPlayerCollection(Mockito.anyString(), Mockito.<Player>any(), Mockito.eq(CollectionType.MY_CARDS), Mockito.eq(10)))
|
||||
@@ -142,9 +143,9 @@ public class SingleEliminationRecurringQueueTest {
|
||||
ImmediateRecurringQueue queue = new ImmediateRecurringQueue(10, "format", CollectionType.MY_CARDS,
|
||||
"id-", "name-", 2, false, tournamentService, new NoPrizes(), new SingleEliminationPairing("singleElimination"));
|
||||
|
||||
Player player1 = new Player(1, "p1", "u", null);
|
||||
Player player2 = new Player(2, "p2", "u", null);
|
||||
Player player3 = new Player(3, "p3", "u", null);
|
||||
Player player1 = new Player(1, "p1", "pass", "u", null, null, null, null);
|
||||
Player player2 = new Player(2, "p2", "pass", "u", null, null, null, null);
|
||||
Player player3 = new Player(3, "p3", "pass", "u", null, null, null, null);
|
||||
|
||||
CollectionsManager collectionsManager = Mockito.mock(CollectionsManager.class);
|
||||
Mockito.when(collectionsManager.removeCurrencyFromPlayerCollection(Mockito.anyString(), Mockito.<Player>any(), Mockito.eq(CollectionType.MY_CARDS), Mockito.eq(10)))
|
||||
|
||||
Reference in New Issue
Block a user