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.aerospike.delivery.db.base.Database.java

public static void assertWriteLocked(ReentrantReadWriteLock lock) {
    if (!lock.isWriteLocked()) {
        throw new AssertionError("Call this operation from inside withWriteLocked().");
    }//from ww  w . j  av a 2  s  .c  om
}

From source file:keywhiz.cli.commands.AddAction.java

@Override
public void run() {
    List<String> types = addActionConfig.addType;

    if (types == null || types.isEmpty()) {
        throw new IllegalArgumentException("Must specify a single type to add.");
    }/*  ww w . java 2s. com*/

    String firstType = types.get(0).toLowerCase().trim();
    String name = addActionConfig.name;

    if (name == null || !validName(name)) {
        throw new IllegalArgumentException(format("Invalid name, must match %s", VALID_NAME_PATTERN));
    }

    switch (firstType) {
    case "group":
        try {
            keywhizClient.getGroupByName(name);
            throw new AssertionError("Group already exists.");
        } catch (NotFoundException e) {
            // group does not exist, continue to add it
        } catch (IOException e) {
            throw Throwables.propagate(e);
        }
        try {
            keywhizClient.createGroup(name, null);
            logger.info("Creating group '{}'.", name);
        } catch (IOException e) {
            throw Throwables.propagate(e);
        }
        break;

    case "secret":
        try {
            keywhizClient.getSanitizedSecretByName(name);
            throw new AssertionError("Secret already exists.");
        } catch (NotFoundException e) {
            // secret does not exist, continue to add it
        } catch (IOException e) {
            throw Throwables.propagate(e);
        }
        byte[] content = readSecretContent();
        ImmutableMap<String, String> metadata = getMetadata();

        createAndAssignSecret(name, content, metadata, getExpiry());
        break;

    case "client":
        try {
            keywhizClient.getClientByName(name);
            throw new AssertionError("Client name already exists.");
        } catch (NotFoundException e) {
            // client does not exist, continue to add it
        } catch (IOException e) {
            throw Throwables.propagate(e);
        }
        try {
            keywhizClient.createClient(name);
            logger.info("Creating client '{}'.", name);
        } catch (IOException e) {
            throw Throwables.propagate(e);
        }
        break;

    default:
        throw new AssertionError("Invalid add type specified: " + firstType);
    }
}

From source file:com.gs.collections.impl.jmh.map.JdkMutableMapGetTest.java

@Benchmark
public void get() {
    int localSize = this.size;
    String[] localElements = this.elements;
    Map<String, String> localJdkMap = this.jdkMap;

    for (int i = 0; i < localSize; i++) {
        if (localJdkMap.get(localElements[i]) == null) {
            throw new AssertionError(i);
        }/*from  w w w  .j  a va  2 s  . com*/
    }
}

From source file:org.callimachusproject.test.TemporaryServerFactory.java

private static File findCallimachusWebappCar() {
    File dist = new File("dist");
    if (dist.list() != null) {
        for (String file : dist.list()) {
            if (file.startsWith("callimachus-webapp") && file.endsWith(".car"))
                return new File(dist, file);
        }/*from w w w  .j  a va2  s.c o m*/
    }
    File car = SystemProperties.getWebappCarFile();
    if (car != null && car.exists())
        return car;
    throw new AssertionError("Could not find callimachus-webapp.car in " + dist.getAbsolutePath());
}

From source file:at.beeone.netbankinglight.api.NetbankingSession.java

private NetbankingSession(Builder builder) {
    if (builder.endpoint == null) {
        throw new AssertionError("you need to specify an endpoint URL");
    }/*from  w  ww. ja  va2  s . c  o m*/

    mBuilder = new RestCall.Builder().authTokenField("X-BeeOne-Auth").endpoint(builder.endpoint)
            .header("Content-Type", "application/json");

}

From source file:com.googlecode.osde.internal.gadgets.parser.AbstractParser.java

public T parse(InputStream stream) throws ParserException {
    try {// www .  j  a  va  2s  .  com
        return parse(new InputStreamReader(stream, "UTF-8"));
    } catch (UnsupportedEncodingException e) {
        throw new AssertionError("Should not happen");
    }
}

From source file:guru.nidi.ramltester.util.FormDecoder.java

public Values decode(RamlRequest request) {
    if (request.getContentType() == null) {
        return new Values();
    }//w w w .j a  v a2s.  com
    final MediaType type;
    try {
        type = MediaType.valueOf(request.getContentType());
    } catch (InvalidMediaTypeException e) {
        return new Values();
    }
    if (type.isCompatibleWith(URL_ENCODED)) {
        final String charset = type.getCharset(DEFAULT_CHARSET);
        try {
            final String content = IoUtils.readIntoString(
                    new InputStreamReader(new ByteArrayInputStream(request.getContent()), charset));
            return decodeUrlEncoded(content, charset);
        } catch (UnsupportedEncodingException e) {
            throw new IllegalArgumentException("Unknown charset " + charset, e);
        } catch (IOException e) {
            throw new AssertionError(e);
        }
    }
    if (type.isCompatibleWith(MULTIPART)) {
        return decodeMultipart(request);
    }
    return new Values();
}

From source file:bi.meteorite.pages.SaikuTable.java

public void shouldHaveRowElementsWhere(BeanMatcher... matchers) {
    List<WebElement> rows = getRowElementsWhere(matchers);
    if (rows.isEmpty()) {
        throw new AssertionError(
                "Expecting a table with at least one row where: " + Arrays.deepToString(matchers));
    }//from  ww w. j av a  2 s . c  o m
}

From source file:com.baidu.qa.service.test.setup.SetUpWithMysqlImpl.java

public boolean setTestDataWithSql(File file, Config config) {
    FileCharsetDetector det = new FileCharsetDetector();
    try {/*ww w  .j  a  v  a  2s  . c o m*/
        String oldcharset = det.guestFileEncoding(file);
        if (oldcharset.equalsIgnoreCase("UTF-8") == false)
            FileUtil.transferFile(file, oldcharset, "UTF-8");
    } catch (Exception ex) {
        log.error("[change expect file charset error]:" + ex);
    }

    List<String> datalist = FileUtil.getListFromFile(file);
    if (datalist.size() <= 1) {
        return true;
    }
    try {
        String table = file.getName().substring(0, file.getName().indexOf(Constant.FILE_TYPE_DB) - 1);
        String[] name = table.split("\\.");
        Assert.assertEquals("[get db name error]:from " + file.getName(), 2, name.length);

        String dbname = name[0];
        StringBuilder sb = new StringBuilder();
        sb.append("insert into ");
        sb.append(table);
        sb.append(" ( " + datalist.get(0) + " )");
        sb.append(" values ");
        for (int i = 1; i < datalist.size(); i++) {
            sb.append(" (" + datalist.get(i) + " ),");
        }
        sb.deleteCharAt(sb.length() - 1);

        log.info("[insert csv data into db,the sql is]:" + sb.toString());
        JdbcUtil.excuteInsertOrUpdateSql(sb.toString(), dbname, config.getReplace_time());

        log.debug("[insert csv data into db,the data are]:");
        for (int i = 0; i < datalist.size(); i++) {
            System.out.println(datalist.get(i));
        }

        return true;
    } catch (Exception e) {
        log.error("[insert csv data into mysql error]:", e);
        throw new AssertionError("insert csv data into mysql error..." + e.getMessage());
    }

}

From source file:com.asakusafw.runtime.flow.MapperWithRuntimeResource.java

@Override
public final void run(Context context) throws IOException, InterruptedException {
    this.resources = new RuntimeResourceManager(context.getConfiguration());
    resources.setup();/*from   w w w.j  a v  a 2 s . c  o  m*/
    try {
        runInternal(context);
    } catch (Throwable t) {
        oombuf = null;
        LOG.error(MessageFormat.format("error occurred while executing mapper: {0}", getClass().getName()), t);
        if (t instanceof Error) {
            throw (Error) t;
        } else if (t instanceof RuntimeException) {
            throw (RuntimeException) t;
        } else if (t instanceof IOException) {
            throw (IOException) t;
        } else if (t instanceof InterruptedException) {
            throw (InterruptedException) t;
        } else {
            throw new AssertionError(t);
        }
    } finally {
        this.resources.cleanup();
    }
}