Skip to content

Commit

Permalink
feat(objectionary#2746):fixed todo and fixed messages in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Yanich96 committed Dec 28, 2023
1 parent 428dd48 commit a0e73bf
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@
* Returns already optimized XML if it's found in the cache.
*
* @since 0.28.11
* @todo #2746:30min The tests
* {@link org.eolang.maven.optimization.OptCachedTest#returnsFromCacheCorrectProgram(Path path)}
* and
* {@link org.eolang.maven.optimization.OptCachedTest#returnsFromCacheCorrectProgram(Path path)}
* show that getting from cache don't work correctly.
* @todo #2746:30min 30min Use checksum, not time.
* The following tests show that fetching from the cache doesn't work correctly:
* - {@link org.eolang.maven.optimization.OptCachedTest#returnsFromCacheCorrectProgram(Path path)},
* - {@link org.eolang.maven.optimization.OptCachedTest#returnsFromCacheCorrectProgram(Path path)}.
* Need to fix the file validation from cache: using checksum, but not time.
* Don't forget to enable the tests.
*/
public final class OptCached implements Optimization {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ final class OptCachedTest {
@Disabled
@Test
void returnsFromCacheIfXmlAlreadyInCache(@TempDir final Path tmp) throws IOException {
final XML program = OptCachedTest.program(ZonedDateTime.now());
final XML program = OptCachedTest.program(ZonedDateTime.now(), "same");
OptCachedTest.save(tmp, program);
MatcherAssert.assertThat(
"We expected that the program will be returned from the cache",
Expand All @@ -77,12 +77,12 @@ void returnsFromCacheIfXmlAlreadyInCache(@TempDir final Path tmp) throws IOExcep
@Disabled
@Test
void returnsFromCacheButTimesSaveAndExecuteDifferent(@TempDir final Path tmp)
throws IOException, InterruptedException {
final XML program = OptCachedTest.program(ZonedDateTime.now());
Thread.sleep(70_000);
throws IOException {
final XML program = OptCachedTest.program(ZonedDateTime.now().minusMinutes(2));
OptCachedTest.save(tmp, program);
MatcherAssert.assertThat(
"We expected that the program will be returned from the cache",
String.format("We expected that the program will be returned from the cache, " +
"even if compilation and saving times are different"),
new OptCached(
path -> {
throw new IllegalStateException("This code shouldn't be executed");
Expand All @@ -96,12 +96,12 @@ void returnsFromCacheButTimesSaveAndExecuteDifferent(@TempDir final Path tmp)
@Disabled
@Test
void returnsFromCacheCorrectProgram(@TempDir final Path tmp)
throws IOException, InterruptedException {
XML program = OptCachedTest.programWithSomethings(ZonedDateTime.now(), "first program");
throws IOException {
XML program = OptCachedTest.program(ZonedDateTime.now(), "first program");
OptCachedTest.save(tmp, program);
program = OptCachedTest.programWithSomethings(ZonedDateTime.now(), "second program");
program = OptCachedTest.program(ZonedDateTime.now(), "second program");
MatcherAssert.assertThat(
"We expected that the correct program will be returned from the cache",
String.format("We expected the program corresponding to the code will be returned from the cache"),
new OptCached(
path -> {
throw new IllegalStateException("This code shouldn't be executed");
Expand Down Expand Up @@ -186,24 +186,16 @@ private static XML program() {
* @return XML representation of program.
*/
private static XML program(final ZonedDateTime time) {
return new XMLDocument(
new Xembler(
new Directives()
.add("program")
.attr("name", "main")
.attr("time", time.format(DateTimeFormatter.ISO_INSTANT))
.up()
).xmlQuietly()
);
return OptCachedTest.program(time, "same");
}

/**
* Generates EO program for tests with specified time and content.
* Generates EO program for tests with specified time and context.
* @param time Time.
* @param something String.
* @return XML representation of program.
*/
private static XML programWithSomethings(final ZonedDateTime time, final String something) {
private static XML program(final ZonedDateTime time, final String something) {
return new XMLDocument(
new Xembler(
new Directives()
Expand Down

0 comments on commit a0e73bf

Please sign in to comment.