mirror of
				https://github.com/suyiiyii/SIMS.git
				synced 2025-11-04 15:54:52 +08:00 
			
		
		
		
	在测试中mock S3Client,避免报错
This commit is contained in:
		
							parent
							
								
									b9ca333958
								
							
						
					
					
						commit
						d353304f3a
					
				
							
								
								
									
										6
									
								
								pom.xml
									
									
									
									
									
								
							
							
						
						
									
										6
									
								
								pom.xml
									
									
									
									
									
								
							@ -117,6 +117,12 @@
 | 
				
			|||||||
            <artifactId>commons-io</artifactId>
 | 
					            <artifactId>commons-io</artifactId>
 | 
				
			||||||
            <version>2.11.0</version>
 | 
					            <version>2.11.0</version>
 | 
				
			||||||
        </dependency>
 | 
					        </dependency>
 | 
				
			||||||
 | 
					        <dependency>
 | 
				
			||||||
 | 
					            <groupId>org.mockito</groupId>
 | 
				
			||||||
 | 
					            <artifactId>mockito-core</artifactId>
 | 
				
			||||||
 | 
					            <version>4.0.0</version>
 | 
				
			||||||
 | 
					            <scope>test</scope>
 | 
				
			||||||
 | 
					        </dependency>
 | 
				
			||||||
    </dependencies>
 | 
					    </dependencies>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    <build>
 | 
					    <build>
 | 
				
			||||||
 | 
				
			|||||||
@ -25,6 +25,3 @@ S3:
 | 
				
			|||||||
  BUCKET: ${S3_BUCKET}
 | 
					  BUCKET: ${S3_BUCKET}
 | 
				
			||||||
  ACCESS_KEY: ${S3_ACCESS_KEY}
 | 
					  ACCESS_KEY: ${S3_ACCESS_KEY}
 | 
				
			||||||
  SECRET_KEY: ${S3_SECRET_KEY}
 | 
					  SECRET_KEY: ${S3_SECRET_KEY}
 | 
				
			||||||
 | 
					 | 
				
			||||||
springdoc:
 | 
					 | 
				
			||||||
  default-support-form-data: true
 | 
					 | 
				
			||||||
@ -1,10 +1,14 @@
 | 
				
			|||||||
package top.suyiiyii.sims.service;
 | 
					package top.suyiiyii.sims.service;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import org.junit.jupiter.api.Test;
 | 
					import org.junit.jupiter.api.Test;
 | 
				
			||||||
 | 
					import org.junit.jupiter.api.extension.ExtendWith;
 | 
				
			||||||
 | 
					import org.mockito.junit.jupiter.MockitoExtension;
 | 
				
			||||||
import org.springframework.beans.factory.annotation.Autowired;
 | 
					import org.springframework.beans.factory.annotation.Autowired;
 | 
				
			||||||
import org.springframework.boot.test.context.SpringBootTest;
 | 
					import org.springframework.boot.test.context.SpringBootTest;
 | 
				
			||||||
 | 
					import org.springframework.boot.test.mock.mockito.MockBean;
 | 
				
			||||||
import org.springframework.test.context.ActiveProfiles;
 | 
					import org.springframework.test.context.ActiveProfiles;
 | 
				
			||||||
import top.suyiiyii.sims.entity.Role;
 | 
					import top.suyiiyii.sims.entity.Role;
 | 
				
			||||||
 | 
					import top.suyiiyii.sims.utils.S3Client;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import java.util.List;
 | 
					import java.util.List;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -12,11 +16,15 @@ import static org.junit.jupiter.api.Assertions.*;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
@SpringBootTest
 | 
					@SpringBootTest
 | 
				
			||||||
@ActiveProfiles("test")
 | 
					@ActiveProfiles("test")
 | 
				
			||||||
 | 
					@ExtendWith(MockitoExtension.class)
 | 
				
			||||||
class RbacServiceTest {
 | 
					class RbacServiceTest {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Autowired
 | 
					    @Autowired
 | 
				
			||||||
    private RbacService rbacService;
 | 
					    private RbacService rbacService;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @MockBean
 | 
				
			||||||
 | 
					    private S3Client s3Client;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Test
 | 
					    @Test
 | 
				
			||||||
    void addRoleWithUserId() {
 | 
					    void addRoleWithUserId() {
 | 
				
			||||||
        int userId = 1; // mock userId
 | 
					        int userId = 1; // mock userId
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user