RunnerUtilImpl implements RunnerUtil { @Override public boolean isRunnerMemoryCorrect(@Min(value=0) int totalMemory, @Min(value=0) int usedMemory, @Min(value=0) int availableMemory) { if (usedMemory < 0 || totalMemory < 0 || availableMemory < 0) { showWarning(locale.messagesIncorrectValue()); return false; } if (usedMemory % MB_100.getValue() != 0) { showWarning(locale.ramSizeMustBeMultipleOf(MB_100.getValue())); return false; } if (usedMemory > totalMemory) { showWarning(locale.messagesTotalRamLessCustom(usedMemory, totalMemory)); return false; } if (usedMemory > availableMemory) { showWarning(locale.messagesAvailableRamLessCustom(usedMemory, totalMemory, totalMemory - availableMemory)); return false; } return true; } @Inject  RunnerUtilImpl(DialogFactory dialogFactory,
                          RunnerLocalizationConstant locale,
                          Provider<RunnerManagerPresenter> presenter,
                          ConsoleContainer consoleContainer,
                          NotificationManager notificationManager,
                          AppContext appContext); @Override boolean isRunnerMemoryCorrect(@Min(value=0) int totalMemory, @Min(value=0) int usedMemory, @Min(value=0) int availableMemory); @Override void showWarning(@NotNull String message); @Override void showError(@NotNull Runner runner, @NotNull String message, @Nullable Throwable exception); @Override void showError(@NotNull Runner runner,
                          @NotNull String message,
                          @Nullable Throwable exception,
                          @NotNull Notification notification); @Override boolean hasRunPermission();  }
@Test @UseDataProvider("checkIsNonNegativeMemoryValue") public void runnerMemoryShouldBeAboveZero(@Min(value=0) int totalMemory, @Min(value=0) int usedMemory, @Min(value=0) int availableMemory) { when(locale.messagesIncorrectValue()).thenReturn(SOME_TEXT); boolean isCorrect = util.isRunnerMemoryCorrect(totalMemory, usedMemory, availableMemory); verifyShowWarning(); verify(locale).messagesIncorrectValue(); assertThat(isCorrect, is(false)); }
@Test public void errorMessageShouldBeShownWhenMemoryNotMultiple128() throws Exception { when(locale.ramSizeMustBeMultipleOf(MB_100.getValue())).thenReturn(SOME_TEXT); boolean isCorrect = util.isRunnerMemoryCorrect(125, 123, 125); verifyShowWarning(); verify(locale).ramSizeMustBeMultipleOf(MB_100.getValue()); assertThat(isCorrect, is(false)); }
@Test public void errorMessageShouldBeShownWhenUsedMemoryMoreTotalMemory() throws Exception { when(locale.messagesTotalRamLessCustom(anyInt(), anyInt())).thenReturn(SOME_TEXT); boolean isCorrect = util.isRunnerMemoryCorrect(99, 100, 99); verifyShowWarning(); verify(locale).messagesTotalRamLessCustom(100, 99); assertThat(isCorrect, is(false)); }
@Test public void errorMessageShouldBeShownWhenUsedMemoryMoreAvailableMemory() throws Exception { when(locale.messagesAvailableRamLessCustom(anyInt(), anyInt(), anyInt())).thenReturn(SOME_TEXT); boolean isCorrect = util.isRunnerMemoryCorrect(257, 200, 128); verifyShowWarning(); verify(locale).messagesAvailableRamLessCustom(200, 257, 129); assertThat(isCorrect, is(false)); }
@Test public void memoryShouldBeCorrect() throws Exception { boolean isCorrect = util.isRunnerMemoryCorrect(200, 200, 200); assertThat(isCorrect, is(true)); verify(dialogFactory, never()).createMessageDialog(anyString(), anyString(), any(ConfirmCallback.class)); }