add junit test and move some function to common