How to use method of org.jmock.example.sniper.AuctionSniper class

Best Jmock-library code snippet using org.jmock.example.sniper.AuctionSniper.

Run Jmock-library automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

copy
1package org.jmock.samples.sniper;
2
3import org.junit.*;
4
5import org.jmock.*;
6import org.jmock.integration.junit4.*;
7
8/**
9 * This and other classes in this package (except, naturally, AuctionSniper_JMockit_Test) are based
10 * on the original source code available
11 * <a href="http://svn.jmock.codehaus.org/browse/jmock/trunk/jmock2/example/org/jmock/example/sniper">here</a>.
12 * Small modifications were made to simplify the code, without compromising the original design.
13 */
14public final class AuctionSniperTest
15{
16   @Rule public final JUnitRuleMockery context = new JUnitRuleMockery();
17
18   final Money increment = new Money(2);
19   final Money maximumBid = new Money(20);
20   final Money beatableBid = new Money(10);
21   final Money unbeatableBid = maximumBid.add(new Money(1));
22
23   final Auction auction = context.mock(Auction.class);
24   final AuctionSniperListener listener = context.mock(AuctionSniperListener.class, "listener");
25
26   final AuctionSniper sniper = new AuctionSniper(auction, increment, maximumBid, listener);
27
28   @Test
29   public void triesToBeatTheLatestHighestBid() throws Exception
30   {
31      final Money expectedBid = beatableBid.add(increment);
32
33      context.checking(new Expectations() {{
34         oneOf(auction).bid(expectedBid);
35      }});
36
37      sniper.bidAccepted(beatableBid);
38   }
39
40   @Test
41   public void willNotBidPriceGreaterThanMaximum() throws Exception
42   {
43      context.checking(new Expectations() {{
44         ignoring(listener);
45         never(auction).bid(with(any(Money.class)));
46      }});
47
48      sniper.bidAccepted(unbeatableBid);
49   }
50
51   @Test
52   public void willLimitBidToMaximum() throws Exception
53   {
54      context.checking(new Expectations() {{
55         exactly(1).of(auction).bid(maximumBid);
56      }});
57
58      sniper.bidAccepted(maximumBid.subtract(new Money(1)));
59   }
60
61   @Test
62   public void willAnnounceItHasFinishedIfPriceGoesAboveMaximum()
63   {
64      context.checking(new Expectations() {{
65         exactly(1).of(listener).sniperFinished(sniper);
66      }});
67
68      sniper.bidAccepted(unbeatableBid);
69   }
70
71   @Test
72   public void catchesExceptionsAndReportsThemToErrorListener() throws Exception
73   {
74      final AuctionException exception = new AuctionException("test");
75
76      context.checking(new Expectations() {{
77         allowing(auction).bid(with(any(Money.class))); will(throwException(exception));
78         exactly(1).of(listener).sniperBidFailed(sniper, exception);
79      }});
80
81      sniper.bidAccepted(beatableBid);
82   }
83}
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Most used method in AuctionSniper

Trigger code on LambdaTest Cloud Grid

Execute automation tests with on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)