From 8903d5e6897f6fe84837fdba9041688a09d6668d Mon Sep 17 00:00:00 2001 From: matthew16550 Date: Fri, 3 Sep 2021 17:51:22 +1000 Subject: [PATCH] Prevent intermittent test failure due to PSystemError creating different output at different times of the hour. --- src/net/sourceforge/plantuml/error/PSystemError.java | 12 +++++++++++- test/net/sourceforge/plantuml/PipeTest.java | 4 ++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/net/sourceforge/plantuml/error/PSystemError.java b/src/net/sourceforge/plantuml/error/PSystemError.java index 06aa5f0db..08af2ba60 100644 --- a/src/net/sourceforge/plantuml/error/PSystemError.java +++ b/src/net/sourceforge/plantuml/error/PSystemError.java @@ -97,6 +97,13 @@ import net.sourceforge.plantuml.version.PSystemVersion; import net.sourceforge.plantuml.version.Version; public abstract class PSystemError extends PlainDiagram { + + // Dodgy kludge for testing - we will need a different approach if we want to test addMessageDedication() etc. + private static boolean disableTimeBasedErrorDecorations = false; + + public static void disableTimeBasedErrorDecorations() { + PSystemError.disableTimeBasedErrorDecorations = true; + } protected List trace; protected ErrorUml singleError; @@ -249,7 +256,10 @@ public abstract class PSystemError extends PlainDiagram { } final int min = (int) (System.currentTimeMillis() / 60000L) % 60; // udrawable = addMessageAdopt(udrawable); - if (min == 1 || min == 8 || min == 13 || min == 55) { + if (disableTimeBasedErrorDecorations) { + // do nothing + } + else if (min == 1 || min == 8 || min == 13 || min == 55) { udrawable = addMessagePatreon(udrawable); } else if (min == 15) { udrawable = addMessageLiberapay(udrawable); diff --git a/test/net/sourceforge/plantuml/PipeTest.java b/test/net/sourceforge/plantuml/PipeTest.java index 1ac074284..3061ed7dc 100644 --- a/test/net/sourceforge/plantuml/PipeTest.java +++ b/test/net/sourceforge/plantuml/PipeTest.java @@ -12,6 +12,8 @@ import java.nio.charset.Charset; import java.util.LinkedList; import java.util.List; +import net.sourceforge.plantuml.error.PSystemError; + import org.assertj.core.api.AutoCloseableSoftAssertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -29,6 +31,8 @@ class PipeTest { @BeforeEach void setup() { + PSystemError.disableTimeBasedErrorDecorations(); + errorStatus = ErrorStatus.init(); baos = new ByteArrayOutputStream();