ExaminePlugin extends Plugin { @VisibleForTesting void getItemPrice(int id, ItemComposition itemComposition, int quantity) { quantity = Math.max(1, quantity); final int gePrice = itemManager.getItemPrice(id); final int alchPrice = itemComposition.getHaPrice(); if (gePrice > 0 || alchPrice > 0) { final ChatMessageBuilder message = new ChatMessageBuilder() .append(ChatColorType.NORMAL) .append("Price of ") .append(ChatColorType.HIGHLIGHT); if (quantity > 1) { message .append(QuantityFormatter.formatNumber(quantity)) .append(" x "); } message .append(itemComposition.getName()) .append(ChatColorType.NORMAL) .append(":"); if (gePrice > 0) { message .append(ChatColorType.NORMAL) .append(" GE average ") .append(ChatColorType.HIGHLIGHT) .append(QuantityFormatter.formatNumber((long) gePrice * quantity)); if (quantity > 1) { message .append(ChatColorType.NORMAL) .append(" (") .append(ChatColorType.HIGHLIGHT) .append(QuantityFormatter.formatNumber(gePrice)) .append(ChatColorType.NORMAL) .append("ea)"); } } if (alchPrice > 0) { message .append(ChatColorType.NORMAL) .append(" HA value ") .append(ChatColorType.HIGHLIGHT) .append(QuantityFormatter.formatNumber((long) alchPrice * quantity)); if (quantity > 1) { message .append(ChatColorType.NORMAL) .append(" (") .append(ChatColorType.HIGHLIGHT) .append(QuantityFormatter.formatNumber(alchPrice)) .append(ChatColorType.NORMAL) .append("ea)"); } } chatMessageManager.queue(QueuedMessage.builder() .type(ChatMessageType.ITEM_EXAMINE) .runeLiteFormattedMessage(message.build()) .build()); } }  @Subscribe void onGameStateChanged(GameStateChanged event); @Subscribe void onMenuOptionClicked(MenuOptionClicked event); @Subscribe void onChatMessage(ChatMessage event);  }
@Test public void testGetItemPrice() { ItemComposition itemComposition = mock(ItemComposition.class); when(itemComposition.getName()).thenReturn("Abyssal whip"); when(itemComposition.getHaPrice()).thenReturn(2); when(itemManager.getItemPrice(ItemID.ABYSSAL_WHIP)).thenReturn(3); examinePlugin.getItemPrice(ItemID.ABYSSAL_WHIP, itemComposition, 2_000_000_000); ArgumentCaptor<QueuedMessage> argumentCaptor = ArgumentCaptor.forClass(QueuedMessage.class); verify(chatMessageManager).queue(argumentCaptor.capture()); QueuedMessage queuedMessage = argumentCaptor.getValue(); assertEquals( "<colNORMAL>Price of <colHIGHLIGHT>2,000,000,000 x Abyssal whip<colNORMAL>:<colNORMAL> GE average <colHIGHLIGHT>6,000,000,000<colNORMAL> (<colHIGHLIGHT>3<colNORMAL>ea)<colNORMAL> HA value <colHIGHLIGHT>4,000,000,000<colNORMAL> (<colHIGHLIGHT>2<colNORMAL>ea)", queuedMessage.getRuneLiteFormattedMessage() ); }