1.在项目目录下运行 mvn idea:idea
2. cd yourporject/path, rm *.iml *.ipr *.iws, the reopen idea, 重新在idea中执行maven build
3. Alt+shift+A, Type:Registry 选择 compiler.automake.allow.when.app.running 打勾
1.在项目目录下运行 mvn idea:idea
2. cd yourporject/path, rm *.iml *.ipr *.iws, the reopen idea, 重新在idea中执行maven build
3. Alt+shift+A, Type:Registry 选择 compiler.automake.allow.when.app.running 打勾
import com.thoughtworks.xstream.converters.reflection.FieldKey; import com.thoughtworks.xstream.converters.reflection.FieldKeySorter; import com.thoughtworks.xstream.core.util.OrderRetainingMap; import java.lang.annotation.Annotation; import java.lang.reflect.Field; import java.util.LinkedHashMap; import java.util.Map; import java.util.Set; public class PartialSeqFieldKeySorter implements FieldKeySorter { @Override public Map sort(Class type, Map keyedByFieldKey) { Annotation sequence = type.getAnnotation(XMLSequence.class); if (sequence != null) { final String[] fieldsOrder = ((XMLSequence) sequence).value(); Mapcustom = new LinkedHashMap<>(); Map notCustom = new LinkedHashMap<>(); Set > fields = keyedByFieldKey.entrySet(); for (String fieldName : fieldsOrder) { if (fieldName != null) { for (Map.Entry fieldEntry : fields) { if (fieldName.equalsIgnoreCase(fieldEntry.getKey().getFieldName())) { custom.put(fieldEntry.getKey(), fieldEntry.getValue()); } } } } return custom; } else { return keyedByFieldKey; } } }
SomeClass someclass = mock(SomeClass.class,Mockito.RETURNS_DEEP_STUBS);2. Assert Any Exceptions 断言异常
assertThrows(RunTimeException.class, ()->{ //logic code });3. Mock private method私有方法
@InjectMocks PrivateInClass privateInClass; ReflectionTestUtils.invokeMethod(privateInClass, "privateMethodName", param1, param2, ...);4. Mock final class 将文件加入到如下路径
.../test/resources/mockkito-extensions/org.mockito.plugins.MockMakerMockMaker 文件内容
mock-maker-inline
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
documentBuilderFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
documentBuilderFactory.setFeature("http://xml.org/sax/features/external-general-entities", false);
documentBuilderFactory.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
documentBuilderFactory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
documentBuilderFactory.setXIncludeAware(false);
documentBuilderFactory.setExpandEntityReferences(false);
……