Код: Выделить всё
package __6__240703.test.user_repository;
import static org.mockito.Mockito.*;
import static org.junit.jupiter.api.Assertions.*;
import __6__240703.main.user_repository.User;
import __6__240703.main.user_repository.UserRepository;
import __6__240703.main.user_repository.UserService;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.util.Optional;
public class UserServiceIntegrationTest {
private UserRepository userRepository;
private UserService userService;
@BeforeEach
public void setUp() {
userRepository = mock(UserRepository.class);
userService = new UserService(userRepository);
}
@Test
public void testGetUserById() {
User user = new User("1", "John Doe");
when(userRepository.findById("1")).thenReturn(Optional.of(user));
User result = userService.getUserById("1");
assertNotNull(result);
assertEquals("John Doe", result.getName());
}
@Test
public void testCreateUser() {
User user = new User("2", "Jane Doe");
userService.createUser(user);
verify(userRepository, times(1)).save(user);
}
}
Код: Выделить всё
java.lang.IllegalStateException: Could not initialize plugin: interface org.mockito.plugins.MockMaker (alternate: n u l l ) < b r / > < b r / > a t o r g . m o c k i t o . i n t e r n a l . c o n f i g u r a t i o n . p l u g i n s . P l u g i n L o a d e r $ 1 . i n v o k e ( P l u g i n L o a d e r . j a v a : 8 4 ) < b r / > a t j d k . p r o x y 2 / j d k . p r o x y 2 . $ P r o x y 1 0 . i s T y p e M o c k a b l e ( U n k n o w n S o u r c e ) < b r / > a t o r g . m o c k i t o . i n t e r n a l . u t i l . M o c k U t i l . t y p e M o c k a b i l i t y O f ( M o c k U t i l . j a v a : 7 8 ) < b r / > a t o r g . m o c k i t o . i n t e r n a l . u t i l . M o c k C r e a t i o n V a l i d a t o r . v a l i d a t e T y p e ( M o c k C r e a t i o n V a l i d a t o r . j a v a : 2 2 ) < b r / > a t o r g . m o c k i t o . i n t e r n a l . c r e a t i o n . M o c k S e t t i n g s I m p l . v a l i d a t e d S e t t i n g s ( M o c k S e t t i n g s I m p l . j a v a : 2 7 4 ) < b r / > a t o r g . m o c k i t o . i n t e r n a l . c r e a t i o n . M o c k S e t t i n g s I m p l . b u i l d ( M o c k S e t t i n g s I m p l . j a v a : 2 3 5 ) < b r / > a t o r g . m o c k i t o . i n t e r n a l . M o c k i t o C o r e . m o c k ( M o c k i t o C o r e . j a v a : 8 6 ) < b r / > a t o r g . m o c k i t o . M o c k i t o . m o c k ( M o c k i t o . j a v a : 2 1 0 1 ) < b r / > a t o r g . m o c k i t o . M o c k i t o . m o c k ( M o c k i t o . j a v a : 2 0 1 6 ) < b r / > a t _ _ 6 _ _ 2 4 0 7 0 3 . t e s t . u s e r _ r e p o s i t o r y . U s e r S e r v i c e I n t e g r a t i o n T e s t . s e t U p ( U s e r S e r v i c e I n t e g r a t i o n T e s t . j a v a : 1 9 ) < b r / > a t j a v a . b a s e / j d k . i n t e r n a l . r e f l e c t . N a t i v e M e t h o d A c c e s s o r I m p l . i n v o k e 0 ( N a t i v e M e t h o d ) < b r / > a t j a v a . b a s e / j d k . i n t e r n a l . r e f l e c t . N a t i v e M e t h o d A c c e s s o r I m p l . i n v o k e ( N a t i v e M e t h o d A c c e s s o r I m p l . j a v a : 7 7 ) < b r / > a t j a v a . b a s e / j d k . i n t e r n a l . r e f l e c t . D e l e g a t i n g M e t h o d A c c e s s o r I m p l . i n v o k e ( D e l e g a t i n g M e t h o d A c c e s s o r I m p l . j a v a : 4 3 ) < b r / > a t j a v a . b a s e / j a v a . l a n g . r e f l e c t . M e t h o d . i n v o k e ( M e t h o d . j a v a : 5 6 8 ) < b r / > a t o r g . j u n i t . p l a t f o r m . c o m m o n s . u t i l . R e f l e c t i o n U t i l s . i n v o k e M e t h o d ( R e f l e c t i o n U t i l s . j a v a : 7 2 7 ) < b r / > a t o r g . j u n i t . j u p i t e r . e n g i n e . e x e c u t i o n . M e t h o d I n v o c a t i o n . p r o c e e d ( M e t h o d I n v o c a t i o n . j a v a : 6 0 ) < b r / > a t o r g . j u n i t . j u p i t e r . e n g i n e . e x e c u t i o n . I n v o c a t i o n I n t e r c e p t o r C h a i n $ V a l i d a t i n g I n v o c a t i o n . p r o c e e d ( I n v o c a t i o n I n t e r c e p t o r C h a i n . j a v a : 1 3 1 ) < b r / > a t o r g . j u n i t . j u p i t e r . e n g i n e . e x t e n s i o n . T i m e o u t E x t e n s i o n . i n t e r c e p t ( T i m e o u t E x t e n s i o n . j a v a : 1 5 6 ) < b r / > a t o r g . j u n i t . j u p i t e r . e n g i n e . e x t e n s i o n . T i m e o u t E x t e n s i o n . i n t e r c e p t L i f e c y c l e M e t h o d ( T i m e o u t E x t e n s i o n . j a v a : 1 2 8 ) < b r / > a t o r g . j u n i t . j u p i t e r . e n g i n e . e x t e n s i o n . T i m e o u t E x t e n s i o n . i n t e r c e p t B e f o r e E a c h M e t h o d ( T i m e o u t E x t e n s i o n . j a v a : 7 8 ) < b r / > a t o r g . j u n i t . j u p i t e r . e n g i n e . e x e c u t i o n . I n t e r c e p t i n g E x e c u t a b l e I n v o k e r $ R e f l e c t i v e I n t e r c e p t o r C a l l . l a m b d a $ o f V o i d M e t h o d $ 0 ( I n t e r c e p t i n g E x e c u t a b l e I n v o k e r . j a v a : 1 0 3 ) < b r / > a t o r g . j u n i t . j u p i t e r . e n g i n e . e x e c u t i o n . I n t e r c e p t i n g E x e c u t a b l e I n v o k e r . l a m b d a $ i n v o k e $ 0 ( I n t e r c e p t i n g E x e c u t a b l e I n v o k e r . j a v a : 9 3 ) < b r / > a t o r g . j u n i t . j u p i t e r . e n g i n e . e x e c u t i o n . I n v o c a t i o n I n t e r c e p t o r C h a i n $ I n t e r c e p t e d I n v o c a t i o n . p r o c e e d ( I n v o c a t i o n I n t e r c e p t o r C h a i n . j a v a : 1 0 6 ) < b r / > a t o r g . j u n i t . j u p i t e r . e n g i n e . e x e c u t i o n . I n v o c a t i o n I n t e r c e p t o r C h a i n . p r o c e e d ( I n v o c a t i o n I n t e r c e p t o r C h a i n . j a v a : 6 4 ) < b r / > a t o r g . j u n i t . j u p i t e r . e n g i n e . e x e c u t i o n . I n v o c a t i o n I n t e r c e p t o r C h a i n . c h a i n A n d I n v o k e ( I n v o c a t i o n I n t e r c e p t o r C h a i n . j a v a : 4 5 ) < b r / > a t o r g . j u n i t . j u p i t e r . e n g i n e . e x e c u t i o n . I n v o c a t i o n I n t e r c e p t o r C h a i n . i n v o k e ( I n v o c a t i o n I n t e r c e p t o r C h a i n . j a v a : 3 7 ) < b r / > a t o r g . j u n i t . j u p i t e r . e n g i n e . e x e c u t i o n . I n t e r c e p t i n g E x e c u t a b l e I n v o k e r . i n v o k e ( I n t e r c e p t i n g E x e c u t a b l e I n v o k e r . j a v a : 9 2 ) < b r / > a t o r g . j u n i t . j u p i t e r . e n g i n e . e x e c u t i o n . I n t e r c e p t i n g E x e c u t a b l e I n v o k e r . i n v o k e ( I n t e r c e p t i n g E x e c u t a b l e I n v o k e r . j a v a : 8 6 ) < b r / > a t o r g . j u n i t . j u p i t e r . e n g i n e . d e s c r i p t o r . C l a s s B a s e d T e s t D e s c r i p t o r . i n v o k e M e t h o d I n E x t e n s i o n C o n t e x t ( C l a s s B a s e d T e s t D e s c r i p t o r . j a v a : 5 2 0 ) < b r / > a t o r g . j u n i t . j u p i t e r . e n g i n e . d e s c r i p t o r . C l a s s B a s e d T e s t D e s c r i p t o r . l a m b d a $ s y n t h e s i z e B e f o r e E a c h M e t h o d A d a p t e r $ 2 3 ( C l a s s B a s e d T e s t D e s c r i p t o r . j a v a : 5 0 5 ) < b r / > a t o r g . j u n i t . j u p i t e r . e n g i n e . d e s c r i p t o r . T e s t M e t h o d T e s t D e s c r i p t o r . l a m b d a $ i n v o k e B e f o r e E a c h M e t h o d s $ 3 ( T e s t M e t h o d T e s t D e s c r i p t o r . j a v a : 1 7 4 ) < b r / > a t o r g . j u n i t . j u p i t e r . e n g i n e . d e s c r i p t o r . T e s t M e t h o d T e s t D e s c r i p t o r . l a m b d a $ i n v o k e B e f o r e M e t h o d s O r C a l l b a c k s U n t i l E x c e p t i o n O c c u r s $ 6 ( T e s t M e t h o d T e s t D e s c r i p t o r . j a v a : 2 0 2 ) < b r / > a t o r g . j u n i t . p l a t f o r m . e n g i n e . s u p p o r t . h i e r a r c h i c a l . T h r o w a b l e C o l l e c t o r . e x e c u t e ( T h r o w a b l e C o l l e c t o r . j a v a : 7 3 ) < b r / > a t o r g . j u n i t . j u p i t e r . e n g i n e . d e s c r i p t o r . T e s t M e t h o d T e s t D e s c r i p t o r . i n v o k e B e f o r e M e t h o d s O r C a l l b a c k s U n t i l E x c e p t i o n O c c u r s ( T e s t M e t h o d T e s t D e s c r i p t o r . j a v a : 2 0 2 ) < b r / > a t o r g . j u n i t . j u p i t e r . e n g i n e . d e s c r i p t o r . T e s t M e t h o d T e s t D e s c r i p t o r . i n v o k e B e f o r e E a c h M e t h o d s ( T e s t M e t h o d T e s t D e s c r i p t o r . j a v a : 1 7 1 ) < b r / > a t o r g . j u n i t . j u p i t e r . e n g i n e . d e s c r i p t o r . T e s t M e t h o d T e s t D e s c r i p t o r . e x e c u t e ( T e s t M e t h o d T e s t D e s c r i p t o r . j a v a : 1 3 4 ) < b r / > a t o r g . j u n i t . j u p i t e r . e n g i n e . d e s c r i p t o r . T e s t M e t h o d T e s t D e s c r i p t o r . e x e c u t e ( T e s t M e t h o d T e s t D e s c r i p t o r . j a v a : 6 8 ) < b r / > a t o r g . j u n i t . p l a t f o r m . e n g i n e . s u p p o r t . h i e r a r c h i c a l . N o d e T e s t T a s k . l a m b d a $ e x e c u t e R e c u r s i v e l y $ 6 ( N o d e T e s t T a s k . j a v a : 1 5 1 ) < b r / > a t o r g . j u n i t . p l a t f o r m . e n g i n e . s u p p o r t . h i e r a r c h i c a l . T h r o w a b l e C o l l e c t o r . e x e c u t e ( T h r o w a b l e C o l l e c t o r . j a v a : 7 3 ) < b r / > a t o r g . j u n i t . p l a t f o r m . e n g i n e . s u p p o r t . h i e r a r c h i c a l . N o d e T e s tTask.lambda$executeRecursively$8(NodeTestTask.java:141)
at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:41)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:155)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)
at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:41)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:155)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)
at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit(SameThreadHierarchicalTestExecutorService.java:35)
at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:57)
at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:54)
at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:147)
at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:127)
at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:90)
at org.junit.platform.launcher.core.EngineExecutionOrchestrator.lambda$execute$0(EngineExecutionOrchestrator.java:55)
at org.junit.platform.launcher.core.EngineExecutionOrchestrator.withInterceptedStreams(EngineExecutionOrchestrator.java:102)
at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:54)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:114)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:86)
at org.junit.platform.launcher.core.DefaultLauncherSession$DelegatingLauncher.execute(DefaultLauncherSession.java:86)
at org.junit.platform.launcher.core.SessionPerRequestLauncher.execute(SessionPerRequestLauncher.java:53)
at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:57)
at com.intellij.rt.junit.IdeaTestRunner$Repeater$1.execute(IdeaTestRunner.java:38)
at com.intellij.rt.execution.junit.TestsRepeater.repeat(TestsRepeater.java:11)
at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:35)
at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:232)
at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:55)
Caused by: java.lang.IllegalStateException: Internal problem occurred, please report it. Mockito is unable to load the default implementation of class that is a part of Mockito distribution. Failed to load interface org.mockito.plugins.MockMaker
at org.mockito.internal.configuration.plugins.DefaultMockitoPlugins.create(DefaultMockitoPlugins.java:104)
at org.mockito.internal.configuration.plugins.DefaultMockitoPlugins.getDefaultPlugin(DefaultMockitoPlugins.java:78)
at org.mockito.internal.configuration.plugins.PluginLoader.loadPlugin(PluginLoader.java:75)
at org.mockito.internal.configuration.plugins.PluginLoader.loadPlugin(PluginLoader.java:50)
at org.mockito.internal.configuration.plugins.PluginRegistry.(PluginRegistry.java:27)
at org.mockito.internal.configuration.plugins.Plugins.(Plugins.java:22)
at org.mockito.internal.MockitoCore.(MockitoCore.java:73)
at org.mockito.Mockito.(Mockito.java:1683)
... 75 more
Caused by: java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:480)
at org.mockito.internal.configuration.plugins.DefaultMockitoPlugins.create(DefaultMockitoPlugins.java:102)
... 82 more
Caused by: org.mockito.exceptions.base.MockitoInitializationException:
Could not initialize inline Byte Buddy mock maker.
введите здесь описание изображения
Я пробовал использовать jdk21 и jdk17. Я также пытался использовать параметры виртуальной машины «-XX:+EnableDynamicAgentLoading -Djdk.attach.allowAttachSelf=true», но безуспешно.
Я также пытался использовать строку «mock-maker-inline». в файле «resources.mockito-extensions.org.mockito.plugins.MockMaker» безуспешно.
Подробнее здесь: https://stackoverflow.com/questions/786 ... ker-plugin