Fixed JAVA-722 bug, added test cases