diff --git a/spring-test/src/main/java/org/springframework/test/context/transaction/TestContextTransactionUtils.java b/spring-test/src/main/java/org/springframework/test/context/transaction/TestContextTransactionUtils.java index b67154371b..d00370dcf3 100644 --- a/spring-test/src/main/java/org/springframework/test/context/transaction/TestContextTransactionUtils.java +++ b/spring-test/src/main/java/org/springframework/test/context/transaction/TestContextTransactionUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -205,13 +205,10 @@ public abstract class TestContextTransactionUtils { "Only one TransactionManagementConfigurer may exist in the ApplicationContext"); if (configurers.size() == 1) { TransactionManager tm = configurers.values().iterator().next().annotationDrivenTransactionManager(); - if (tm instanceof PlatformTransactionManager) { - return (PlatformTransactionManager) tm; - } - else { - throw new IllegalStateException( - "Specified transaction manager is not a PlatformTransactionManager: " + tm); - } + Assert.state(tm instanceof PlatformTransactionManager, () -> + "Transaction manager specified via TransactionManagementConfigurer " + + "is not a PlatformTransactionManager: " + tm); + return (PlatformTransactionManager) tm; } }