22
22
import org .junit .Test ;
23
23
24
24
import com .adobe .epubcheck .api .EpubCheck ;
25
- import com .adobe .epubcheck .tool .Checker ;
25
+ import com .adobe .epubcheck .tool .EpubChecker ;
26
26
import com .adobe .epubcheck .util .Messages ;
27
27
28
28
public class CommandLineTest
@@ -35,7 +35,6 @@ public class CommandLineTest
35
35
private final ByteArrayOutputStream outContent = new ByteArrayOutputStream ();
36
36
private final ByteArrayOutputStream errContent = new ByteArrayOutputStream ();
37
37
38
- private SecurityManager originalManager ;
39
38
private PrintStream originalOut ;
40
39
private PrintStream originalErr ;
41
40
private final Messages messages = Messages .getInstance (Locale .ENGLISH );
@@ -46,8 +45,6 @@ public void setUp()
46
45
{
47
46
defaultLocale = Locale .getDefault ();
48
47
Locale .setDefault (Locale .ENGLISH );
49
- this .originalManager = System .getSecurityManager ();
50
- System .setSecurityManager (new NoExitSecurityManager ());
51
48
originalOut = System .out ;
52
49
originalErr = System .err ;
53
50
System .setOut (new PrintStream (outContent ));
@@ -58,7 +55,6 @@ public void setUp()
58
55
public void tearDown ()
59
56
{
60
57
Locale .setDefault (defaultLocale );
61
- System .setSecurityManager (this .originalManager );
62
58
System .setOut (originalOut );
63
59
System .setErr (originalErr );
64
60
}
@@ -292,14 +288,7 @@ public void missingTranslationShouldFallbackTest()
292
288
Locale .setDefault (Locale .FRANCE );
293
289
294
290
URL inputUrl = CommandLineTest .class .getResource ("valid.epub" );
295
-
296
- try
297
- {
298
- Checker .main (new String [] { inputUrl .getPath (), "--locale" , "ar-eg" });
299
- } catch (NoExitSecurityManager .ExitException e )
300
- {
301
- assertEquals ("Return code should be zero" , 0 , e .status );
302
- }
291
+ runCommandLineTest (0 , inputUrl .getPath (), "--locale" , "ar-eg" );
303
292
304
293
assertTrue ("Valid Locale without translation should fallback to JVM default." ,
305
294
outContent .toString ().contains ("faites en utilisant" ));
@@ -345,13 +334,7 @@ public void incorrectLocaleShouldFailTest()
345
334
346
335
URL inputUrl = CommandLineTest .class .getResource ("valid.epub" );
347
336
348
- try
349
- {
350
- Checker .main (new String [] { inputUrl .getPath (), "--locale" , "foobar" });
351
- } catch (NoExitSecurityManager .ExitException e )
352
- {
353
- assertEquals ("Return code should be zero" , 0 , e .status );
354
- }
337
+ runCommandLineTest (0 , inputUrl .getPath (), "--locale" , "foobar" );
355
338
356
339
assertTrue ("Invalid Locale should use JVM default." ,
357
340
outContent .toString ().contains ("faites en utilisant" ));
@@ -756,18 +739,11 @@ public void xmpFileTest()
756
739
}
757
740
}
758
741
759
- public static void runCommandLineTest (int expectedReturnCode , String ... args )
742
+ public void runCommandLineTest (int expectedReturnCode , String ... args )
760
743
{
761
- int result = Integer .MAX_VALUE ;
762
- try
763
- {
764
- Checker .main (args );
765
- } catch (NoExitSecurityManager .ExitException e )
766
- {
767
- result = e .status ;
768
- }
769
744
770
- assertEquals ("Return code" , expectedReturnCode , result );
745
+ int returnCode = new EpubChecker ().run (args );
746
+ assertEquals ("Return code" , expectedReturnCode , returnCode );
771
747
}
772
748
773
749
}
0 commit comments