package com.github.onsdigital.babbage.request.handler;

import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;

import static com.github.onsdigital.babbage.request.handler.PageRequestHandler.isCookiesPreferenceSet;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.when;

public class PageRequestHandlerTest {

    @Mock
    private HttpServletRequest request;

    @Mock
    private Cookie cookie;

    @Before
    public void setUp() throws Exception {
        MockitoAnnotations.initMocks(this);
    }

    @Test
    public void isCookiesPreferenceSet_RequestIsNull_ReturnsFalse() {
        boolean result = isCookiesPreferenceSet(null);
        assertFalse(result);
    }

    @Test
    public void isCookiesPreference_CookiesIsNull_ReturnsFalse() {
        when(request.getCookies()).thenReturn(null);
        boolean result = isCookiesPreferenceSet(request);
        assertFalse(result);
    }

    @Test
    public void isCookiesPreference_CookieNotExist_ReturnsFalse() {
        Cookie[] cookies = new Cookie[]{cookie};
        when(cookie.getName()).thenReturn("test_cookie");
        when(request.getCookies()).thenReturn(cookies);

        boolean result = isCookiesPreferenceSet(request);

        assertFalse(result);
    }

    @Test
    public void isCookiesPreference_CookieExists_ReturnsTrue() {
        Cookie[] cookies = new Cookie[]{cookie};
        when(cookie.getName()).thenReturn("cookies_preferences_set");
        when(request.getCookies()).thenReturn(cookies);

        boolean result = isCookiesPreferenceSet(request);

        assertTrue(result);
    }
}
@@ -1095,32 +1095,308 @@
 result);%0A    %7D%0A%0A
+    @Test%0A    public void isCookiesPreference_CookiesIsEmptyArray_ReturnsFalse() %7B%0A        Cookie%5B%5D cookies = new Cookie%5B%5D%7B%7D;%0A        when(request.getCookies()).thenReturn(cookies);%0A        boolean result = isCookiesPreferenceSet(request);%0A        assertFalse(result);%0A    %7D%0A%0A
     @Test%0A    pu

add test to account for expected behaviour when cookies array is empty