Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can it use cactoos.TempFile? #1133

Open
Masynchin opened this issue Jul 11, 2022 · 2 comments
Open

Can it use cactoos.TempFile? #1133

Masynchin opened this issue Jul 11, 2022 · 2 comments

Comments

@Masynchin
Copy link
Contributor

I am trying to rewrite this test case using cactoos.TempFile:

@Test
@DisabledOnOs(OS.WINDOWS)
void dispatchesByFileName(@TempDir final Path temp) throws Exception {
final File file = temp.resolve("a.txt").toFile();
FileUtils.write(
file, "hello, world!",
StandardCharsets.UTF_8
);
MatcherAssert.assertThat(
new HeadPrint(
new TkFiles(temp.toFile()).act(
new RqFake(
"GET", "/a.txt?hash=a1b2c3", ""
)
)
),
new StartsWith("HTTP/1.1 200 OK")
);
FileUtils.delete(file);
}

but can't satisfy type system. It is possible to implement?

@yegor256
Copy link
Owner

@Masynchin hard to understand what you are trying to do and what is the error you are getting.

@Masynchin
Copy link
Contributor Author

Masynchin commented Aug 24, 2022

@yegor256 I am trying to replace @TempDir annotation and manual file deletion with cactoos.TempFolder and cactoos.TempFile accordingly. I have some progress, and can share working example:

@Test
@DisabledOnOs(OS.WINDOWS)
void dispatchesByFileName() throws Exception {
    try (final TempFolder dir = new TempFolder();
         final TempFile file = new TempFile(dir, "a", ".txt")) {
        FileUtils.write(
            file.value().toFile(),
            "hello, world!",
            StandardCharsets.UTF_8
        );
        MatcherAssert.assertThat(
            new RsHeadPrint(
                new TkFiles(dir.value().toFile()).act(
                    new RqFake(
                        "GET",
                        String.format(
                            "/%s?hash=a1b2c3", file.value().getFileName()
                        ), 
                        ""
                    )
                )
            ),
            new StartsWith("HTTP/1.1 200 OK")
        );
    }
}

One difference is that file name is not the same between the tests, so url created dynamically. If you think that using TempFolder/File worth it, I can open PR. Otherwise, I can close this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants