Search in sources :

Example 1 with ClassPool

use of org.apache.ibatis.javassist.ClassPool in project judge by zjnu-acm.

the class MockGenerator method toMethodComparator.

private Comparator<String> toMethodComparator(Class<?> key) {
    AtomicInteger counter = new AtomicInteger();
    ClassPool classPool = ClassPool.getDefault();
    Map<String, Integer> map = Stream.concat(takeWhile(Stream.<Class<?>>iterate(key, Class::getSuperclass), parent -> parent != null && parent.getClassLoader() != null), Arrays.stream(key.getInterfaces())).flatMap(type -> stream(classPool, type)).collect(Collectors.toMap(method -> method.getDeclaringClass().getName().replace(".", "/") + "." + method.getName() + ":" + method.getSignature(), __ -> counter.getAndIncrement()));
    return Comparator.comparingInt(s -> map.getOrDefault(s, Integer.MAX_VALUE));
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) PathVariable(org.springframework.web.bind.annotation.PathVariable) Arrays(java.util.Arrays) RequestParam(org.springframework.web.bind.annotation.RequestParam) ClassPool(org.apache.ibatis.javassist.ClassPool) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Autowired(org.springframework.beans.factory.annotation.Autowired) HandlerMethod(org.springframework.web.method.HandlerMethod) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Gson(com.google.gson.Gson) Locale(java.util.Locale) Map(java.util.Map) MethodParameter(org.springframework.core.MethodParameter) Method(java.lang.reflect.Method) Path(java.nio.file.Path) MatcherWrapper(cn.edu.zjnu.acm.judge.util.MatcherWrapper) PrintWriter(java.io.PrintWriter) WebAppConfiguration(org.springframework.test.context.web.WebAppConfiguration) ClassUtils(org.springframework.util.ClassUtils) ImmutableMap(com.google.common.collect.ImmutableMap) Predicate(java.util.function.Predicate) MediaType(org.springframework.http.MediaType) Set(java.util.Set) RequestMethod(org.springframework.web.bind.annotation.RequestMethod) MockMvcResultMatchers(org.springframework.test.web.servlet.result.MockMvcResultMatchers) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) MockMultipartFile(org.springframework.mock.web.MockMultipartFile) UncheckedIOException(java.io.UncheckedIOException) Objects(java.util.Objects) Test(org.junit.jupiter.api.Test) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) Stream(java.util.stream.Stream) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Modifier(java.lang.reflect.Modifier) RequestMappingHandlerMapping(org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping) RequestHeader(org.springframework.web.bind.annotation.RequestHeader) RunWith(org.junit.runner.RunWith) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) MockMvc(org.springframework.test.web.servlet.MockMvc) RequestBody(org.springframework.web.bind.annotation.RequestBody) RequestMappingInfo(org.springframework.web.servlet.mvc.method.RequestMappingInfo) HttpServletRequest(javax.servlet.http.HttpServletRequest) Parameter(java.lang.reflect.Parameter) MvcResult(org.springframework.test.web.servlet.MvcResult) StreamSupport(java.util.stream.StreamSupport) Application(cn.edu.zjnu.acm.judge.Application) Files(java.nio.file.Files) StringWriter(java.io.StringWriter) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) HttpServletResponse(javax.servlet.http.HttpServletResponse) IOException(java.io.IOException) Maps(com.google.common.collect.Maps) MockMvcRequestBuilders(org.springframework.test.web.servlet.request.MockMvcRequestBuilders) CtMethod(org.apache.ibatis.javassist.CtMethod) AutoConfigureMockMvc(org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc) Paths(java.nio.file.Paths) ReflectionUtils(org.springframework.util.ReflectionUtils) MultipartFile(org.springframework.web.multipart.MultipartFile) JUnitPlatform(org.junit.platform.runner.JUnitPlatform) Comparator(java.util.Comparator) InputStream(java.io.InputStream) Transactional(org.springframework.transaction.annotation.Transactional) StringUtils(org.springframework.util.StringUtils) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ClassPool(org.apache.ibatis.javassist.ClassPool)

Aggregations

Application (cn.edu.zjnu.acm.judge.Application)1 MatcherWrapper (cn.edu.zjnu.acm.judge.util.MatcherWrapper)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 Maps (com.google.common.collect.Maps)1 Gson (com.google.gson.Gson)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 UncheckedIOException (java.io.UncheckedIOException)1 Method (java.lang.reflect.Method)1 Modifier (java.lang.reflect.Modifier)1 Parameter (java.lang.reflect.Parameter)1 StandardCharsets (java.nio.charset.StandardCharsets)1 Files (java.nio.file.Files)1 Path (java.nio.file.Path)1 Paths (java.nio.file.Paths)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1