Using reflection to change static final File.separatorChar for unit testing?

前端 未结 7 863
太阳男子
太阳男子 2020-11-28 09:37

Specifically, I\'m trying to create a unit test for a method which requires uses File.separatorChar to build paths on windows and unix. The code must run on bot

相关标签:
7条回答
  • 2020-11-28 10:06

    You can take the source for java.io.File, and modify it so that separatorChar and separator are not final, and add a setSeparatorChar method that updates the two of them, then include the compiled class in your bootclasspath.

    0 讨论(0)
提交回复
热议问题