package com.instinctools.padlaboris.service;

import com.instinctools.padlaboris.model.Patient;
import com.instinctools.padlaboris.repository.PatientRepository;
import org.hamcrest.core.Is;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.List;

import static org.junit.Assert.assertThat;

@RunWith(SpringRunner.class)
@SpringBootTest
public class DefaultPatientServiceTest {

    @Autowired
    private PatientService patientService;

    @Autowired
    private PatientRepository patientRepository;

    private Integer id;

    private Patient patient;

    @Before
    public void setUp() throws Exception {

        patient = new Patient();

        patient.setLastName("lastName");
        patient.setGender("male");

        id = patientRepository.save(patient).getId();
    }

    @Test
    public void create() throws Exception {

        final String content = "newPatientLastName";

        patient.setLastName(content);

        final Patient saved = patientService.create(patient);

        assertThat(saved.getLastName(), Is.is(content));
    }

    @Test
    public void fetch() throws Exception {

        final String content = "lastName";

        assertThat(patientService.fetch(id).getLastName(), Is.is(content));
    }

    @Test
    public void findByLastName() throws Exception {

        final String content = "lastName";

        final List<Patient> patients = patientService.findByLastName(content);

        assertThat(patients.get(0).getLastName(), Is.is(content));
    }

    @Test
    public void findByGender() throws Exception {

        final String content = "male";

        final List<Patient> patients = patientService.findByGender(content);

        assertThat(patients.get(0).getGender(), Is.is(content));
    }

    @Test
    public void delete() throws Exception {

        patientService.delete(id);

        assertThat(patientRepository.exists(id), Is.is(false));
    }
}

@@ -450,16 +450,56 @@
 unner;%0A%0A
+import javax.transaction.Transactional;%0A
 import j
@@ -1319,32 +1319,412 @@
 ntent));%0A    %7D%0A%0A
+    @Test%0A    @Transactional%0A    public void update() throws Exception %7B%0A%0A        final String content = %22updatePatientLastName%22;%0A%0A        final Patient updatePatient = patientRepository.findOne(id);%0A%0A        updatePatient.setLastName(content);%0A        patientService.update(updatePatient);%0A%0A        assertThat(patientRepository.findOne(id).getLastName(), Is.is(content));%0A    %7D%0A%0A
     @Test%0A    pu

Rename DefaultPatientServiceTest to PatientRepositoryTest