/** * Registers a {@link Closeable} resource that should be closed after the test * completes. * * @return <code>resource</code> (for call chaining). */ public <T extends Closeable> T closeAfterTest(T resource) { return getContext().closeAtEnd(resource, LifecycleScope.TEST); }
/** * Registers a {@link Closeable} resource that should be closed after the suite * completes. * * @return <code>resource</code> (for call chaining). */ public static <T extends Closeable> T closeAfterSuite(T resource) { return getContext().closeAtEnd(resource, LifecycleScope.SUITE); }
/** * Registers a {@link Closeable} resource that should be closed after the suite * completes. * * @return <code>resource</code> (for call chaining). */ public static <T extends Closeable> T closeAfterSuite(T resource) { return getContext().closeAtEnd(resource, LifecycleScope.SUITE); }
/** * Registers a {@link Closeable} resource that should be closed after the test * completes. * * @return <code>resource</code> (for call chaining). */ public <T extends Closeable> T closeAfterTest(T resource) { return RandomizedContext.current().closeAtEnd(resource, LifecycleScope.TEST); }
/** * Registers a {@link Closeable} resource that should be closed after the suite * completes. * * @return <code>resource</code> (for call chaining). */ public static <T extends Closeable> T closeAfterSuite(T resource) { return RandomizedContext.current().closeAtEnd(resource, LifecycleScope.SUITE); }
/** * Registers a {@link Closeable} resource that should be closed after the test * completes. * * @return <code>resource</code> (for call chaining). */ public <T extends Closeable> T closeAfterTest(T resource) { return getContext().closeAtEnd(resource, LifecycleScope.TEST); }
/** * Assign a temporary server socket. If you need a temporary port one can * assign a server socket and close it immediately, just to acquire its port * number. * * @param scope * The lifecycle scope to close the socket after. If the socket is * closed earlier, nothing happens (silently dropped). */ public static ServerSocket newServerSocket(LifecycleScope scope) throws IOException { final ServerSocket socket = new ServerSocket(0); getContext().closeAtEnd(new Closeable() { public void close() throws IOException { if (!socket.isClosed()) socket.close(); } }, scope); return socket; }
/** * Assign a temporary server socket. If you need a temporary port one can * assign a server socket and close it immediately, just to acquire its port * number. * * @param scope * The lifecycle scope to close the socket after. If the socket is * closed earlier, nothing happens (silently dropped). */ public static ServerSocket newServerSocket(LifecycleScope scope) throws IOException { final ServerSocket socket = new ServerSocket(0); getContext().closeAtEnd(new Closeable() { public void close() throws IOException { if (!socket.isClosed()) socket.close(); } }, scope); return socket; }
/** * Creates a temporary directory, deleted after the given lifecycle phase. * Temporary directory is created relative to a globally picked temporary directory. */ public static Path newTempDir(LifecycleScope scope) throws IOException { checkContext(); synchronized (RandomizedTest.class) { Path tempDir = globalTempDir().resolve(nextTempName()); Files.createDirectories(tempDir); getContext().closeAtEnd(new TempPathResource(tempDir), scope); return tempDir; } }
/** * Creates a new temporary file deleted after the given lifecycle phase completes. * The file is physically created on disk, but is not locked or opened. */ public static Path newTempFile(LifecycleScope scope) throws IOException { checkContext(); synchronized (RandomizedTest.class) { Path tempFile = globalTempDir().resolve(nextTempName()); Files.createFile(tempFile); getContext().closeAtEnd(new TempPathResource(tempFile), scope); return tempFile; } }
/** * Creates a new temporary file deleted after the given lifecycle phase completes. * The file is physically created on disk, but is not locked or opened. */ public static Path newTempFile(LifecycleScope scope) throws IOException { checkContext(); synchronized (RandomizedTest.class) { Path tempFile = globalTempDir().resolve(nextTempName()); Files.createFile(tempFile); getContext().closeAtEnd(new TempPathResource(tempFile), scope); return tempFile; } }
/** * Creates a temporary directory, deleted after the given lifecycle phase. * Temporary directory is created relative to a globally picked temporary directory. */ public static Path newTempDir(LifecycleScope scope) throws IOException { checkContext(); synchronized (RandomizedTest.class) { Path tempDir = globalTempDir().resolve(nextTempName()); Files.createDirectories(tempDir); getContext().closeAtEnd(new TempPathResource(tempDir), scope); return tempDir; } }