小编Cof*_*nky的帖子

如何将Java API的内部结构隐藏到世界其他地方

我正在开发一个Java Api来做事情(秘密,呃嗯;).

有没有办法隐藏类,以及我的API的内部结构?

我到现在才发现:

  • 使用内部类(丑陋的方式,我不想把所有内容放在类文件中)
  • 一个包中的所有类,以便我可以使用"包"-visibilty(也很难看,我需要更多的包)

例:

---
package net.my.app;
//this is the Public Access
class MyPublicClass{
    public void somePublicFunction(){ 
        //access to not visibil classes
    }
}

---
package net.my.app.notvisible:
//this is what i want to hide
class MyNOTPublicClass{
    ...
}
---
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?谢谢!

java api design-patterns

14
推荐指数
2
解决办法
9631
查看次数

通过一次测试调用JUnit setUp两次,并搞乱Powermock expectNew

在我的测试中非常奇怪的行为.

  public class MyTestclass {
     @Before
     void setUp(){
        //do some setup, but hu i get called twice
        //here i do some try catch thing to get the stacktrace...
     }

     void testOnlyOneTest(){
        //make the testing, i get called only once
     }

     @After
     void tearDown(){
        //do some destroy things,... i get called twice too
     }
  }
Run Code Online (Sandbox Code Playgroud)

堆栈跟踪:

  1)
  MyTestClassTest.setUp() line: 85          
  NativeMethodAccessorImpl.invoke0(Method, Object, Object[]) line: not available [native method]   
  NativeMethodAccessorImpl.invoke(Object, Object[]) line: 39  
  DelegatingMethodAccessorImpl.invoke(Object, Object[]) line: 25         
  Method.invoke(Object, Object...) line: 597        
  PowerMockJUnit44RunnerDelegateImpl$PowerMockJUnit44MethodRunner(MethodRoadie).runBefores() …
Run Code Online (Sandbox Code Playgroud)

java junit easymock mocking powermock

2
推荐指数
1
解决办法
3992
查看次数

标签 统计

java ×2

api ×1

design-patterns ×1

easymock ×1

junit ×1

mocking ×1

powermock ×1