0

i've got a simple class to test in Android environment

public class ClassToTest {
    public synchronized static void func1() {....}
}

i should test: func1() can run in ONLY ONE thread, and in other threads its calls should be blocked.

how to write this JUNIT test case?

many thanks!

McArthor Lee
  • 183
  • 12
  • or, a `synchronized static` method should block in multi threads, and this is guaranteed by JAVA, and should not be tested? – McArthor Lee Jul 04 '17 at 01:44

1 Answers1

0

"Two threads cannot execute static synchronized methods of the same class at the same time, just as two threads cannot execute synchronized methods on the same object at the same time." -- The Java Programming Language, 4th Edition, Section 14.3.2

If I understand what you're asking, I don't think you should bother to write that unit test.

Also see this SO Question

albert c braun
  • 2,650
  • 1
  • 22
  • 32