Skip to content

Commit 98d0272

Browse files
Implementing code review feedback from claude.
1 parent 438d0b1 commit 98d0272

2 files changed

Lines changed: 10 additions & 21 deletions

File tree

src/org/labkey/test/TestFileUtils.java

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -451,30 +451,21 @@ public static void deleteDir(File dir)
451451
* @param sourceDir the directory to rename
452452
* @param newDirName the new name for the directory
453453
*/
454-
public static void renameDir(Path sourceDir, String newDirName)
454+
public static void renameDir(Path sourceDir, String newDirName) throws IOException
455455
{
456456
LOG.info("Renaming {} to {}", sourceDir, newDirName);
457457

458458
// Check if the directory is outside the test enlistment.
459459
checkFileLocation(sourceDir.toFile());
460460

461-
Assert.assertTrue(sourceDir + " does not exists.", sourceDir.toFile().exists());
461+
Assert.assertTrue("Directory does not exist: " + sourceDir, sourceDir.toFile().exists());
462462

463-
try
464-
{
465-
// Get the separator appropriate for the given OS.
466-
String separator = File.separator;
467-
int lastIndex = sourceDir.toString().lastIndexOf(separator);
468-
Path newDir = lastIndex <= 0 ?
469-
Paths.get(separator + newDirName) :
470-
Paths.get(sourceDir.toString().substring(0, lastIndex) + separator + newDirName);
471-
Files.move(sourceDir, newDir);
472-
LOG.info("Rename successful.");
473-
}
474-
catch (IOException e)
475-
{
476-
LOG.info("WARNING: Exception renaming directory -- " + e.getMessage());
477-
}
463+
Path newDir = sourceDir.getParent() != null
464+
? sourceDir.getParent().resolve(newDirName)
465+
: Paths.get(newDirName);
466+
Files.move(sourceDir, newDir);
467+
468+
LOG.info("Rename successful.");
478469
}
479470

480471
private static void checkFileLocation(File file)

src/org/labkey/test/tests/assay/AssayTransformMissingParentDirTest.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package org.labkey.test.tests.assay;
22

33
import org.apache.commons.io.FileUtils;
4-
import org.apache.commons.lang3.SystemUtils;
54
import org.junit.Assert;
65
import org.junit.Test;
76
import org.junit.experimental.categories.Category;
@@ -19,8 +18,7 @@
1918
import java.io.File;
2019
import java.nio.file.Files;
2120
import java.nio.file.Path;
22-
import java.nio.file.Paths;
23-
import java.time.Instant;
21+
import java.util.UUID;
2422

2523
/**
2624
* Issue 54156: Regression test to ensure a reasonable error message is shown when an assay design references
@@ -53,7 +51,7 @@ public void testMissingParentDirectoryRegression() throws Exception
5351

5452
// Now rename the parent dir to ensure we handle it reasonably. Deleting directories on Windows is not always
5553
// timely, renaming the directory will have the same effect.
56-
String newName = "Not-Here-" + Instant.now().getEpochSecond();
54+
String newName = "Not-Here-" + UUID.randomUUID();
5755
TestFileUtils.renameDir(parentDir, newName);
5856

5957
Assert.assertFalse(String.format("Directory %s is still present.", parentDir),

0 commit comments

Comments
 (0)