Skip to content

Commit f426323

Browse files
SnipxiText-CI
authored andcommitted
Allow overriding test timeout for classes extending from ITextTest
Inheritance is not taken into account for Junit @timeout rules. This means that if several @timeout rules are present in the class inheritance chain, and even if timeout is specified as an attribute of the @test annotation, the minimal timeout would be decisive. This fix allows classes extending from ITextTest setting bigger timeout for tests. Previously it was only possible to make timeout smaller due to the fact described above. See also junit-team/junit4#1126
1 parent 11789c5 commit f426323

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

pdftest/src/main/java/com/itextpdf/test/ITextTest.java

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public abstract class ITextTest {
6666
protected final Logger LOGGER = LoggerFactory.getLogger(getClass());
6767

6868
@Rule
69-
public Timeout testTimeout = new Timeout(5, TimeUnit.MINUTES);
69+
public Timeout testTimeout = getTestTimeout();
7070

7171
/**
7272
* Creates a folder with a given path, including all necessary nonexistent parent directories.
@@ -151,21 +151,8 @@ public static void restoreCryptographyRestrictions() {
151151
}
152152
}
153153

154-
private static void deleteDirectoryContents(String path, boolean removeParentDirectory) {
155-
File file = new File(path);
156-
if (file.exists() && file.listFiles() != null) {
157-
for (File f : file.listFiles()) {
158-
if (f.isDirectory()) {
159-
deleteDirectoryContents(f.getPath(), false);
160-
f.delete();
161-
} else {
162-
f.delete();
163-
}
164-
}
165-
if (removeParentDirectory) {
166-
file.delete();
167-
}
168-
}
154+
protected Timeout getTestTimeout() {
155+
return new Timeout(5, TimeUnit.MINUTES);
169156
}
170157

171158
protected byte[] readFile(String filename) throws IOException {
@@ -191,4 +178,21 @@ protected String createStringByEscaped(byte[] bytes) {
191178
return buf.toString();
192179
}
193180

181+
private static void deleteDirectoryContents(String path, boolean removeParentDirectory) {
182+
File file = new File(path);
183+
if (file.exists() && file.listFiles() != null) {
184+
for (File f : file.listFiles()) {
185+
if (f.isDirectory()) {
186+
deleteDirectoryContents(f.getPath(), false);
187+
f.delete();
188+
} else {
189+
f.delete();
190+
}
191+
}
192+
if (removeParentDirectory) {
193+
file.delete();
194+
}
195+
}
196+
}
197+
194198
}

0 commit comments

Comments
 (0)