github-code-scanning[bot] commented on code in PR #12337:
URL: https://github.com/apache/dolphinscheduler/pull/12337#discussion_r993402443
##########
dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/utils/FileUtilsTest.java:
##########
@@ -62,52 +56,53 @@
@Test
public void testCopyFile() throws IOException {
- //Define dest file path
+ // Define dest file path
String src = rootPath + System.getProperty("file.separator") +
"src.txt";
String destFilename = rootPath + System.getProperty("file.separator")
+ "data.txt";
- logger.info("destFilename: "+destFilename);
+ logger.info("destFilename: " + destFilename);
- //Define InputStream for MultipartFile
+ // Define InputStream for MultipartFile
String data = "data text";
org.apache.commons.io.FileUtils.writeStringToFile(new File(src), data);
- //Use Mockito to mock MultipartFile
+ // Use Mockito to mock MultipartFile
MultipartFile file = Mockito.mock(MultipartFile.class,
Mockito.RETURNS_DEEP_STUBS);
Mockito.when(file.getInputStream()).thenReturn(new
FileInputStream(src));
- //Invoke copyFile
- FileUtils.copyInputStreamToFile(file,destFilename);
+ // Invoke copyFile
+ FileUtils.copyInputStreamToFile(file, destFilename);
- //Test file exists
+ // Test file exists
File destFile = new File(destFilename);
- assertTrue(destFile.exists());
+ Assertions.assertTrue(destFile.exists());
}
@Test
public void testFile2Resource() throws IOException {
- //Define dest file path
- String destFilename = rootPath + System.getProperty("file.separator")
+ "data.txt";
- logger.info("destFilename: "+destFilename);
+ // Define dest file path
+ String destFilename = rootPath + System.getProperty("file.separator")
+ "resource.txt";
+ logger.info("destFilename: " + destFilename);
- //Define test resource
- File file = folder.newFile("resource.txt");
+ // Define test resource
+ File file = new File(destFilename);
+ org.apache.commons.io.FileUtils.writeStringToFile(file, "test data");
Review Comment:
## Deprecated method or constructor invocation
Invoking [FileUtils.writeStringToFile](1) should be avoided because it has
been deprecated.
[Show more
details](https://github.com/apache/dolphinscheduler/security/code-scanning/1769)
##########
dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/utils/FileUtilsTest.java:
##########
@@ -62,52 +56,53 @@
@Test
public void testCopyFile() throws IOException {
- //Define dest file path
+ // Define dest file path
String src = rootPath + System.getProperty("file.separator") +
"src.txt";
String destFilename = rootPath + System.getProperty("file.separator")
+ "data.txt";
- logger.info("destFilename: "+destFilename);
+ logger.info("destFilename: " + destFilename);
- //Define InputStream for MultipartFile
+ // Define InputStream for MultipartFile
String data = "data text";
org.apache.commons.io.FileUtils.writeStringToFile(new File(src), data);
- //Use Mockito to mock MultipartFile
+ // Use Mockito to mock MultipartFile
MultipartFile file = Mockito.mock(MultipartFile.class,
Mockito.RETURNS_DEEP_STUBS);
Mockito.when(file.getInputStream()).thenReturn(new
FileInputStream(src));
- //Invoke copyFile
- FileUtils.copyInputStreamToFile(file,destFilename);
+ // Invoke copyFile
+ FileUtils.copyInputStreamToFile(file, destFilename);
- //Test file exists
+ // Test file exists
File destFile = new File(destFilename);
- assertTrue(destFile.exists());
+ Assertions.assertTrue(destFile.exists());
}
@Test
public void testFile2Resource() throws IOException {
- //Define dest file path
- String destFilename = rootPath + System.getProperty("file.separator")
+ "data.txt";
- logger.info("destFilename: "+destFilename);
+ // Define dest file path
+ String destFilename = rootPath + System.getProperty("file.separator")
+ "resource.txt";
+ logger.info("destFilename: " + destFilename);
- //Define test resource
- File file = folder.newFile("resource.txt");
+ // Define test resource
+ File file = new File(destFilename);
+ org.apache.commons.io.FileUtils.writeStringToFile(file, "test data");
- //Invoke file2Resource and test not null
- Resource resource = FileUtils.file2Resource(file.getAbsolutePath());
- assertNotNull(resource);
+ // Invoke file2Resource and test not null
+ Resource resource = FileUtils.file2Resource(file.toString());
+ Assertions.assertNotNull(resource);
- //Invoke file2Resource and test null
- Resource resource1 =
FileUtils.file2Resource(file.getAbsolutePath()+"abc");
- assertNull(resource1);
+ // Invoke file2Resource and test null
+ Resource resource1 = FileUtils.file2Resource(file + "abc");
+ Assertions.assertNull(resource1);
}
@Test
public void testFile2String() throws IOException {
String content = "123";
- org.apache.commons.io.FileUtils.writeStringToFile(new
File("/tmp/task.json"),content);
+ org.apache.commons.io.FileUtils.writeStringToFile(new
File("/tmp/task.json"), content);
Review Comment:
## Deprecated method or constructor invocation
Invoking [FileUtils.writeStringToFile](1) should be avoided because it has
been deprecated.
[Show more
details](https://github.com/apache/dolphinscheduler/security/code-scanning/1770)
##########
dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/permission/ResourcePermissionCheckServiceTest.java:
##########
@@ -57,52 +56,55 @@
private ProjectMapper projectMapper;
@Mock
- private ApplicationContext context;
+ private ApplicationContext context;
@Mock
private ResourcePermissionCheckService<Object>
resourcePermissionCheckService;
@InjectMocks
ResourcePermissionCheckServiceImpl resourcePermissionCheckServices;
- protected static final Map<AuthorizationType,
ResourcePermissionCheckServiceImpl.ResourceAcquisitionAndPermissionCheck<?>>
RESOURCE_LIST_MAP = new ConcurrentHashMap<>();
+ protected static final Map<AuthorizationType,
ResourcePermissionCheckServiceImpl.ResourceAcquisitionAndPermissionCheck<?>>
RESOURCE_LIST_MAP =
+ new ConcurrentHashMap<>();
@Test
- public void testResourcePermissionCheck(){
+ public void testResourcePermissionCheck() {
User user = new User();
user.setId(1);
- Object[] obj = new Object[]{1,2};
- boolean result =
this.resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.PROJECTS,
obj, user.getId(), logger);
- Assert.assertFalse(result);
+ Object[] obj = new Object[]{1, 2};
+ boolean result =
this.resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.PROJECTS,
obj,
+ user.getId(), logger);
+ Assertions.assertFalse(result);
}
@Test
- public void testOperationPermissionCheck(){
+ public void testOperationPermissionCheck() {
User user = new User();
user.setId(1);
resourcePermissionCheckServices.setApplicationContext(context);
-
Assert.assertFalse(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.PROJECTS,
null, user.getId(), null, logger));
+
Assertions.assertFalse(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.PROJECTS,
null,
+ user.getId(), null, logger));
String sourceUrl = "/tmp/";
-
Assert.assertFalse(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.PROJECTS,
null, user.getId(), sourceUrl, logger));
+
Assertions.assertFalse(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.PROJECTS,
null,
+ user.getId(), sourceUrl, logger));
}
@Test
- public void testUserOwnedResourceIdsAcquisition(){
+ public void testUserOwnedResourceIdsAcquisition() {
User user = new User();
user.setId(1);
- //ADMIN
+ // ADMIN
user.setUserType(UserType.ADMIN_USER);
- Object[] obj = new Object[]{1,2};
+ Object[] obj = new Object[]{1, 2};
Review Comment:
## Unread local variable
Variable 'Object\[\] obj' is never read.
[Show more
details](https://github.com/apache/dolphinscheduler/security/code-scanning/1771)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]