Fixed bug JENKINS-20539 and added more tests for JENKINS-20517