|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2019 the original author or authors. |
| 2 | + * Copyright 2002-2020 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
14 | 14 | * limitations under the License.
|
15 | 15 | */
|
16 | 16 |
|
17 |
| -package org.springframework.test.context.junit4.spr9645; |
| 17 | +package org.springframework.test.context.transaction.manager; |
18 | 18 |
|
19 |
| -import org.junit.Test; |
20 |
| -import org.junit.runner.RunWith; |
| 19 | +import org.junit.jupiter.api.Test; |
21 | 20 |
|
| 21 | +import org.springframework.beans.factory.annotation.Autowired; |
22 | 22 | import org.springframework.context.annotation.Bean;
|
23 | 23 | import org.springframework.context.annotation.Configuration;
|
24 |
| -import org.springframework.test.context.ContextConfiguration; |
25 |
| -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; |
| 24 | +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; |
26 | 25 | import org.springframework.test.context.transaction.AfterTransaction;
|
27 |
| -import org.springframework.test.context.transaction.BeforeTransaction; |
28 | 26 | import org.springframework.transaction.PlatformTransactionManager;
|
29 | 27 | import org.springframework.transaction.annotation.Transactional;
|
30 | 28 | import org.springframework.transaction.testfixture.CallCountingTransactionManager;
|
|
38 | 36 | * @author Sam Brannen
|
39 | 37 | * @since 3.2
|
40 | 38 | */
|
41 |
| -@RunWith(SpringJUnit4ClassRunner.class) |
42 |
| -@ContextConfiguration |
| 39 | +@SpringJUnitConfig |
43 | 40 | @Transactional("txManager1")
|
44 |
| -public class LookUpTxMgrByTypeAndQualifierAtClassLevelTests { |
| 41 | +class LookUpTxMgrByTypeAndQualifierAtClassLevelTests { |
45 | 42 |
|
46 |
| - private static final CallCountingTransactionManager txManager1 = new CallCountingTransactionManager(); |
47 |
| - private static final CallCountingTransactionManager txManager2 = new CallCountingTransactionManager(); |
| 43 | + @Autowired |
| 44 | + CallCountingTransactionManager txManager1; |
48 | 45 |
|
49 |
| - @Configuration |
50 |
| - static class Config { |
51 |
| - |
52 |
| - @Bean |
53 |
| - public PlatformTransactionManager txManager1() { |
54 |
| - return txManager1; |
55 |
| - } |
56 |
| - |
57 |
| - @Bean |
58 |
| - public PlatformTransactionManager txManager2() { |
59 |
| - return txManager2; |
60 |
| - } |
61 |
| - } |
| 46 | + @Autowired |
| 47 | + CallCountingTransactionManager txManager2; |
62 | 48 |
|
63 |
| - @BeforeTransaction |
64 |
| - public void beforeTransaction() { |
65 |
| - txManager1.clear(); |
66 |
| - txManager2.clear(); |
67 |
| - } |
68 | 49 |
|
69 | 50 | @Test
|
70 |
| - public void transactionalTest() { |
| 51 | + void transactionalTest() { |
71 | 52 | assertThat(txManager1.begun).isEqualTo(1);
|
72 | 53 | assertThat(txManager1.inflight).isEqualTo(1);
|
73 | 54 | assertThat(txManager1.commits).isEqualTo(0);
|
74 | 55 | assertThat(txManager1.rollbacks).isEqualTo(0);
|
| 56 | + |
| 57 | + assertThat(txManager2.begun).isEqualTo(0); |
| 58 | + assertThat(txManager2.inflight).isEqualTo(0); |
| 59 | + assertThat(txManager2.commits).isEqualTo(0); |
| 60 | + assertThat(txManager2.rollbacks).isEqualTo(0); |
75 | 61 | }
|
76 | 62 |
|
77 | 63 | @AfterTransaction
|
78 |
| - public void afterTransaction() { |
| 64 | + void afterTransaction() { |
79 | 65 | assertThat(txManager1.begun).isEqualTo(1);
|
80 | 66 | assertThat(txManager1.inflight).isEqualTo(0);
|
81 | 67 | assertThat(txManager1.commits).isEqualTo(0);
|
82 | 68 | assertThat(txManager1.rollbacks).isEqualTo(1);
|
| 69 | + |
| 70 | + assertThat(txManager2.begun).isEqualTo(0); |
| 71 | + assertThat(txManager2.inflight).isEqualTo(0); |
| 72 | + assertThat(txManager2.commits).isEqualTo(0); |
| 73 | + assertThat(txManager2.rollbacks).isEqualTo(0); |
| 74 | + } |
| 75 | + |
| 76 | + |
| 77 | + @Configuration |
| 78 | + static class Config { |
| 79 | + |
| 80 | + @Bean |
| 81 | + PlatformTransactionManager txManager1() { |
| 82 | + return new CallCountingTransactionManager(); |
| 83 | + } |
| 84 | + |
| 85 | + @Bean |
| 86 | + PlatformTransactionManager txManager2() { |
| 87 | + return new CallCountingTransactionManager(); |
| 88 | + } |
| 89 | + |
83 | 90 | }
|
84 | 91 |
|
85 | 92 | }
|
0 commit comments