[java] Added test. Closes #2963