package com.fwdekker.randomness;

import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.CommonDataKeys;
import com.intellij.openapi.actionSystem.Presentation;
import com.intellij.openapi.editor.Editor;
import org.junit.Before;
import org.junit.Test;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;


/**
 * Unit tests for {@link InsertRandomSomething}.
 */
public final class InsertRandomSomethingTest {
    /**
     * The recognizable string that is inserted by the insertion action.
     */
    private static final String RANDOM_STRING = "random_string";

    private InsertRandomSomething insertRandomSomething;


    @Before
    public void beforeEach() {
        insertRandomSomething = new InsertRandomSimple();
    }


    @Test
    public void testDisabled() {
        final AnActionEvent event = mock(AnActionEvent.class);
        final Presentation presentation = spy(Presentation.class);
        when(event.getPresentation()).thenReturn(presentation);

        insertRandomSomething.update(event);

        assertThat(presentation.isEnabled()).isFalse();
    }

    @Test
    public void testEnabled() {
        final AnActionEvent event = mock(AnActionEvent.class);
        final Presentation presentation = spy(Presentation.class);
        when(event.getData(CommonDataKeys.EDITOR)).thenReturn(mock(Editor.class));
        when(event.getPresentation()).thenReturn(presentation);

        insertRandomSomething.update(event);

        assertThat(presentation.isEnabled()).isTrue();
    }


    /**
     * Simple implementation of {@code InsertRandomSomething}.
     */
    private static class InsertRandomSimple extends InsertRandomSomething {
        @Override
        protected String generateString() {
            return RANDOM_STRING;
        }
    }
}

@@ -424,16 +424,159 @@
 to.spy;%0A
+import static org.mockito.Mockito.times;%0Aimport static org.mockito.Mockito.verify;%0Aimport static org.mockito.Mockito.verifyNoMoreInteractions;%0A
 import s
@@ -1044,34 +1044,593 @@
     
-@Test%0A    public void test
+/**%0A     * Tests that no further actions are taken when the editor is %7B@code null%7D.%0A     */%0A    @Test%0A    public void testActionPerformedNullEditor() %7B%0A        final AnActionEvent event = mock(AnActionEvent.class);%0A        when(event.getData(CommonDataKeys.EDITOR)).thenReturn(null);%0A%0A        insertRandomSomething.actionPerformed(event);%0A%0A        verify(event, times(1)).getData(CommonDataKeys.EDITOR);%0A        verifyNoMoreInteractions(event);%0A    %7D%0A%0A    /**%0A     * Tests that the action's presentation is disabled when the editor is null.%0A     */%0A    @Test%0A    public void testUpdate
 Disa
@@ -1760,32 +1760,101 @@
 ntation.class);%0A
+        when(event.getData(CommonDataKeys.EDITOR)).thenReturn(null);%0A
         when(eve
@@ -2007,24 +2007,124 @@
 e();%0A    %7D%0A%0A
+    /**%0A     * Tests that the action's presentation is enabled when the editor is not null.%0A     */%0A
     @Test%0A  
@@ -2141,16 +2141,22 @@
 oid test
+Update
 Enabled(

Test edge case and add test documentation