77import org .jboss .shrinkwrap .api .ShrinkWrap ;
88import org .jboss .shrinkwrap .api .asset .EmptyAsset ;
99import org .jboss .shrinkwrap .api .spec .JavaArchive ;
10- import org .junit .Before ;
1110import org .junit .Test ;
1211import org .junit .runner .RunWith ;
1312
14- import javax .naming .InitialContext ;
15- import javax .naming .NamingException ;
13+ import javax .ejb .EJB ;
1614
1715import static org .hamcrest .MatcherAssert .*;
1816import static org .hamcrest .Matchers .*;
2422public class AccountSessionStatelessnessTest {
2523
2624 final private float deposit_amount = 10f ;
27- private AccountSessionBean account ;
25+
26+ @ EJB
27+ AccountSessionBean account1 ;
28+
29+ @ EJB
30+ AccountSessionBean account2 ;
2831
2932 @ Deployment
3033 public static Archive <?> deployment () {
@@ -33,37 +36,35 @@ public static Archive<?> deployment() {
3336 .addAsManifestResource (EmptyAsset .INSTANCE , "beans.xml" );
3437 }
3538
36- @ Before
37- public void setup () throws NamingException {
38- InitialContext ctx = new InitialContext ();
39- Object object = ctx .lookup ("java:global/test/AccountSessionBean" );
40-
41- assertThat (object , instanceOf (AccountSessionBean .class ));
42-
43- AccountSessionBean account = (AccountSessionBean ) object ;
44- if (this .account != null ) {
45- assertThat ("Expect same instance" ,
46- account .hashCode (),
47- is (equalTo (this .account .hashCode ())));
48- }
49-
50- this .account = account ;
39+ /**
40+ * JSR 318: Enterprise JavaBeans, Version 3.1
41+ * 3.4.7.2 Session Object Identity / Stateless Session Beans
42+ *
43+ * All business object references of the same interface type for the same
44+ * stateless session bean have the same object identity, which is assigned
45+ * by the container. All references to the no-interface view of the same
46+ * stateless session bean have the same object identity.
47+ */
48+ @ Test
49+ @ InSequence (1 )
50+ public void should_be_identical_beans () {
51+ assertThat ("Expect same instances" , account1 , is (account2 ));
5152 }
5253
5354 @ Test
54- @ InSequence (1 )
55- public void should_deposit_amount () {
56- assertThat (account .getAmount (), is (equalTo (0f )));
55+ @ InSequence (2 )
56+ public void should_deposit_amount_on_first_account () {
57+ assertThat (account1 .getAmount (), is (equalTo (0f )));
5758
58- String actual = account .deposit (deposit_amount );
59+ String actual = account1 .deposit (deposit_amount );
5960
6061 assertThat (actual , is (equalTo ("Deposited: " + deposit_amount )));
61- assertThat (account .getAmount (), is (equalTo (deposit_amount )));
62+ assertThat (account1 .getAmount (), is (equalTo (deposit_amount )));
6263 }
6364
6465 @ Test
65- @ InSequence (2 )
66- public void should_contain_already_deposited_amount () {
67- assertThat (account .getAmount (), is (equalTo (deposit_amount )));
66+ @ InSequence (3 )
67+ public void should_contain_already_deposited_amount_on_second_account () {
68+ assertThat (account2 .getAmount (), is (equalTo (deposit_amount )));
6869 }
6970}
0 commit comments