Add proxyTargetBeans = false and fix some tests

This commit is contained in:
Dave Syer
2019-07-10 12:59:52 +01:00
committed by Oleg Zhurakousky
parent 521c6d3397
commit 307292b959
6 changed files with 40 additions and 19 deletions

View File

@@ -16,33 +16,54 @@
package com.example;
import org.junit.Ignore;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.asyncDispatch;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.MediaType;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import org.springframework.test.web.servlet.MvcResult;
/**
* @author Dave Syer
*/
@RunWith(SpringRunner.class)
@WebMvcTest
@SpringBootTest
@AutoConfigureMockMvc
public class SampleApplicationMvcTests {
@Autowired
private MockMvc mockMvc;
@Test
@Ignore("FIXME")
public void words() throws Exception {
this.mockMvc.perform(get("/words"))
.andExpect(content().string("[\"foo\",\"bar\"]"));
MvcResult result = this.mockMvc.perform(get("/words")).andReturn();
mockMvc.perform(asyncDispatch(result)).andExpect(content().string("[\"foo\",\"bar\"]"));
}
@Test
public void uppercase() throws Exception {
MvcResult result = this.mockMvc.perform(post("/uppercase").contentType(MediaType.TEXT_PLAIN).content("foo")).andReturn();
mockMvc.perform(asyncDispatch(result)).andExpect(content().string("FOO"));
}
@Test
public void lowercase() throws Exception {
MvcResult result = this.mockMvc.perform(post("/lowercase").contentType(MediaType.TEXT_PLAIN).content("FOO")).andReturn();
mockMvc.perform(asyncDispatch(result)).andExpect(content().string("[\"foo\"]"));
}
@Test
public void lowercaseMulti() throws Exception {
MvcResult result = this.mockMvc.perform(post("/lowercase").contentType(MediaType.APPLICATION_JSON).content("[\"FOO\"]")).andReturn();
mockMvc.perform(asyncDispatch(result)).andExpect(content().string("[\"foo\"]"));
}
}

View File

@@ -16,19 +16,19 @@
package com.example;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.List;
import java.util.function.Function;
import java.util.function.Supplier;
import org.junit.Test;
import org.junit.runner.RunWith;
import reactor.core.publisher.Flux;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import static org.assertj.core.api.Assertions.assertThat;
import reactor.core.publisher.Flux;
@RunWith(SpringRunner.class)
@SpringBootTest
@@ -124,7 +124,7 @@ public class SampleApplicationTests {
@Test
public void testCharCounter() {
Integer length = this.charCounter.apply("the quick brown fox");
assertThat(length).isEqualTo(new Integer(19));
assertThat(length).isEqualTo(19);
}
}