Example usage for java.lang AssertionError AssertionError

List of usage examples for java.lang AssertionError AssertionError

Introduction

In this page you can find the example usage for java.lang AssertionError AssertionError.

Prototype

public AssertionError(double detailMessage) 

Source Link

Document

Constructs an AssertionError with its detail message derived from the specified double, which is converted to a string as defined in section 15.18.1.1 of The Java™ Language Specification.

Usage

From source file:com.gatf.executor.dataprovider.SQLDatabaseTestDataSource.java

public void init() {
    Thread currentThread = Thread.currentThread();
    ClassLoader oldClassLoader = currentThread.getContextClassLoader();
    try {/*from   w  w  w  .j a va 2 s .c  om*/
        currentThread.setContextClassLoader(getProjectClassLoader());
        if (args == null || args.length == 0) {
            throw new AssertionError("No arguments passed to the DatabaseProvider");
        }

        if (args.length < 4) {
            throw new AssertionError("All 4 arguments, namely jdbcUrl, jdbcDriver, dbUserName and"
                    + "dbPassword are mandatory for DatabaseProvider");
        }

        Assert.assertNotNull("jdbcUrl cannot be empty", args[0]);
        Assert.assertNotNull("jdbcDriver cannot be empty", args[1]);
        Assert.assertNotNull("dbUserName cannot be empty", args[2]);
        Assert.assertNotNull("dbPassword cannot be empty", args[3]);

        jdbcUrl = args[0].trim();
        String jdbcDriver = args[1].trim();
        dbUserName = args[2].trim();
        dbPassword = args[3].trim();

        Assert.assertFalse("jdbcUrl cannot be empty", jdbcUrl.isEmpty());
        Assert.assertFalse("jdbcDriver cannot be empty", jdbcDriver.isEmpty());
        Assert.assertFalse("dbUserName cannot be empty", dbUserName.isEmpty());

        StringBuilder build = new StringBuilder();
        build.append("DatabaseTestDataSource configuration [\n");
        build.append(String.format("jdbcUrl is %s\n", jdbcUrl));
        build.append(String.format("jdbcDriver is %s\n", jdbcDriver));
        build.append(String.format("dbUserName is %s\n", dbUserName));
        build.append(String.format("dbPassword is %s]", dbPassword));
        logger.info(build.toString());

        //Load the driver first
        try {
            Driver driver = (Driver) getProjectClassLoader().loadClass(jdbcDriver).newInstance();
            CustomDriverManager.registerDriver(driver);
        } catch (Exception e) {
            throw new AssertionError(String.format("Driver class %s not found", jdbcDriver));
        }

        for (int i = 0; i < poolSize; i++) {
            //Now try connecting to the Database
            Connection conn = null;
            try {
                conn = CustomDriverManager.getConnection(jdbcUrl, dbUserName, dbPassword);
            } catch (Exception e) {
                throw new AssertionError(String.format(
                        "Connection to the Database using the JDBC URL %s failed with the error %s", jdbcUrl,
                        ExceptionUtils.getStackTrace(e)));
            }

            addToPool(conn, false);
        }

    } catch (Exception t) {
        t.printStackTrace();
    } finally {
        currentThread.setContextClassLoader(oldClassLoader);
    }
}

From source file:facebook4j.junit.F4JHttpParameterMatchers.java

@Factory
public static Matcher<HttpParameter[]> hasPostJsonParameter(final String name,
        final String expectedJsonObjectSource) {
    JSONObject expectedJsonObject;//w w  w  .  j a v  a  2  s  .  c o m
    try {
        expectedJsonObject = new JSONObject(expectedJsonObjectSource);
    } catch (JSONException ex) {
        throw new AssertionError("failed to parse object source: " + expectedJsonObjectSource);
    }
    return hasPostJsonParameter(name, expectedJsonObject);
}

From source file:com.feilong.core.net.ParamExtensionUtil.java

/** Don't let anyone instantiate this class. */
private ParamExtensionUtil() {
    //AssertionError?. ?????. ???.
    //see Effective Java 2nd
    throw new AssertionError("No " + getClass().getName() + " instances for you!");
}

From source file:com.discovery.darchrow.bean.PropertyUtil.java

/** Don't let anyone instantiate this class. */
private PropertyUtil() {
    //AssertionError?. ?????. ???.
    //see Effective Java 2nd
    throw new AssertionError("No " + getClass().getName() + " instances for you!");
}

From source file:fi.hsl.parkandride.itest.AbstractIntegrationTest.java

public static String resourceAsString(String resourcePath) {
    try {/*from w  ww  . j  a va 2 s .c  o m*/
        return Resources.toString(Resources.getResource(resourcePath), Charsets.UTF_8);
    } catch (IOException e) {
        throw new AssertionError("Loading of resource '" + resourcePath + "' failed: " + e);
    }
}

From source file:gmc.hotplate.logic.LocalDataManager.java

@Override
public Map<Ingredient, Float> getIngredients(long recipeId) {
    throw new AssertionError("Not implemented yet!");
}

From source file:edu.emory.cci.aiw.cvrg.eureka.common.comm.BinaryOperator.java

@Override
boolean evaluate(Map<String, List<Proposition>> propMap) {
    switch (this.op) {
    case AND:/*w ww.  j  a  va2s.c  om*/
        return this.leftNode.evaluate(propMap) && this.rightNode.evaluate(propMap);
    case OR:
        return this.leftNode.evaluate(propMap) || this.rightNode.evaluate(propMap);
    default:
        throw new AssertionError("Invalid op " + this.op);
    }
}

From source file:com.anhth12.lambda.ml.param.HyperParams.java

public static HyperParamValues<?> fromConfig(Config config, String key) {
    switch (config.getValue(key).valueType()) {
    case LIST://  w w  w . j a  v  a 2s  . c  o  m
        List<String> stringValues = config.getStringList(key);
        try {
            return range(Integer.parseInt(stringValues.get(0)), Integer.parseInt(stringValues.get(1)));
        } catch (NumberFormatException nfe) {
            // continue
        }
        try {
            return range(Double.parseDouble(stringValues.get(0)), Double.parseDouble(stringValues.get(1)));
        } catch (NumberFormatException nfe) {
            // continue
        }
        return unorderedFromValues(stringValues);
    case STRING:
    case NUMBER:
        String stringValue = config.getString(key);
        try {
            return fixed(Integer.parseInt(stringValue));
        } catch (NumberFormatException nfe) {

        }

        try {
            return fixed(Double.parseDouble(stringValue));
        } catch (NumberFormatException nfe) {
            // continue
        }
        return unorderedFromValues(Collections.singletonList(stringValue));
    default:
        throw new AssertionError(config.getValue(key).valueType().name());

    }
}

From source file:sit.web.client.HttpHelper.java

public static String encodeString(String myString) {
    if (myString == null) {
        throw new NullPointerException("encodeString: myString == null!");
    }//  w  ww.ja  v  a  2  s  . com
    try {
        return java.net.URLEncoder.encode(myString, "UTF-8");
    } catch (UnsupportedEncodingException ex) {
        throw new AssertionError("UTF-8 not supported");
    }
}

From source file:com.predic8.membrane.test.AssertUtils.java

public static void assertContainsNot(String needle, String haystack) {
    if (!haystack.contains(needle))
        return;//from   ww w .  j av  a2s. c  om
    throw new AssertionError("The string '" + haystack + "' does contain '" + needle + "'.");
}