<fim-prefix>MaterialConfig hgMaterialConfig = hg("http://example.com", null);
            hgMaterialConfig.setUserName("bob");
            hgMaterialConfig.setPassword("badger");

            hgMaterialConfig.validate(new ConfigSaveValidationContext(null));

            assertThat(hgMaterialConfig.errors().on(HgMaterialConfig.URL)).isNull();
        }

        @Test
        void shouldEnsureBranchIsNotProvidedInBothUrlAsWellAsAttributes() {
            HgMaterialConfig hgMaterialConfig = hg("http://bob:pass@example.com#some-branch", null);
            hgMaterialConfig.setBranchAttribute("branch-in-attribute");

            hgMaterialConfig.validate(new ConfigSaveValidationContext(null));

            assertThat(hgMaterialConfig.errors().on(HgMaterialConfig.URL)).isEqualTo("Ambiguous branch, must be provided either in URL or as an attribute.");
        }

        @Test
        void rejectsObviouslyWrongURL() {
            assertTrue(validating(hg("-url-not-starting-with-an-alphanumeric-character", "folder")).errors().containsKey(HgMaterialConfig.URL));
            assertTrue(validating(hg("_url-not-starting-with-an-alphanumeric-character", "folder")).errors().containsKey(HgMaterialConfig.URL));
            assertTrue(validating(hg("@url-not-starting-with-an-alphanumeric-character", "folder")).errors().containsKey(HgMaterialConfig.URL));

            assertFalse(validating(hg("url-starting-with-an-alphanumeric-character", "folder")).errors().containsKey(HgMaterialConfig.URL));
            // BUG: CWE-77 Improper Neutralization of Special Elements used in a Command ('Command Injection')
            // 
            // FIXED:  <fim-middle>         
            assertFalse(validating(hg("#{url}", "folder")).errors().containsKey(HgMaterialConfig.URL));
        }

        private HgMaterialConfig validating(HgMaterialConfig hg) {
         <fix-suffix>   hg.validate(new ConfigSaveValidationContext(null));
            return hg;
        }
    }

    @Nested
    class ValidateTree {
        @Test
        void shouldCallValidate() {
            final MaterialConfig materialConfig = spy(hg("https://example.repo", null));
            final ValidationContext validationContext = mockValidationContextForSecretParams();

            materialConfig.validateTree(validationContext);

            verify(materialConfig).validate(validationContext);
        }

        @Test
        void shouldFailIfEncryptedPasswordIsIncorrect() {
            HgMaterialConfig hgMaterialConfig = hg("http://example.com", null);
            hgMaterialConfig.setEncryptedPassword("encryptedPassword");

            final boolean validationResult = hgMaterialConfig.validateTree(new ConfigSaveValidationContext(null));

            assertThat(validationResult).isFalse();
            assertThat(hgMaterialConfig.errors().on("encryptedPassword"))
                    .isEqualT<|endoftext|>