package com.camunda.fox.cycle.web.service.resource;

import javax.inject.Inject;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.kubek2k.springockito.annotations.ReplaceWithMock;
import org.kubek2k.springockito.annotations.SpringockitoContextLoader;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import com.camunda.fox.cycle.entity.Roundtrip;
import com.camunda.fox.cycle.repository.RoundtripRepository;
import com.camunda.fox.cycle.web.dto.RoundtripDTO;

import static org.junit.Assert.*;
import static org.mockito.BDDMockito.*;
import static org.hamcrest.Matchers.*;
import org.junit.Ignore;
import static org.mockito.Matchers.any;

/**
 *
 * @author nico.rehwaldt
 */
@Ignore // Broke through introduction of AOP
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(
  loader = SpringockitoContextLoader.class, 
  locations = {"classpath:/spring/context.xml", "classpath:/spring/test-*.xml"}
)
public class RoundtripControllerMockTest {

  @Inject
  @ReplaceWithMock
  private RoundtripRepository roundtripRepository;

  @Inject
  private RoundtripService roundtripController;

  @Test
  public void shouldAddRoundtrip() throws Exception {
    
    // given
    Roundtrip roundtrip = new Roundtrip(1l, "ASDF");
    RoundtripDTO dto = new RoundtripDTO(roundtrip);
    
    given(roundtripRepository.saveAndFlush(any(Roundtrip.class))).willReturn(roundtrip);
    
    // when
    RoundtripDTO response = roundtripController.create(dto);
    
    // then
    assertThat(response.getId(), is(roundtrip.getId()));
    assertThat(response.getName(), is(roundtrip.getName()));
    verify(roundtripRepository).saveAndFlush(any(Roundtrip.class));
  }
}

@@ -57,29 +57,224 @@
 ort 
-javax.inject.Inject;%0A
+static org.hamcrest.Matchers.is;%0Aimport static org.junit.Assert.assertThat;%0Aimport static org.mockito.BDDMockito.given;%0Aimport static org.mockito.Mockito.verify;%0A%0Aimport javax.inject.Inject;%0A%0Aimport org.junit.Ignore;
 %0Aimp
@@ -757,267 +757,43 @@
 O;%0A%0A
-import static org.junit.Assert.*;%0Aimport static org.mockito.BDDMockito.*;%0Aimport static org.hamcrest.Matchers.*;%0Aimport org.junit.Ignore;%0Aimport static org.mockito.Matchers.any;%0A%0A/**%0A *%0A * @author nico.rehwaldt%0A */%0A@Ignore // Broke through introduction of AOP
+/**%0A *%0A * @author nico.rehwaldt%0A */
 %0A@Ru
@@ -1388,32 +1388,53 @@
 ry.saveAndFlush(
+org.mockito.Matchers.
 any(Roundtrip.cl
@@ -1721,16 +1721,37 @@
 ndFlush(
+org.mockito.Matchers.
 any(Roun

fix mock test