[SPARK-4409] Added JavaAPI Tests, and fixed a couple of bugs