我无法为我的测试添加注释以@WebMvcTest使其正常工作。我还配置了spring-cloud-config-server和spring-cloud-starter,所有带有这个注解的Test类好像都失败了。我有以下控制器测试:
代码:
@RunWith(SpringRunner.class)
@WebMvcTest(controllers = UserController.class)
@ActiveProfiles({"dev", "native"})
public class UserControllerTest {
@MockBean
private UserService userService;
@Autowired
private MockMvc mockMvc;
@Autowired
private ObjectMapper objectMapper;
@Test
public void changePassword() throws Exception {
given(userService.changePassword(any(), any(), any())).willReturn(true);
MvcResult result = mockMvc.perform(post(/user/changePassword)
.param("old", "Pa$$W0rd")
.param("new, "NewPa$$W0rd"))
.andExpect(status().isOk()).andReturn();
assertThat(result).isNotNull();
assertThat(result.getResponse().getContentAsString()).isEqualTo("true");
}
}
Run Code Online (Sandbox Code Playgroud)
相关控制器:
@RestController
@RequestMapping(/user)
@Log4j2
public class UserController {
private UserService userService;
public UserController(UserService userService) {
this.userService = userService;
}
@Timed
@PostMapping(value = /changePassword)
public ResponseEntity changePassword(@RequestParam("old") String oldPassword,
@RequestParam("new") String newPassword) …Run Code Online (Sandbox Code Playgroud) 我想知道如何检查第一列中的一行是否作为另一个文件中另一行的一部分存在。例如,如果我有以下文件:
a.txt:
0000_01_000000049E 7821069312
0000_01_000000049F 7886800896
0000_01_00000004A1 8302987264
0000_01_00000004A2 8469055488
0000_01_00000004A3 8040450048
0000_01_00000004A5 8250165248
0000_01_00000004A6 8116242432
0000_01_00000004A7 8260126720
0000_01_00000004A9 6420892672
0000_01_00000004AA 1076364288
0000_01_00000004AB 7822870528
0000_01_00000004AE 4297589760
0000_01_00000004AF 2360320
Run Code Online (Sandbox Code Playgroud)
b.txt:
0000_01_000000049E,000000,0000_02_00000002AA,7821070336,1451596986,L3,0,0
0000_01_000000049F,000001,0000_02_00000002AA,7886801920,1451623534,L3,0,0
0000_01_00000004A0,000002,0000_02_00000002AA,6888983552,1451051126,L3,0,0
0000_01_00000004A1,000003,0000_02_00000002AA,8302988288,1451618939,L3,0,0
0000_01_00000004A2,000004,0000_02_00000002AA,8469056512,1451605811,L3,0,0
0000_01_00000004A3,000005,0000_02_00000002AA,8040451072,1452180174,L3,0,0
0000_01_00000004A4,000006,0000_02_00000002AA,8569819136,1451541232,L3,0,0
0000_01_00000004A5,000007,0000_02_00000002AA,8250166272,1452181606,L3,0,0
0000_01_00000004A6,000008,0000_02_00000002AA,8116243456,1452013786,L3,0,0
0000_01_00000004A7,000009,0000_02_00000002AA,8260127744,1451420337,L3,0,0
0000_01_00000004A8,000010,0000_02_00000002AA,8454605824,1451542793,L3,0,0
0000_01_00000004A9,000011,0000_02_00000002AA,7543657472,1451568105,L3,0,0
0000_01_00000004AA,000012,0000_02_00000002AA,7654181888,1451494089,L3,0,0
0000_01_00000004AB,000013,0000_02_00000002AA,7822871552,1451590252,L3,0,0
0000_01_00000004AC,000014,0000_02_00000002AA,5295639552,1450925203,L3,0,0
0000_01_00000004AD,000015,0000_02_00000002AA,7793807360,1451470796,L3,0,0
0000_01_00000004AE,000016,0000_02_00000002AA,8330842112,1451591997,L3,0,0
0000_01_00000004AF,000017,0000_02_00000002AA,29039368192,1452093213,L3,0,0
Run Code Online (Sandbox Code Playgroud)
我想返回文件“b.txt”中第二列的值,其中文件“a.txt”和“b.txt”中第一列的值匹配(内部联接排序)。因此,如果该文件位于输出文件“c.txt”中,我想要以下输出:
c.txt:
000000
000001
000002
000003
000004
000005
000007
000008
000009
000011
000012
000013
000016
000017
Run Code Online (Sandbox Code Playgroud)
请注意,文件“b.txt”第二列中不存在这些值:
000006
000010
000014
000015
Run Code Online (Sandbox Code Playgroud)
我尝试到处寻找,但找不到任何可以帮助解决问题的具体内容。感谢您的帮助。
谢谢!