Example usage for org.apache.commons.lang StringUtils remove

List of usage examples for org.apache.commons.lang StringUtils remove

Introduction

In this page you can find the example usage for org.apache.commons.lang StringUtils remove.

Prototype

public static String remove(String str, char remove) 

Source Link

Document

Removes all occurrences of a character from within the source string.

Usage

From source file:org.sonar.plugins.pmd.PmdProfileExporterTest.java

@Test
public void testExportXPathRule() {
    StringWriter xmlOutput = new StringWriter();
    RulesProfile profile = RulesProfile.create();
    Rule xpathTemplate = Rule.create(PmdConstants.REPOSITORY_KEY, "MyOwnRule", "This is my own xpath rule.")
            .setConfigKey(PmdConstants.XPATH_CLASS).setPluginName(PmdConstants.REPOSITORY_KEY);
    xpathTemplate.createParameter(PmdConstants.XPATH_EXPRESSION_PARAM);
    xpathTemplate.createParameter(PmdConstants.XPATH_MESSAGE_PARAM);
    ActiveRule xpath = profile.activateRule(xpathTemplate, null);
    xpath.setParameter(PmdConstants.XPATH_EXPRESSION_PARAM, "//FieldDeclaration");
    xpath.setParameter(PmdConstants.XPATH_MESSAGE_PARAM, "This is bad");
    exporter.exportProfile(profile, xmlOutput);
    assertEquals(TestUtils.getResourceContent("/org/sonar/plugins/pmd/export_xpath_rules.xml"),
            StringUtils.remove(xmlOutput.toString(), '\r'));
}

From source file:org.sonar.plugins.scmstats.AbstractScmAdapter.java

Resource createResource(String resourceName) {

    String mavenizedResourceName = StringUtils.remove(resourceName, configuration.getSourceDir());
    mavenizedResourceName = StringUtils.remove(mavenizedResourceName, configuration.getTestSourceDir());

    int index = StringUtils.lastIndexOf(mavenizedResourceName, "/");
    String directory = StringUtils.substring(mavenizedResourceName, 0, index);
    String filename = StringUtils.substring(mavenizedResourceName, index + 1);
    return new File(directory, filename);
}

From source file:org.sonar.plugins.scmstats.MavenScmConfiguration.java

private String getDir(String dir) {
    String baseDir = mavenProject.getBasedir().getAbsolutePath();
    String relativeBaseDir = StringUtils.remove(dir, baseDir).replace("\\", "/");
    if (relativeBaseDir.charAt(0) == '/') {
        relativeBaseDir = relativeBaseDir.substring(1);
    }//from   w  w  w . ja  va  2  s .  com
    return relativeBaseDir;
}

From source file:org.sonar.server.issue.notification.IssueChangesEmailTemplateTest.java

@Test
public void email_should_display_assignee_change() throws Exception {
    Notification notification = generateNotification().setFieldValue("old.assignee", "simon")
            .setFieldValue("new.assignee", "louis");

    EmailMessage email = underTest.format(notification);
    assertThat(email.getMessageId()).isEqualTo("issue-changes/ABCDE");
    assertThat(email.getSubject()).isEqualTo("Struts, change on issue #ABCDE");

    String message = email.getMessage();
    String expected = Resources.toString(Resources.getResource(
            "org/sonar/server/issue/notification/IssueChangesEmailTemplateTest/email_with_assignee_change.txt"),
            StandardCharsets.UTF_8);
    expected = StringUtils.remove(expected, '\r');
    assertThat(message).isEqualTo(expected);
    assertThat(email.getFrom()).isNull();
}

From source file:org.sonar.server.issue.notification.IssueChangesEmailTemplateTest.java

@Test
public void email_should_display_plan_change() throws Exception {
    Notification notification = generateNotification().setFieldValue("old.actionPlan", null)
            .setFieldValue("new.actionPlan", "ABC 1.0");

    EmailMessage email = underTest.format(notification);
    assertThat(email.getMessageId()).isEqualTo("issue-changes/ABCDE");
    assertThat(email.getSubject()).isEqualTo("Struts, change on issue #ABCDE");

    String message = email.getMessage();
    String expected = Resources.toString(Resources.getResource(
            "org/sonar/server/issue/notification/IssueChangesEmailTemplateTest/email_with_action_plan_change.txt"),
            StandardCharsets.UTF_8);
    expected = StringUtils.remove(expected, '\r');
    assertThat(message).isEqualTo(expected);
    assertThat(email.getFrom()).isNull();
}

From source file:org.sonar.server.issue.notification.IssueChangesEmailTemplateTest.java

@Test
public void email_should_display_resolution_change() throws Exception {
    Notification notification = generateNotification().setFieldValue("old.resolution", "FALSE-POSITIVE")
            .setFieldValue("new.resolution", "FIXED");

    EmailMessage email = underTest.format(notification);
    assertThat(email.getMessageId()).isEqualTo("issue-changes/ABCDE");
    assertThat(email.getSubject()).isEqualTo("Struts, change on issue #ABCDE");

    String message = email.getMessage();
    String expected = Resources.toString(Resources.getResource(
            "org/sonar/server/issue/notification/IssueChangesEmailTemplateTest/email_should_display_resolution_change.txt"),
            StandardCharsets.UTF_8);
    expected = StringUtils.remove(expected, '\r');
    assertThat(message).isEqualTo(expected);
    assertThat(email.getFrom()).isNull();
}

From source file:org.sonar.server.issue.notification.IssueChangesEmailTemplateTest.java

@Test
public void display_component_key_if_no_component_name() throws Exception {
    Notification notification = generateNotification().setFieldValue("componentName", null);

    EmailMessage email = underTest.format(notification);
    assertThat(email.getMessageId()).isEqualTo("issue-changes/ABCDE");
    assertThat(email.getSubject()).isEqualTo("Struts, change on issue #ABCDE");

    String message = email.getMessage();
    String expected = Resources.toString(Resources.getResource(
            "org/sonar/server/issue/notification/IssueChangesEmailTemplateTest/display_component_key_if_no_component_name.txt"),
            StandardCharsets.UTF_8);
    expected = StringUtils.remove(expected, '\r');
    assertThat(message).isEqualTo(expected);
}

From source file:org.sonar.server.issue.notification.IssueChangesEmailTemplateTest.java

@Test
public void test_email_with_multiple_changes() throws Exception {
    Notification notification = generateNotification().setFieldValue("comment", "How to fix it?")
            .setFieldValue("old.assignee", "simon").setFieldValue("new.assignee", "louis")
            .setFieldValue("new.resolution", "FALSE-POSITIVE").setFieldValue("new.status", "RESOLVED")
            .setFieldValue("new.type", "BUG").setFieldValue("new.tags", "bug performance");

    EmailMessage email = underTest.format(notification);
    assertThat(email.getMessageId()).isEqualTo("issue-changes/ABCDE");
    assertThat(email.getSubject()).isEqualTo("Struts, change on issue #ABCDE");

    String message = email.getMessage();
    String expected = Resources.toString(Resources.getResource(
            "org/sonar/server/issue/notification/IssueChangesEmailTemplateTest/email_with_multiple_changes.txt"),
            StandardCharsets.UTF_8);
    expected = StringUtils.remove(expected, '\r');
    assertThat(message).isEqualTo(expected);
    assertThat(email.getFrom()).isNull();
}

From source file:org.sonar.server.issue.notification.NewIssuesEmailTemplateTest.java

@Test
public void format_email_with_all_fields_filled() throws Exception {
    Notification notification = newNotification();
    addAssignees(notification);//w w w  . ja v  a  2s  .  c om
    addRules(notification);
    addTags(notification);
    addComponents(notification);

    EmailMessage message = template.format(notification);

    // TODO datetime to be completed when test is isolated from JVM timezone
    String expectedContent = IOUtils.toString(
            getClass().getResource("NewIssuesEmailTemplateTest/email_with_all_details.txt"),
            StandardCharsets.UTF_8);
    assertThat(message.getMessage()).startsWith(StringUtils.remove(expectedContent, '\r'));
}

From source file:org.sonar.server.issue.notification.NewIssuesEmailTemplateTest.java

@Test
public void format_email_with_no_assignees_tags_nor_components() throws Exception {
    Notification notification = newNotification();

    EmailMessage message = template.format(notification);

    // TODO datetime to be completed when test is isolated from JVM timezone
    String expectedContent = IOUtils.toString(
            getClass().getResource("NewIssuesEmailTemplateTest/email_with_partial_details.txt"),
            StandardCharsets.UTF_8);
    assertThat(message.getMessage()).startsWith(StringUtils.remove(expectedContent, '\r'));
}