private static InspectContainerResponse.ContainerState buildState(boolean running, boolean paused, String startedAt, String finishedAt) { InspectContainerResponse.ContainerState state = Mockito.mock(InspectContainerResponse.ContainerState.class); when(state.getRunning()).thenReturn(running); when(state.getPaused()).thenReturn(paused); when(state.getStartedAt()).thenReturn(startedAt); when(state.getFinishedAt()).thenReturn(finishedAt); return state; } }
/** * Based on this status, has the container halted? * * @param state the state provided by InspectContainer * @return true if we can conclude that the container has started but is now stopped, false otherwise. */ public static boolean isContainerStopped(InspectContainerResponse.ContainerState state) { // get some preconditions out of the way if (state.getRunning() || state.getPaused()) { return false; } // if the finished timestamp is non-empty, that means the container started and finished. boolean hasStarted = isDockerTimestampNonEmpty(state.getStartedAt()); boolean hasFinished = isDockerTimestampNonEmpty(state.getFinishedAt()); return hasStarted && hasFinished; }
/** * Based on this status, has the container halted? * * @param state the state provided by InspectContainer * @return true if we can conclude that the container has started but is now stopped, false otherwise. */ public static boolean isContainerStopped(InspectContainerResponse.ContainerState state) { // get some preconditions out of the way if (state.getRunning() || state.getPaused()) { return false; } // if the finished timestamp is non-empty, that means the container started and finished. boolean hasStarted = isDockerTimestampNonEmpty(state.getStartedAt()); boolean hasFinished = isDockerTimestampNonEmpty(state.getFinishedAt()); return hasStarted && hasFinished; }