-
Notifications
You must be signed in to change notification settings - Fork 0
/
JWFileChooserBug34.java
132 lines (114 loc) · 4.21 KB
/
JWFileChooserBug34.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/*
* Copyright © 2020 Mark Raynsford <code@io7m.com> http://io7m.com
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
* IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
package com.io7m.jwheatsheaf.tests;
import com.io7m.jwheatsheaf.api.JWFileChooserAction;
import com.io7m.jwheatsheaf.api.JWFileChooserConfiguration;
import com.io7m.jwheatsheaf.api.JWFileChooserEventType;
import com.io7m.jwheatsheaf.api.JWFileChooserType;
import com.io7m.jwheatsheaf.api.JWFileChoosersType;
import com.io7m.jwheatsheaf.ui.JWFileChoosers;
import javafx.scene.input.KeyCode;
import javafx.stage.Stage;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInfo;
import org.junit.jupiter.api.extension.ExtendWith;
import org.testfx.api.FxAssert;
import org.testfx.api.FxRobot;
import org.testfx.framework.junit5.ApplicationExtension;
import org.testfx.framework.junit5.Start;
import org.testfx.framework.junit5.Stop;
import org.testfx.matcher.base.NodeMatchers;
import java.io.IOException;
import java.nio.file.FileSystem;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
@ExtendWith(ApplicationExtension.class)
public final class JWFileChooserBug34
{
private JWTestFilesystems filesystems;
private FileSystem dosFilesystem;
private JWFileChooserType chooser;
private List<JWFileChooserEventType> events;
private JWFileChoosersType choosers;
@Start
public void start(final Stage stage)
throws Exception
{
this.events = Collections.synchronizedList(new ArrayList<>());
this.filesystems = JWTestFilesystems.create();
final var systems = this.filesystems.filesystems();
this.dosFilesystem = systems.get("ExampleDOS");
final var configuration =
JWFileChooserConfiguration.builder()
.setAction(JWFileChooserAction.CREATE)
.setFileSystem(this.dosFilesystem)
.setFileSelectionMode(path -> {
return Boolean.valueOf(Files.isRegularFile(path));
})
.build();
this.choosers = JWFileChoosers.create();
this.chooser = this.choosers.create(stage, configuration);
this.chooser.setEventListener(event -> this.events.add(event));
this.chooser.show();
}
@Stop
public void stop()
throws IOException
{
this.choosers.close();
this.chooser.cancel();
}
/**
* In CREATE mode, specifying a nonexistent file if using a filter that
* checks if files are regular files, does not silently fail when the user
* clicks OK.
*
* @param robot The FX test robot
*/
@Test
public void test_NameField_NonexistentFileDoesNotSilentlyFail(
final FxRobot robot,
final TestInfo info)
{
JWFileWindowTitles.setTitle(this.chooser, info);
final var delegate = new JWRobotDelegate(robot);
final var okButton =
robot.lookup("#fileChooserOKButton")
.queryButton();
robot.clickOn("#fileChooserNameField");
FxAssert.verifyThat(okButton, NodeMatchers.isDisabled());
robot.write("THIS_DOES_NOT_EXIST.TXT");
delegate.pauseBriefly();
FxAssert.verifyThat(okButton, NodeMatchers.isEnabled());
robot.type(KeyCode.ENTER);
FxAssert.verifyThat(okButton, NodeMatchers.isEnabled());
FxAssert.verifyThat(okButton, NodeMatchers.isEnabled());
robot.clickOn(okButton);
Assertions.assertEquals(
List.of("Z:\\USERS\\GROUCH\\THIS_DOES_NOT_EXIST.TXT"),
this.chooser.result()
.stream()
.map(Path::toString)
.collect(Collectors.toList())
);
Assertions.assertEquals(0, this.events.size());
}
}