Exemple #1
0
 @AfterClass(alwaysRun = true)
 protected void nullifyInstanceFields() {
   for (Class<?> current = this.getClass();
       current.getSuperclass() != null;
       current = current.getSuperclass()) {
     Field[] fields = current.getDeclaredFields();
     for (Field f : fields) {
       try {
         if (!Modifier.isStatic(f.getModifiers()) && !f.getDeclaringClass().isPrimitive()) {
           f.setAccessible(true);
           f.set(this, null);
         }
       } catch (Exception e) {
       }
     }
   }
 }
Exemple #2
0
  /** Returns a set of tests to run for varied log configurations. */
  protected Object[] testsFor(Class<? extends LogTest> testClass) throws Throwable {
    List<Object> tests = new ArrayList<>();
    for (int i = 1; i < 10; i++) {
      LogTest test = testClass.newInstance();
      test.entriesPerSegment = i;
      test.entryPadding = i / 3;
      tests.add(test);
    }

    return tests.toArray(new Object[tests.size()]);
  }
  public boolean setConnection(String url, String dbName, String userName, String password)
      throws Exception {

    // Declare status as false by default
    boolean dbStatus = true;

    try {
      Class.forName(driver).newInstance();
      conn = DriverManager.getConnection(url + dbName, userName, password);
    } catch (InstantiationException e) {
      // If catch block execute it will set the dbStatus flase
      dbStatus = false;
    }
    return dbStatus;
  }
  @Test
  public void estConnection() throws IllegalAccessException, ClassNotFoundException, SQLException {

    Connection conn = null;
    String url = "jdbc:mysql://localhost:3306/";
    String driver = "com.mysql.jdbc.Driver";
    String dbName = "sakila";
    String userName = "******";
    String password = "******";

    try {

      // This will create Object of Driver class
      Class.forName(driver).newInstance();
      conn = DriverManager.getConnection(url + dbName, userName, password);

    } catch (InstantiationException e) {
      System.out.println("Connection failed");
      e.printStackTrace();
    }
  }