This is an automated email from the ASF dual-hosted git repository.

ebourg pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tomcat-jakartaee-migration.git

commit c4e5c1840652d44523b38b49c3057187bfef0efb
Author: Emmanuel Bourg <ebo...@apache.org>
AuthorDate: Tue Apr 7 02:52:51 2020 +0200

    Test invalid options
---
 .../org/apache/tomcat/jakartaee/MigrationTest.java | 25 +++++++++++++++
 .../tomcat/jakartaee/NoExitSecurityManager.java    | 36 ++++++++++++++++++++++
 2 files changed, 61 insertions(+)

diff --git a/src/test/java/org/apache/tomcat/jakartaee/MigrationTest.java 
b/src/test/java/org/apache/tomcat/jakartaee/MigrationTest.java
index 80e595d..8ed7f81 100644
--- a/src/test/java/org/apache/tomcat/jakartaee/MigrationTest.java
+++ b/src/test/java/org/apache/tomcat/jakartaee/MigrationTest.java
@@ -20,12 +20,24 @@ package org.apache.tomcat.jakartaee;
 import java.io.File;
 
 import org.apache.commons.io.FileUtils;
+import org.junit.After;
+import org.junit.Before;
 import org.junit.Test;
 
 import static org.junit.Assert.*;
 
 public class MigrationTest {
 
+    @Before
+    public void setUp() {
+        System.setSecurityManager(new NoExitSecurityManager());
+    }
+
+    @After
+    public void tearDown() {
+        System.setSecurityManager(null);
+    }
+
     @Test
     public void testMigrateSingleSourceFile() throws Exception {
         File migratedFile = new 
File("target/test-classes/HelloServlet.migrated.java");
@@ -64,4 +76,17 @@ public class MigrationTest {
         assertFalse("Imports not migrated", migratedSource.contains("import 
javax.servlet"));
         assertTrue("Migrated imports not found", 
migratedSource.contains("import jakarta.servlet"));
     }
+
+    @Test
+    public void testInvalidOption() throws Exception {
+        File sourceFile = new File("target/test-classes/HelloServlet.java");
+        File migratedFile = new 
File("target/test-classes/HelloServlet.migrated.java");
+
+        try {
+            Migration.main(new String[] {"-invalid", 
sourceFile.getAbsolutePath(), migratedFile.getAbsolutePath()});
+            fail("No error code returned");
+        } catch (SecurityException e) {
+            assertEquals("error code", "1", e.getMessage());
+        }
+    }
 }
diff --git 
a/src/test/java/org/apache/tomcat/jakartaee/NoExitSecurityManager.java 
b/src/test/java/org/apache/tomcat/jakartaee/NoExitSecurityManager.java
new file mode 100644
index 0000000..446e96c
--- /dev/null
+++ b/src/test/java/org/apache/tomcat/jakartaee/NoExitSecurityManager.java
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.tomcat.jakartaee;
+
+import java.security.Permission;
+
+public class NoExitSecurityManager extends SecurityManager {
+
+    @Override
+    public void checkPermission(Permission perm) {
+    }
+
+    @Override
+    public void checkPermission(Permission perm, Object context) {
+    }
+    
+    @Override
+    public void checkExit(int status) {
+        throw new SecurityException("" + status);
+    }
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to