File tree 2 files changed +10
-7
lines changed
log4j-to-slf4j/src/test/java/org/apache/logging/slf4j
2 files changed +10
-7
lines changed Original file line number Diff line number Diff line change 26
26
import org .apache .logging .log4j .spi .ThreadContextMap ;
27
27
import org .junit .jupiter .api .Test ;
28
28
import org .junitpioneer .jupiter .Issue ;
29
- import org .slf4j .MDCTestHelper ;
30
29
import org .slf4j .spi .MDCAdapter ;
31
30
32
31
class MDCContextMapTest {
33
32
34
33
@ Test
35
34
@ Issue ("https://github.com/apache/logging-log4j2/issues/1426" )
36
- void nonNullGetCopy () {
35
+ void nonNullGetCopy () throws Exception {
37
36
final ThreadContextMap contextMap = new MDCContextMap ();
38
37
final MDCAdapter mockAdapter = mock (MDCAdapter .class );
39
38
when (mockAdapter .getCopyOfContextMap ()).thenReturn (null );
Original file line number Diff line number Diff line change 14
14
* See the License for the specific language governing permissions and
15
15
* limitations under the License.
16
16
*/
17
- package org .slf4j ;
17
+ package org .apache . logging . slf4j ;
18
18
19
+ import java .lang .reflect .Field ;
20
+ import org .slf4j .MDC ;
19
21
import org .slf4j .spi .MDCAdapter ;
20
22
21
- public class MDCTestHelper {
23
+ class MDCTestHelper {
22
24
23
- public static MDCAdapter replaceMDCAdapter (final MDCAdapter adapter ) {
24
- final MDCAdapter old = MDC .mdcAdapter ;
25
- MDC .mdcAdapter = adapter ;
25
+ static MDCAdapter replaceMDCAdapter (final MDCAdapter adapter ) throws Exception {
26
+ Field mdcAdapterField = MDC .class .getDeclaredField ("MDC_ADAPTER" );
27
+ mdcAdapterField .setAccessible (true );
28
+ final MDCAdapter old = (MDCAdapter ) mdcAdapterField .get (null );
29
+ mdcAdapterField .set (null , adapter );
26
30
return old ;
27
31
}
28
32
}
You can’t perform that action at this time.
0 commit comments