GrandExchangeOfferSlot extends JPanel { void updateOffer(ItemComposition offerItem, BufferedImage itemImage, @Nullable GrandExchangeOffer newOffer) { if (newOffer == null || newOffer.getState() == EMPTY) { return; } else { cardLayout.show(container, FACE_CARD); itemName.setText(offerItem.getName()); itemIcon.setIcon(new ImageIcon(itemImage)); boolean buying = newOffer.getState() == GrandExchangeOfferState.BOUGHT || newOffer.getState() == GrandExchangeOfferState.BUYING || newOffer.getState() == GrandExchangeOfferState.CANCELLED_BUY; String offerState = (buying ? "Bought " : "Sold ") + QuantityFormatter.quantityToRSDecimalStack(newOffer.getQuantitySold()) + " / " + QuantityFormatter.quantityToRSDecimalStack(newOffer.getTotalQuantity()); offerInfo.setText(offerState); itemPrice.setText(htmlLabel("Price each: ", QuantityFormatter.formatNumber(newOffer.getPrice()))); String action = buying ? "Spent: " : "Received: "; offerSpent.setText(htmlLabel(action, QuantityFormatter.formatNumber(newOffer.getSpent()) + " / " + QuantityFormatter.formatNumber(newOffer.getPrice() * newOffer.getTotalQuantity()))); progressBar.setForeground(getProgressColor(newOffer)); progressBar.setMaximumValue(newOffer.getTotalQuantity()); progressBar.setValue(newOffer.getQuantitySold()); final JPopupMenu popupMenu = new JPopupMenu(); popupMenu.setBorder(new EmptyBorder(5, 5, 5, 5)); final JMenuItem openGeLink = new JMenuItem("Open Grand Exchange website"); openGeLink.addActionListener(e -> GrandExchangePlugin.openGeLink(offerItem.getName(), offerItem.getId())); popupMenu.add(openGeLink); for (Component c : container.getComponents()) { if (c instanceof JPanel) { JPanel panel = (JPanel) c; panel.setToolTipText(htmlTooltip(((int) progressBar.getPercentage()) + "%")); panel.setComponentPopupMenu(popupMenu); } } } revalidate(); repaint(); } GrandExchangeOfferSlot();   }
@Test public void testUpdateOffer() { when(offer.getState()).thenReturn(GrandExchangeOfferState.CANCELLED_BUY); GrandExchangeOfferSlot offerSlot = new GrandExchangeOfferSlot(); offerSlot.updateOffer(mock(ItemComposition.class), mock(AsyncBufferedImage.class), offer); }