@Test
  public void willLimitBidToMaximum() throws Exception {
    sniper.bidAccepted(maximumBid.subtract(new Money(1)));

    new Verifications() {
      {
        auction.bid(maximumBid);
      }
    };
  }
  @Test
  public void willAnnounceItHasFinishedIfPriceGoesAboveMaximum() {
    sniper.bidAccepted(unbeatableBid);

    new Verifications() {
      {
        listener.sniperFinished(sniper);
      }
    };
  }
  @Test
  public void willAnnounceItHasFinishedIfPriceGoesAboveMaximum() {
    context.checking(
        new Expectations() {
          {
            exactly(1).of(listener).sniperFinished(sniper);
          }
        });

    sniper.bidAccepted(unbeatableBid);
  }
  @Test
  public void willNotBidPriceGreaterThanMaximum() throws Exception {
    sniper.bidAccepted(unbeatableBid);

    new Verifications() {
      {
        auction.bid((Money) any);
        times = 0;
      }
    };
  }
  @Test
  public void willLimitBidToMaximum() throws Exception {
    context.checking(
        new Expectations() {
          {
            exactly(1).of(auction).bid(maximumBid);
          }
        });

    sniper.bidAccepted(maximumBid.subtract(new Money(1)));
  }
  @Test
  public void triesToBeatTheLatestHighestBid() throws Exception {
    final Money expectedBid = beatableBid.add(increment);

    sniper.bidAccepted(beatableBid);

    new Verifications() {
      {
        auction.bid(expectedBid);
      }
    };
  }
  @Test
  public void willNotBidPriceGreaterThanMaximum() throws Exception {
    context.checking(
        new Expectations() {
          {
            ignoring(listener);
            never(auction).bid(with(any(Money.class)));
          }
        });

    sniper.bidAccepted(unbeatableBid);
  }
  @Test
  public void triesToBeatTheLatestHighestBid() throws Exception {
    final Money expectedBid = beatableBid.add(increment);

    context.checking(
        new Expectations() {
          {
            oneOf(auction).bid(expectedBid);
          }
        });

    sniper.bidAccepted(beatableBid);
  }
  @Test
  public void catchesExceptionsAndReportsThemToErrorListener() throws Exception {
    final AuctionException exception = new AuctionException("test");

    context.checking(
        new Expectations() {
          {
            allowing(auction).bid(with(any(Money.class)));
            will(throwException(exception));
            exactly(1).of(listener).sniperBidFailed(sniper, exception);
          }
        });

    sniper.bidAccepted(beatableBid);
  }
  @Test
  public void catchesExceptionsAndReportsThemToErrorListener() throws Exception {
    final AuctionException exception = new AuctionException("test");
    new Expectations() {
      {
        auction.bid((Money) any);
        result = exception;
      }
    };

    sniper.bidAccepted(beatableBid);

    new Verifications() {
      {
        listener.sniperBidFailed(sniper, exception);
      }
    };
  }
Example #11
0
 @Override
 public void sniperAdded(AuctionSniper sniper) {
   addSniperSnapshot(sniper.getSnapshot());
   sniper.addSniperListener(new SwingThreadSniperListener(this));
 }