Пример #1
0
  @Test
  public void forUnsupportedLanguageShouldGetAWarningMessage() throws Exception {
    // given
    String[] command = new String[] {"--dic=gUnsupported"};
    CommandLineToStatusClassWrapper commandLineToStatusClassWrapper =
        new CommandLineToStatusClassWrapper(command, mapMockedDictionaries, outStream);
    Translator translator =
        new Translator(mapMockedDictionaries, browserActivator, commandLineToStatusClassWrapper);

    // when
    translator.doAction();

    // then
    Assert.assertTrue(
        outStream.getContent(), outStream.getContent().contains("unresolved dictionary"));
  }
Пример #2
0
  @Test
  public void canReadFromInputFile() throws Exception {
    // given
    // String[] command = new String[]{"--dic=gDic", "--oriLang=it", "--targetLang=en",
    // "--inFile=infile"};
    String[] command = new String[] {"--dic=gDic", "--oriLang=it", "--targetLang=en"};
    CommandLineToStatusClassWrapper commandLineToStatusClassWrapper =
        new CommandLineToStatusClassWrapper(command, mapMockedDictionaries, outStream);

    InputStream inputStream =
        new InputStream() {
          int count = 0;

          public String next() {
            if (count++ < 3) return "hi";
            else return null;
          }
        };

    Translator translator =
        new Translator(mapMockedDictionaries, browserActivator, commandLineToStatusClassWrapper);

    // translator.setCommand(new String[]{"--dic=gDic", "--oriLang=it", "--targetLang=en",
    // "--inFile=infile"});
    // translator.setInputStream(inputStream);

    // when
    translator.doAction();

    // then
    Assert.assertTrue(outStream.getContent().contains("salut"));
  }
Пример #3
0
  @Test
  public void helpCommandShouldReturnAvailablesDictionaries() throws Exception {
    mapMockedDictionaries.put(
        "myDic",
        new GenericDictionary(
            "myDic",
            (new ContentProvider() {
              public String retrieve(String word, String langIn, String langOut) throws Exception {
                return null; // To change body of implemented methods use File | Settings | File
                             // Templates.
              }

              public String supportedLanguges() {
                return null; // To change body of implemented methods use File | Settings | File
                             // Templates.
              }

              public String getInfoUrl() {
                return null; // To change body of implemented methods use File | Settings | File
                             // Templates.
              }
            }),
            new ContentFilter() {
              public String filter(String content, String langIn, String langOut) {
                return null; // To change body of implemented methods use File | Settings | File
                             // Templates.
              }
            }));

    String[] command = new String[] {"--help"};
    // CommandLineToStatusClassWrapper commandLineToStatusClassWrapper = new
    // CommandLineToStatusClassWrapper(command,mapMockedDictionaries);
    CommandLineToStatusClassWrapper commandLineToStatusClassWrapper =
        new CommandLineToStatusClassWrapper(command, mapMockedDictionaries, outStream);
    Translator translator =
        new Translator(mapMockedDictionaries, browserActivator, commandLineToStatusClassWrapper);

    // translator.setCommand(new String[]{"--help"});
    translator.doAction();

    Assert.assertTrue(outStream.getContent().contains("gApi"));
    Assert.assertTrue(outStream.getContent().contains("gDic"));
    Assert.assertTrue(outStream.getContent().contains("myDic"));
  }
Пример #4
0
  @Test
  public void canGetThePlainLanguageNameRefactor() throws Exception {
    // given
    String[] command = new String[] {"--dic=gApi", "--languages"};
    CommandLineToStatusClassWrapper clMapper =
        new CommandLineToStatusClassWrapper(command, mapMockedDictionaries, outStream);
    Translator translator = new Translator(mapMockedDictionaries, browserActivator, clMapper);

    // when
    translator.doAction();

    // then
    Assert.assertTrue(
        "extend languages description is not contained",
        outStream.getContent().toLowerCase().contains("italian"));
  }
Пример #5
0
  @Test
  public void canReadFromInputFileMultipleLines() throws Exception {
    // given
    // String[] command = new String[]{"--dic=gDic", "--oriLang=it", "--targetLang=en",
    // "--inFile=infile"};
    String[] command = new String[] {"--dic=gDic", "--oriLang=it", "--targetLang=en"};
    CommandLineToStatusClassWrapper commandLineToStatusClassWrapper =
        new CommandLineToStatusClassWrapper(command, mapMockedDictionaries, outStream);
    Translator translator =
        new Translator(mapMockedDictionaries, browserActivator, commandLineToStatusClassWrapper);

    // when
    // translator.setCommand(new String[]{"--dic=gDic", "--oriLang=it", "--targetLang=en",
    // "--inFile=infile"});
    translator.doAction();

    // then
    Assert.assertTrue(outStream.getContent().contains("salut!"));
    Assert.assertTrue(outStream.getContent().contains("\n"));
  }