fixed junit tests - changed BeforeClass to Before

The junit tests were using BeforeClass annotation to have initialization code. It should actually be @Before.

Also the tests relied on the order of the tests in source code which is not the order that JUNIT runs the tests. So, with this fix parts of code were moved to the test functions. This code can still be refactored to moved the common initialization codes into a function.