Revert "SQOOP-3100: Clean up expected exception logic in tests - part III."

This reverts commit 150843b26414ece3d9076c56c7d9caed63529380.

I've mistakenly committed the previous change with incorrect author
information, and would not like to break any toolchain by rewriting the
history, thus I'm reverting this, and committing again the change with
proper header information

(Attila Szabo)
diff --git a/ivy/libraries.properties b/ivy/libraries.properties
index 84b834b..05baa5c 100644
--- a/ivy/libraries.properties
+++ b/ivy/libraries.properties
@@ -36,7 +36,7 @@
 
 ivy.version=2.3.0
 
-junit.version=4.12
+junit.version=4.11
 mockito-all.version=1.9.5
 
 h2.version=1.3.170
diff --git a/src/test/com/cloudera/sqoop/TestIncrementalImport.java b/src/test/com/cloudera/sqoop/TestIncrementalImport.java
index 52a55b7..57f4433 100644
--- a/src/test/com/cloudera/sqoop/TestIncrementalImport.java
+++ b/src/test/com/cloudera/sqoop/TestIncrementalImport.java
@@ -49,9 +49,7 @@
 import com.cloudera.sqoop.tool.ImportTool;
 import com.cloudera.sqoop.tool.JobTool;
 import org.junit.Before;
-import org.junit.Rule;
 import org.junit.Test;
-import org.junit.rules.ExpectedException;
 
 
 import static org.junit.Assert.*;
@@ -72,9 +70,6 @@
   // What database do we read from.
   public static final String SOURCE_DB_URL = "jdbc:hsqldb:mem:incremental";
 
-  @Rule
-  public ExpectedException thrown = ExpectedException.none();
-
   @Before
   public void setUp() throws Exception {
     // Delete db state between tests.
@@ -954,12 +949,14 @@
     List<String> args = getArgListForTable(TABLE_NAME, false, true);
     args.add("--append");
     createJob(TABLE_NAME, args);
-
-    thrown.expect(RuntimeException.class);
-    thrown.reportMissingExceptionWithMessage("Expected incremental import on varchar column to fail");
-    runJob(TABLE_NAME);
+    try {
+      runJob(TABLE_NAME);
+      //the above line should throw an exception otherwise the test has failed
+      fail("Expected incremental import on varchar column to fail.");
+    } catch(RuntimeException e) {
+      //expected
+    }
   }
-
   @Test
   public void testModifyWithTimestamp() throws Exception {
     // Create a table with data in it; import it.
diff --git a/src/test/com/cloudera/sqoop/lib/TestRecordParser.java b/src/test/com/cloudera/sqoop/lib/TestRecordParser.java
index d964cef..57bdb5f 100644
--- a/src/test/com/cloudera/sqoop/lib/TestRecordParser.java
+++ b/src/test/com/cloudera/sqoop/lib/TestRecordParser.java
@@ -20,10 +20,7 @@
 
 import java.util.ArrayList;
 import java.util.List;
-
-import org.junit.Rule;
 import org.junit.Test;
-import org.junit.rules.ExpectedException;
 
 import static org.junit.Assert.fail;
 
@@ -33,9 +30,6 @@
  */
 public class TestRecordParser {
 
-  @Rule
-  public ExpectedException thrown = ExpectedException.none();
-
   private void assertListsEqual(String msg, List<String> expected,
       List<String> actual) {
     if (expected == null && actual != null) {
@@ -306,41 +300,49 @@
   public void testRequiredQuotes2() throws RecordParser.ParseError {
     RecordParser parser = new RecordParser(
         new DelimiterSet(',', '\n', '\"', '\\', true));
-
-    thrown.expect(RecordParser.ParseError.class);
-    thrown.reportMissingExceptionWithMessage("Expected parse error for required quotes");
-    parser.parseRecord("\"field1\",field2");
+    try {
+      parser.parseRecord("\"field1\",field2");
+      fail("Expected parse error for required quotes");
+    } catch (RecordParser.ParseError pe) {
+      // ok. expected.
+    }
   }
 
   @Test
   public void testRequiredQuotes3() throws RecordParser.ParseError {
     RecordParser parser = new RecordParser(
         new DelimiterSet(',', '\n', '\"', '\\', true));
-
-    thrown.expect(RecordParser.ParseError.class);
-    thrown.reportMissingExceptionWithMessage("Expected ParseError for required quotes");
-    parser.parseRecord("field1,\"field2\"");
+    try {
+      parser.parseRecord("field1,\"field2\"");
+      fail("Expected parse error for required quotes");
+    } catch (RecordParser.ParseError pe) {
+      // ok. expected.
+    }
   }
 
   @Test
   public void testRequiredQuotes4() throws RecordParser.ParseError {
     RecordParser parser = new RecordParser(
         new DelimiterSet(',', '\n', '\"', '\\', true));
-
-    thrown.expect(RecordParser.ParseError.class);
-    thrown.reportMissingExceptionWithMessage("Expected ParseError for required quotes");
-    parser.parseRecord("field1,\"field2\"\n");
+    try {
+      parser.parseRecord("field1,\"field2\"\n");
+      fail("Expected parse error for required quotes");
+    } catch (RecordParser.ParseError pe) {
+      // ok. expected.
+    }
   }
 
   @Test
-  public void testNull() throws RecordParser.ParseError {
+  public void testNull() {
     RecordParser parser = new RecordParser(
         new DelimiterSet(',', '\n', '\"', '\\', true));
     String input = null;
-
-    thrown.expect(RecordParser.ParseError.class);
-    thrown.reportMissingExceptionWithMessage("Expected ParseError for null string");
-    parser.parseRecord(input);
+    try {
+      parser.parseRecord(input);
+      fail("Expected parse error for null string");
+    } catch (RecordParser.ParseError pe) {
+      // ok. expected.
+    }
   }
 
 
diff --git a/src/test/com/cloudera/sqoop/metastore/TestSavedJobs.java b/src/test/com/cloudera/sqoop/metastore/TestSavedJobs.java
index 61d8c97..1fb7324 100644
--- a/src/test/com/cloudera/sqoop/metastore/TestSavedJobs.java
+++ b/src/test/com/cloudera/sqoop/metastore/TestSavedJobs.java
@@ -33,14 +33,13 @@
 import com.cloudera.sqoop.tool.VersionTool;
 
 import org.junit.Before;
-import org.junit.Rule;
 import org.junit.Test;
-import org.junit.rules.ExpectedException;
 
 import java.io.IOException;
 import java.sql.Connection;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
 
 /**
  * Test the metastore and job-handling features.
@@ -56,9 +55,6 @@
   public static final String TEST_AUTOCONNECT_USER = "SA";
   public static final String TEST_AUTOCONNECT_PASS = "";
 
-  @Rule
-  public ExpectedException thrown = ExpectedException.none();
-
   @Before
   public void setUp() throws Exception {
     // Delete db state between tests.
@@ -122,7 +118,7 @@
   }
 
   @Test
-  public void testCreateSameJob() throws IOException {
+  public void testCreateDeleteJob() throws IOException {
     Configuration conf = newConf();
     JobStorageFactory ssf = new JobStorageFactory(conf);
 
@@ -143,45 +139,29 @@
     assertEquals(1, jobs.size());
     assertEquals("versionJob", jobs.get(0));
 
+    // Try to create that same job name again. This should fail.
     try {
-      // Try to create that same job name again. This should fail.
-      thrown.expect(IOException.class);
-      thrown.reportMissingExceptionWithMessage("Expected IOException since job already exists");
       storage.create("versionJob", data);
-    } finally {
-      jobs = storage.list();
-      assertEquals(1, jobs.size());
-
-      // Restore our job, check that it exists.
-      JobData outData = storage.read("versionJob");
-      assertEquals(new VersionTool().getToolName(),
-          outData.getSqoopTool().getToolName());
-
-      storage.close();
+      fail("Expected IOException; this job already exists.");
+    } catch (IOException ioe) {
+      // This is expected; continue operation.
     }
-  }
-
-  @Test
-  public void testDeleteJob() throws IOException {
-    Configuration conf = newConf();
-    JobStorageFactory ssf = new JobStorageFactory(conf);
-
-    Map<String, String> descriptor = new TreeMap<String, String>();
-    JobStorage storage = ssf.getJobStorage(descriptor);
-
-    storage.open(descriptor);
-
-    // Job list should start out empty.
-    List<String> jobs = storage.list();
-    assertEquals(0, jobs.size());
-
-    // Create a job that displays the version.
-    JobData data = new JobData(new SqoopOptions(), new VersionTool());
-    storage.create("versionJob", data);
 
     jobs = storage.list();
     assertEquals(1, jobs.size());
-    assertEquals("versionJob", jobs.get(0));
+
+    // Restore our job, check that it exists.
+    JobData outData = storage.read("versionJob");
+    assertEquals(new VersionTool().getToolName(),
+        outData.getSqoopTool().getToolName());
+
+    // Try to restore a job that doesn't exist. Watch it fail.
+    try {
+      storage.read("DoesNotExist");
+      fail("Expected IOException");
+    } catch (IOException ioe) {
+      // This is expected. Continue.
+    }
 
     // Now delete the job.
     storage.delete("versionJob");
@@ -194,26 +174,6 @@
   }
 
   @Test
-  public void testRestoreNonExistingJob() throws IOException {
-    Configuration conf = newConf();
-    JobStorageFactory ssf = new JobStorageFactory(conf);
-
-    Map<String, String> descriptor = new TreeMap<String, String>();
-    JobStorage storage = ssf.getJobStorage(descriptor);
-
-    storage.open(descriptor);
-
-    try {
-      // Try to restore a job that doesn't exist. Watch it fail.
-      thrown.expect(IOException.class);
-      thrown.reportMissingExceptionWithMessage("Expected IOException since job doesn't exist");
-      storage.read("DoesNotExist");
-    } finally {
-      storage.close();
-    }
-  }
-
-  @Test
     public void testCreateJobWithExtraArgs() throws IOException {
         Configuration conf = newConf();
         JobStorageFactory ssf = new JobStorageFactory(conf);
diff --git a/src/test/com/cloudera/sqoop/orm/TestClassWriter.java b/src/test/com/cloudera/sqoop/orm/TestClassWriter.java
index b3a8a17..a27353d 100644
--- a/src/test/com/cloudera/sqoop/orm/TestClassWriter.java
+++ b/src/test/com/cloudera/sqoop/orm/TestClassWriter.java
@@ -36,7 +36,6 @@
 import org.apache.hadoop.util.Shell;
 import org.junit.After;
 import org.junit.Before;
-import org.junit.Rule;
 import org.junit.Test;
 
 import com.cloudera.sqoop.SqoopOptions;
@@ -47,7 +46,6 @@
 import com.cloudera.sqoop.testutil.ImportJobTestCase;
 import com.cloudera.sqoop.tool.ImportTool;
 import com.cloudera.sqoop.util.ClassLoaderStack;
-import org.junit.rules.ExpectedException;
 
 import java.lang.reflect.Field;
 
@@ -74,9 +72,6 @@
   private ConnManager manager;
   private SqoopOptions options;
 
-  @Rule
-  public ExpectedException thrown = ExpectedException.none();
-
   @Before
   public void setUp() {
     testServer = new HsqldbTestServer();
@@ -647,6 +642,31 @@
     fail("we shouldn't successfully generate code");
   }
 
+  private void runFailedGenerationTest(String [] argv,
+      String classNameToCheck) {
+    File codeGenDirFile = new File(CODE_GEN_DIR);
+    File classGenDirFile = new File(JAR_GEN_DIR);
+
+    try {
+      options = new ImportTool().parseArguments(argv,
+          null, options, true);
+    } catch (Exception e) {
+      LOG.error("Could not parse options: " + e.toString());
+    }
+
+    CompilationManager compileMgr = new CompilationManager(options);
+    ClassWriter writer = new ClassWriter(options, manager,
+        HsqldbTestServer.getTableName(), compileMgr);
+
+    try {
+      writer.generate();
+      compileMgr.compile();
+      fail("ORM class file generation succeeded when it was expected to fail");
+    } catch (Exception ioe) {
+      LOG.error("Got Exception from ORM generation as expected : "
+        + ioe.toString());
+    }
+  }
   /**
    * A dummy manager that declares that it ORM is self managed.
    */
@@ -666,22 +686,7 @@
       "--outdir",
       CODE_GEN_DIR,
     };
-
-    try {
-      options = new ImportTool().parseArguments(argv,
-          null, options, true);
-    } catch (Exception e) {
-      LOG.error("Could not parse options: " + e.toString());
-    }
-
-    CompilationManager compileMgr = new CompilationManager(options);
-    ClassWriter writer = new ClassWriter(options, manager,
-        HsqldbTestServer.getTableName(), compileMgr);
-
-    writer.generate();
-
-    thrown.expect(Exception.class);
-    compileMgr.compile();
+    runFailedGenerationTest(argv, HsqldbTestServer.getTableName());
   }
 
   @Test(timeout = 25000)