Fix not using the selected Cash shop surprise
If you have multiple, it would always use the first one. Now it uses whichever you select (as expected).
This commit is contained in:
@@ -2,6 +2,7 @@ package net.server.channel.handlers;
|
||||
|
||||
import client.inventory.Item;
|
||||
import constants.id.ItemId;
|
||||
import net.packet.InPacket;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
@@ -15,6 +16,7 @@ import tools.PacketCreator;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.anyLong;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
@@ -31,21 +33,25 @@ class CashShopSurpriseHandlerTest extends HandlerTest {
|
||||
when(chr.getCashShop()).thenReturn(cashShop);
|
||||
}
|
||||
|
||||
private InPacket useCashShopSurprisePacket(long cashId) {
|
||||
return Packets.buildInPacket(out -> out.writeLong(cashId));
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldDoNothingWhenCsIsNotOpened() {
|
||||
when(cashShop.isOpened()).thenReturn(false);
|
||||
|
||||
handler.handlePacket(Packets.emptyInPacket(), client);
|
||||
handler.handlePacket(useCashShopSurprisePacket(123), client);
|
||||
|
||||
verify(cashShop, never()).openCashShopSurprise();
|
||||
verify(cashShop, never()).openCashShopSurprise(anyLong());
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldSendFailurePacketWhenFailToOpen() {
|
||||
when(cashShop.isOpened()).thenReturn(true);
|
||||
when(cashShop.openCashShopSurprise()).thenReturn(Optional.empty());
|
||||
when(cashShop.openCashShopSurprise(anyLong())).thenReturn(Optional.empty());
|
||||
|
||||
handler.handlePacket(Packets.emptyInPacket(), client);
|
||||
handler.handlePacket(useCashShopSurprisePacket(456), client);
|
||||
|
||||
verify(client).sendPacket(PacketCreator.onCashItemGachaponOpenFailed());
|
||||
}
|
||||
@@ -55,10 +61,10 @@ class CashShopSurpriseHandlerTest extends HandlerTest {
|
||||
when(cashShop.isOpened()).thenReturn(true);
|
||||
Item cashShopSurprise = Items.itemWithQuantity(ItemId.CASH_SHOP_SURPRISE, 3);
|
||||
Item reward = Items.itemWithQuantity(5000012, 1);
|
||||
when(cashShop.openCashShopSurprise()).thenReturn(Optional.of(new CashShop.CashShopSurpriseResult(
|
||||
when(cashShop.openCashShopSurprise(789)).thenReturn(Optional.of(new CashShop.CashShopSurpriseResult(
|
||||
cashShopSurprise, reward)));
|
||||
|
||||
handler.handlePacket(Packets.emptyInPacket(), client);
|
||||
handler.handlePacket(useCashShopSurprisePacket(789), client);
|
||||
|
||||
verify(client).sendPacket(PacketCreator.onCashGachaponOpenSuccess(ACCOUNT_ID, cashShopSurprise.getCashId(), 3,
|
||||
reward, 5000012, 1, true));
|
||||
|
||||
@@ -2,11 +2,17 @@ package testutil;
|
||||
|
||||
import io.netty.buffer.Unpooled;
|
||||
import net.packet.ByteBufInPacket;
|
||||
import net.packet.ByteBufOutPacket;
|
||||
import net.packet.InPacket;
|
||||
import net.packet.OutPacket;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class Packets {
|
||||
|
||||
public static InPacket emptyInPacket() {
|
||||
return new ByteBufInPacket(Unpooled.buffer());
|
||||
public static InPacket buildInPacket(Consumer<OutPacket> contentProvider) {
|
||||
OutPacket builderInput = new ByteBufOutPacket();
|
||||
contentProvider.accept(builderInput);
|
||||
return new ByteBufInPacket(Unpooled.wrappedBuffer(builderInput.getBytes()));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user