@@ -0,0 +1,3107 @@
+package com.github.terma.jenkins.githubprcoveragestatus;%0A%0Aimport lombok.SneakyThrows;%0Aimport org.apache.commons.io.IOUtils;%0Aimport org.junit.Before;%0Aimport org.junit.Test;%0Aimport org.kohsuke.stapler.StaplerRequest;%0Aimport org.kohsuke.stapler.StaplerResponse;%0Aimport org.mockito.Mockito;%0A%0Aimport java.io.ByteArrayOutputStream;%0Aimport java.io.PrintWriter;%0A%0Aimport static org.hamcrest.CoreMatchers.equalTo;%0Aimport static org.hamcrest.CoreMatchers.nullValue;%0Aimport static org.hamcrest.MatcherAssert.assertThat;%0Aimport static org.mockito.Mockito.times;%0Aimport static org.mockito.Mockito.verify;%0Aimport static org.mockito.Mockito.when;%0A%0Apublic class CoverageStatusIconActionTest %7B%0A%0A    CoverageStatusIconAction action;%0A    StaplerRequest request;%0A    StaplerResponse response;%0A    ByteArrayOutputStream outputStream;%0A    PrintWriter printWriter;%0A%0A    @Before%0A    @SneakyThrows%0A    public void before() %7B%0A        action = new CoverageStatusIconAction();%0A        outputStream = new ByteArrayOutputStream();%0A        request = Mockito.mock(StaplerRequest.class);%0A        response = Mockito.mock(StaplerResponse.class);%0A        printWriter = new PrintWriter(outputStream);%0A        when(request.getParameter(%22coverage%22)).thenReturn(%220.56%22);%0A        when(request.getParameter(%22masterCoverage%22)).thenReturn(%220.51%22);%0A        when(request.getParameter(%22color%22)).thenReturn(%22red%22);%0A        when(response.getWriter()).thenReturn(printWriter);%0A    %7D%0A%0A    @Test%0A    public void testGetter() %7B%0A        assertThat(%22DisplayName%22, action.getDisplayName(), nullValue());%0A        assertThat(%22IconFileName%22, action.getIconFileName(), nullValue());%0A        assertThat(%22UrlName%22, action.getUrlName(), equalTo(CoverageStatusIconAction.URL_NAME));%0A    %7D%0A%0A    @Test%0A    public void verifyIconIsReturnedInRed() %7B%0A        when(request.getParameter(%22color%22)).thenReturn(%22red%22);%0A        verifyIconIsReturned(%22#b94947%22);%0A    %7D%0A%0A    @Test%0A    public void verifyIconIsReturnedInGreen() %7B%0A        when(request.getParameter(%22color%22)).thenReturn(%22brightgreen%22);%0A        verifyIconIsReturned(%22#97CA00%22);%0A    %7D%0A%0A    @Test%0A    public void verifyIconIsReturnedInYellow() %7B%0A        when(request.getParameter(%22color%22)).thenReturn(%22yellow%22);%0A        verifyIconIsReturned(%22#F89406%22);%0A    %7D%0A%0A    @Test%0A    public void verifyIconIsReturnedWithHexColor() %7B%0A        when(request.getParameter(%22color%22)).thenReturn(%22#997755%22);%0A        verifyIconIsReturned(%22#997755%22);%0A    %7D%0A%0A    @SneakyThrows%0A    private void verifyIconIsReturned(String expectedColor) %7B%0A        action.doIndex(request, response);%0A        printWriter.flush();%0A        assertThat(%22Icon body%22, outputStream.toString(), equalTo(getExpectedBody(%2256%25 (+5.0%25) vs master 51%25%22, expectedColor)));%0A        verify(response, times(1)).setContentType(%22image/svg+xml%22);%0A    %7D%0A%0A    @SneakyThrows%0A    private String getExpectedBody(String message, String color) %7B%0A        String svg = IOUtils.toString(this.getClass().getResourceAsStream(%0A            %22/com/github/terma/jenkins/githubprcoveragestatus/Icon/icon.svg%22));%0A        return svg.replace(%22%7B%7B message %7D%7D%22, message).replace(%22%7B%7B color %7D%7D%22, color);%0A    %7D%0A%0A%7D

Add test for CoverageStatusIconAction