Package edu.zao.fire

Examples of edu.zao.fire.MatchReplaceRule


    return file;
  }

  @Test
  public void serializeRule() throws FileNotFoundException, IOException {
    MatchReplaceRule rule = new MatchReplaceRule();
    rule.setMatchString("hello");
    rule.setCapitalizationState(CapitalizationStyle.SENTENCE);
    rule.setReplaceString("goodbye");

    File savedRuleFile = makeTempFile("savedRule.rule");
    ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(savedRuleFile));
    oos.writeObject(rule);
    oos.close();
View Full Code Here


  @Test
  public void deserializeRule() throws FileNotFoundException, IOException, ClassNotFoundException {
    File savedRuleFile = makeTempFile("savedRule.rule");
    ObjectInputStream ois = new ObjectInputStream(new FileInputStream(savedRuleFile));

    MatchReplaceRule rule = (MatchReplaceRule) ois.readObject();
    assertTrue(rule.getMatchString().equals("hello"));
    assertTrue(rule.getCapitalizationState() == CapitalizationStyle.SENTENCE);
    assertTrue(rule.getReplaceString().equals("goodbye"));
  }
View Full Code Here

    return file;
  }

  @Test
  public void testGetNewName_NoModifications() {
    MatchReplaceRule rule = new MatchReplaceRule();
    rule.setMatchString("aaa");
    rule.setReplaceString("bbb");

    File aaaFile = new File("aaaaaa.txt");
    try {
      String newName = rule.getNewName(aaaFile);
      assertTrue(newName.equals("bbbaaa.txt"));
    } catch (IOException e) {
      fail("Should not throw an exception");
      e.printStackTrace();
    }
View Full Code Here

    }
  }

  @Test
  public void testGetNewName_MatchAll() {
    MatchReplaceRule rule = new MatchReplaceRule();
    rule.setMatchString("aaa");
    rule.setReplaceString("bbb");
    rule.setReplacementLimit(ReplacementLimit.ALL);

    File aaaFile = new File("aaaaaa.txt");
    try {
      String newName = rule.getNewName(aaaFile);
      assertTrue(newName.equals("bbbbbb.txt"));
    } catch (IOException e) {
      fail("Should not throw an exception");
      e.printStackTrace();
    }
View Full Code Here

    }
  }

  @Test
  public void testGetNewName_Regex_First() {
    MatchReplaceRule rule = new MatchReplaceRule();
    rule.setMatchString("[ab]");
    rule.setReplaceString("c");
    rule.setMatchRegularExpressions(true);

    File aaaFile = new File("ababab.txt");
    try {
      String newName = rule.getNewName(aaaFile);
      assertTrue(newName.equals("cbabab.txt"));
    } catch (IOException e) {
      fail("Should not throw an exception");
      e.printStackTrace();
    }
View Full Code Here

    }
  }

  @Test
  public void testGetNewName_Regex_All() {
    MatchReplaceRule rule = new MatchReplaceRule();
    rule.setMatchString("[ab]");
    rule.setReplaceString("c");
    rule.setMatchRegularExpressions(true);
    rule.setReplacementLimit(ReplacementLimit.ALL);

    File aaaFile = new File("ababab.txt");
    try {
      String newName = rule.getNewName(aaaFile);
      assertTrue(newName.equals("cccccc.txt"));
    } catch (IOException e) {
      fail("Should not throw an exception");
      e.printStackTrace();
    }
View Full Code Here

    }
  }

  @Test
  public void testGetNewName_Capitalization_All() {
    MatchReplaceRule rule = new MatchReplaceRule();
    rule.setCapitalizationState(CapitalizationStyle.ALL_CAPS);

    File aaaFile = new File("ababab.txt");
    try {
      String newName = rule.getNewName(aaaFile);
      assertTrue(newName.equals("ABABAB.TXT"));
    } catch (IOException e) {
      fail("Should not throw an exception");
      e.printStackTrace();
    }
View Full Code Here

    }
  }

  @Test
  public void testGetNewName_Capitalization_Title() {
    MatchReplaceRule rule = new MatchReplaceRule();
    rule.setCapitalizationState(CapitalizationStyle.TITLE);

    File aaaFile = new File("aba bab.txt");
    try {
      String newName = rule.getNewName(aaaFile);
      assertTrue(newName.equals("Aba Bab.txt"));
    } catch (IOException e) {
      fail("Should not throw an exception");
      e.printStackTrace();
    }
View Full Code Here

    }
  }

  @Test
  public void testGetNewName_Capitalization_Sentence() {
    MatchReplaceRule rule = new MatchReplaceRule();
    rule.setCapitalizationState(CapitalizationStyle.SENTENCE);

    File aaaFile = new File("aba bab.txt");
    try {
      String newName = rule.getNewName(aaaFile);
      assertTrue(newName.equals("Aba bab.txt"));
    } catch (IOException e) {
      fail("Should not throw an exception");
      e.printStackTrace();
    }
View Full Code Here

    }
  }

  @Test
  public void testGetNewName_Capitalization_NoCaps() {
    MatchReplaceRule rule = new MatchReplaceRule();
    rule.setCapitalizationState(CapitalizationStyle.NO_CAPS);

    File aaaFile = new File("AbA BAb.txt");
    try {
      String newName = rule.getNewName(aaaFile);
      assertTrue(newName.equals("aba bab.txt"));
    } catch (IOException e) {
      fail("Should not throw an exception");
      e.printStackTrace();
    }
View Full Code Here

TOP

Related Classes of edu.zao.fire.MatchReplaceRule

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.