我是靠谱客的博主 炙热寒风,这篇文章主要介绍java junit 私有方法_使用junit测试静态私有方法,现在分享给大家,希望可以做个参考。

2015-03-30 06:30:01

阅读( 406 )

测试目标类如下:

package cn.outofmemory.junit;

public class TestTarget {

/**

* 移除正则表达式中需要转义的字符

* @param w word

* @return 移除正则表达式中需要转义的字符

* @author yukaizhao

* @date 2013-2-19

*/

private static String convert4Regex(String w) {

if (w == null) {

return null;

}

String[] convertedChars = {"\",".","+","*","(",")","{","}","[","]","?","/","^","$","|"};

for (String c : convertedChars) {

w = w.replace(c, "\" + c);

}

return w;

}

}

测试方法:

@Test

public void testConvert4Regex() throws Exception {

String input = "A+";

String expected = "A\+";

Method targetMethod = TestTarget.class.getDeclaredMethod("convert4Regex", String.class);

targetMethod.setAccessible(true);

Object actual = targetMethod.invoke(TestTarget.class, new Object[]{input});

assertEquals(expected,actual);

}

分享给朋友:

亲~ 如果您有更好的答案 可在评论区发表您独到的见解。

您想查看更多的信息:

面试题

最后

以上就是炙热寒风最近收集整理的关于java junit 私有方法_使用junit测试静态私有方法的全部内容,更多相关java内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(112)

评论列表共有 0 条评论

立即
投稿
返回
顶部