Untitled

mail@pastecode.io avatar
unknown
plain_text
7 months ago
1.9 kB
1
Indexable
Never
import com.amazon.grcs.icas.text.analysis.model.PatternReplacement;
import org.junit.jupiter.api.Test;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import static org.junit.jupiter.api.Assertions.assertEquals;

class AttrAwarePatternTextCleanerTest {

    @Test
    void clean_shouldReturnCleanedTextForIncludedAttr() {
        // Arrange
        List<PatternReplacement> patternReplacements = new ArrayList<>();
        patternReplacements.add(new PatternReplacement("pattern1", "replacement1"));
        patternReplacements.add(new PatternReplacement("pattern2", "replacement2"));

        Set<String> excludedAttrs = new HashSet<>();
        excludedAttrs.add("attr1");
        excludedAttrs.add("attr2");

        AttrAwarePatternTextCleaner cleaner = new AttrAwarePatternTextCleaner(patternReplacements, excludedAttrs);

        // Act
        String cleanedText = cleaner.clean("text with pattern1 and pattern2", "attr3");

        // Assert
        assertEquals("text with replacement1 and replacement2", cleanedText);
    }

    @Test
    void clean_shouldReturnOriginalTextForExcludedAttr() {
        // Arrange
        List<PatternReplacement> patternReplacements = new ArrayList<>();
        patternReplacements.add(new PatternReplacement("pattern1", "replacement1"));
        patternReplacements.add(new PatternReplacement("pattern2", "replacement2"));

        Set<String> excludedAttrs = new HashSet<>();
        excludedAttrs.add("attr1");
        excludedAttrs.add("attr2");

        AttrAwarePatternTextCleaner cleaner = new AttrAwarePatternTextCleaner(patternReplacements, excludedAttrs);

        // Act
        String cleanedText = cleaner.clean("text with pattern1 and pattern2", "attr1");

        // Assert
        assertEquals("text with pattern1 and pattern2", cleanedText);
    }
}