package org.openlmis.web.controller.vaccine;

import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;

import static java.util.Arrays.asList;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
import static org.junit.Assert.*;
import static org.mockito.Matchers.anyList;
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.isNotNull;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import org.mockito.runners.MockitoJUnitRunner;
import org.openlmis.core.domain.ConfigurationSetting;
import org.openlmis.core.service.ConfigurationSettingService;
import org.openlmis.db.categories.UnitTests;
import org.openlmis.vaccine.domain.VaccineProductDose;
import org.openlmis.vaccine.dto.VaccineServiceConfigDTO;
import org.openlmis.vaccine.service.VaccineProductDoseService;
import org.openlmis.web.response.OpenLmisResponse;
import org.springframework.http.ResponseEntity;

import java.util.ArrayList;
import java.util.List;


@Category(UnitTests.class)
@RunWith(MockitoJUnitRunner.class)
public class ProductDoseControllerTest {

  @Mock
  VaccineProductDoseService service;

  @Mock
  ConfigurationSettingService settingService;

  @InjectMocks
  ProductDoseController controller;

  @Test
  public void shouldGetProgramProtocol() throws Exception {
    List<VaccineProductDose> doses = new ArrayList<>();
    when(service.getForProgram(1L)).thenReturn(doses);
    when(settingService.getBoolValue(anyString())).thenReturn(true);
    when(settingService.getSearchResults(anyString())).thenReturn(asList(new ConfigurationSetting()));
    ResponseEntity<OpenLmisResponse> response = controller.getProgramProtocol(1L);
    assertThat(response.getBody().getData().get("protocol"), is(notNullValue()));
  }

  @Test
  public void shouldSave() throws Exception {
    VaccineServiceConfigDTO dto = new VaccineServiceConfigDTO();
    dto.setTabVisibilitySettings(new ArrayList<ConfigurationSetting>());
    doNothing().when(service).save(anyList());
    ResponseEntity<OpenLmisResponse> response = controller.save(dto);
    verify(service).save(anyList());
    assertThat("success", is(response.getBody().getData().get("status")));
  }
}
@@ -890,24 +890,72 @@
 roductDose;%0A
+import org.openlmis.vaccine.dto.ProductDoseDTO;%0A
 import org.o
@@ -995,24 +995,24 @@
 eConfigDTO;%0A
-
 import org.o
@@ -1369,63 +1369,8 @@
 e;%0A%0A
-  @Mock%0A  ConfigurationSettingService settingService;%0A%0A
   @I
@@ -1493,181 +1493,66 @@
     
-List%3C
 Vaccine
-ProductDose%3E doses = new ArrayList%3C%3E();%0A    when(service.getForProgram(1L)).thenReturn(doses);%0A    when(settingService.getBoolValue(anyString())).thenReturn(true
+ServiceConfigDTO dto = new VaccineServiceConfigDTO(
 );%0A 
@@ -1561,23 +1561,16 @@
  when(se
-ttingSe
 rvice.ge
@@ -1574,81 +1574,49 @@
 .get
-SearchResults(anyString())).thenReturn(asList(new ConfigurationSetting())
+ProductDoseForProgram(1L)).thenReturn(dto
 );%0A 
@@ -1918,64 +1918,46 @@
 .set
-TabVisibilitySettings(new ArrayList%3CConfigurationSetting
+Protocols(new ArrayList%3CProductDoseDTO
 %3E())
@@ -1989,36 +1989,46 @@
 rvice).save(
-anyList
+dto.getProtocols
 ());%0A
+%0A
     Response
@@ -2081,24 +2081,25 @@
 .save(dto);%0A
+%0A
     verify(s
@@ -2142,17 +2142,11 @@
 hat(
-%22success%22
+dto
 , is
@@ -2184,14 +2184,16 @@
 et(%22
-status
+protocol
 %22)))

Fix unit tests that were broken when refactoring tab settings out of product dose controller.