@@ -0,0 +1,1901 @@
+package jenkins.plugins.git.traits;%0A%0Aimport hudson.model.TaskListener;%0Aimport jenkins.plugins.git.GitSCMSourceContext;%0Aimport jenkins.scm.api.SCMHeadObserver;%0Aimport jenkins.scm.api.SCMSource;%0Aimport jenkins.scm.api.SCMSourceCriteria;%0Aimport jenkins.scm.api.trait.SCMSourceContext;%0Aimport jenkins.scm.api.trait.SCMSourceRequest;%0A%0Aimport static org.junit.Assert.*;%0Aimport static org.hamcrest.Matchers.*;%0Aimport org.junit.Test;%0Aimport org.jvnet.hudson.test.Issue;%0A%0A/**%0A * Test for JENKINS-57683 - Class cast exception when an SCMSource or%0A * SCMSourceContext was passed that was not a GitSCMSource.%0A *%0A * @author Mark Waite%0A */%0Apublic class PruneStaleBranchTraitTest %7B%0A%0A    public PruneStaleBranchTraitTest() %7B%0A    %7D%0A%0A    @Test%0A    public void testDecorateContextWithGitSCMSourceContent() %7B%0A        GitSCMSourceContext context = new GitSCMSourceContext(null, null);%0A        assertThat(context.pruneRefs(), is(false));%0A        PruneStaleBranchTrait pruneStaleBranchTrait = new PruneStaleBranchTrait();%0A        pruneStaleBranchTrait.decorateContext(context);%0A        assertThat(context.pruneRefs(), is(true));%0A    %7D%0A%0A    @Test%0A    @Issue(%22JENKINS-57683%22)%0A    public void testDecorateContextWithNonGitSCMSourceContent() %7B%0A        SCMSourceContext context = new FakeSCMSourceContext(null, null);%0A        PruneStaleBranchTrait pruneStaleBranchTrait = new PruneStaleBranchTrait();%0A        pruneStaleBranchTrait.decorateContext(context);%0A        /* JENKINS-57683 would cause this test to throw an exception */%0A    %7D%0A%0A    private static class FakeSCMSourceContext extends SCMSourceContext %7B%0A%0A        public FakeSCMSourceContext(SCMSourceCriteria scmsc, SCMHeadObserver scmho) %7B%0A            super(scmsc, scmho);%0A        %7D%0A%0A        @Override%0A        public SCMSourceRequest newRequest(SCMSource scms, TaskListener tl) %7B%0A            throw new UnsupportedOperationException(%22Not supported yet.%22);%0A        %7D%0A    %7D%0A%7D%0A

Test for PruneStaleBranchTrait class cast exception