Skip to content

Commit

Permalink
Cleanup configFile after enabledAtSignExpansionTest
Browse files Browse the repository at this point in the history
  • Loading branch information
mkarg committed Aug 11, 2024
1 parent 5bdb3f5 commit c95ca94
Showing 1 changed file with 20 additions and 17 deletions.
37 changes: 20 additions & 17 deletions src/test/java/com/beust/jcommander/JCommanderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
Expand Down Expand Up @@ -1059,26 +1058,30 @@ class Params {

@Test
public void enabledAtSignExpansionTest() throws IOException {
Files.writeString(Paths.get("configFile"), "-fromFile");

class Params {
@Parameter(names = {"-username"})
protected String username;
final var configFile = Files.createTempFile(null, null);
Files.writeString(configFile, "-fromFile");
try {
class Params {
@Parameter(names = {"-username"})
protected String username;

@Parameter(names = "-fromFile")
protected boolean fromFile;
@Parameter(names = "-fromFile")
protected boolean fromFile;

@Parameter(names = "-pastAt")
protected String pastAt;
}
@Parameter(names = "-pastAt")
protected String pastAt;
}

Params params = new Params();
Params params = new Params();

JCommander jc = new JCommander(params);
jc.parse("-username", "@tzellman", "@configFile", "-pastAt", "moreValues");
Assert.assertEquals(params.username, "@tzellman");
Assert.assertTrue(params.fromFile);
Assert.assertEquals(params.pastAt, "moreValues");
JCommander jc = new JCommander(params);
jc.parse("-username", "@tzellman", "@" + configFile, "-pastAt", "moreValues");
Assert.assertEquals(params.username, "@tzellman");
Assert.assertTrue(params.fromFile);
Assert.assertEquals(params.pastAt, "moreValues");
} finally {
Files.deleteIfExists(configFile);
}
}

public void parameterWithOneDoubleQuote() {
Expand Down

0 comments on commit c95ca94

Please sign in to comment.