View Javadoc
1   package org.jastacry.test;
2   
3   import static org.junit.Assert.assertTrue;
4   
5   import java.io.ByteArrayOutputStream;
6   import java.io.PrintStream;
7   import java.util.Locale;
8   
9   import org.jastacry.JaStaCry;
10  import org.junit.jupiter.api.AfterEach;
11  import org.junit.jupiter.api.BeforeEach;
12  import org.junit.jupiter.api.Test;
13  
14  /**
15   * Test of locale functions.
16   *
17   * @author Kai Kretschmann
18   *
19   */
20  public class TestLocale
21  {
22      private final ByteArrayOutputStream outContent = new ByteArrayOutputStream();
23      private final ByteArrayOutputStream errContent = new ByteArrayOutputStream();
24      private final PrintStream originalOut = System.out;
25      private final PrintStream originalErr = System.err;
26  
27      @BeforeEach
28      public void setUpStreams() {
29          System.setOut(new PrintStream(outContent));
30          System.setErr(new PrintStream(errContent));
31      }
32  
33      @AfterEach
34      public void restoreStreams() {
35          System.setOut(originalOut);
36          System.setErr(originalErr);
37      }
38  
39      /**
40       * Test method help for Main function in english.
41       *
42       */
43      @Test
44      public void testMainHelpEN()
45      {
46          final String[] sArguments = {
47              "-h"
48          };
49          Locale englishLocale = new Locale("en", "GB");
50          Locale.setDefault(englishLocale);
51      
52          JaStaCry.mainMethod(sArguments);
53          String sOut = outContent.toString();
54          boolean bFound = sOut.contains("show some help");
55          assertTrue("Locale", bFound);
56      }
57  
58      /**
59       * Test method help for Main function in german.
60       *
61       */
62      @Test
63      public void testMainHelpDE()
64      {
65          final String[] sArguments = {
66              "-h"
67          };
68          Locale germanLocale = new Locale("de", "DE");
69          Locale.setDefault(germanLocale);
70  
71          JaStaCry.mainMethod(sArguments);
72          String sOut = outContent.toString();
73          boolean bFound = sOut.contains("zeige Hilfe an");
74          assertTrue("Locale", bFound);
75      }
76  
77  }