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:keywhiz.AuthHelper.java

/**
 * Builds a Keywhiz login request./*from   ww  w.j ava2s. c  om*/
 *
 * @param username login username
 * @param password login password
 * @return valid login request, given a valid username and password
 */
public static Request buildLoginPost(@Nullable String username, @Nullable String password) {
    Map<String, String> login = Maps.newHashMap();
    if (username != null) {
        login.put("username", username);
    }

    if (password != null) {
        login.put("password", password);
    }

    RequestBody body;
    try {
        body = RequestBody.create(KeywhizClient.JSON, MAPPER.writeValueAsString(login));
    } catch (JsonProcessingException e) {
        throw new AssertionError(e);
    }

    return new Request.Builder().url(HttpClients.testUrl("/admin/login")).post(body)
            .addHeader("Content-Type", MediaType.APPLICATION_JSON).build();
}

From source file:catchla.yep.util.YepArrayUtils.java

private YepArrayUtils() {
    throw new AssertionError("You are trying to create an instance for this utility class!");
}

From source file:dbs_project.util.TableInputFileReader.java

private TableInputFileReader() {
    throw new AssertionError("fail.");
}

From source file:com.orange.wro.taglib.tag.AsJsArrayIncludeTag.java

@Override
protected void writeEnd(StringBuilder builder) {
    int length = builder.length();
    if (length == 0) {
        throw new AssertionError(
                "The builder length is zero. This should not happen as we normally append something at the very beginning.");
    }/*w  w  w  .  j  a  va 2 s .c om*/

    try {
        if (builder.charAt(length - 1) == ',') {
            // will be false if we didn't add any file
            builder.deleteCharAt(length - 1);
        }
    } catch (IndexOutOfBoundsException e) {
        // must not happen as we check before
        throw new AssertionError(
                "deleteCharAt triggered a StringIndexOutOfBoundsException, which should not happen.");
    }

    builder.append("]");
}

From source file:de.vanita5.twittnuker.util.TwidereArrayUtils.java

private TwidereArrayUtils() {
    throw new AssertionError("You are trying to create an instance for this utility class!");
}

From source file:com.google.walkaround.slob.server.ChangeDataSerializer.java

public static JSONObject dataToClientJson(ChangeData<String> data, long resultingRevision) {
    Preconditions.checkArgument(resultingRevision <= MAX_DOUBLE_INTEGER, "Resulting revision %s is too large",
            resultingRevision);//www .  j  a v  a2 s.c o m

    // Assume payload is JSON, and parse it to avoid nested json.
    // TODO(danilatos): Consider using ChangeData<JSONObject> instead.
    // The reason I haven't done it yet is because it's not immutable,
    // and also for reasons described in ChangeData.
    JSONObject payloadJson;
    try {
        payloadJson = new JSONObject(data.getPayload());
    } catch (JSONException e) {
        throw new IllegalArgumentException("Invalid payload for " + data, e);
    }

    JSONObject json = new JSONObject();
    try {
        Preconditions.checkArgument(resultingRevision >= 0, "invalid rev %s", resultingRevision);
        json.put("revision", resultingRevision);
        long sanityCheck = json.getLong("revision");
        if (sanityCheck != resultingRevision) {
            throw new AssertionError("resultingRevision " + resultingRevision
                    + " not losslessly represented in JSON, got back " + sanityCheck);
        }
        json.put("sid", data.getClientId().getId());
        json.put("op", payloadJson);
        return json;
    } catch (JSONException e) {
        throw new Error(e);
    }
}

From source file:eu.trentorise.smartcampus.portfolio.utils.NetUtility.java

private NetUtility() {
    throw new AssertionError("You have to use static methods");
}

From source file:net.myrrix.common.io.IOUtils.java

/**
 * @param raw string to URL-encode//from  w  w w.j  a  v a  2  s  .c  om
 * @return the URL encoding of the argument, using the UTF-8 encoding if necessary to interpret
 *  characters as bytes
 */
public static String urlEncode(String raw) {
    try {
        return URLEncoder.encode(raw, Charsets.UTF_8.name());
    } catch (UnsupportedEncodingException uee) {
        // Can't happen for UTF-8
        throw new AssertionError(uee);
    }
}

From source file:org.opf_labs.project.healthcheck.GitHubProject.java

private GitHubProject() {
    throw new AssertionError("In GitHub Project no-arg constructor.");
}

From source file:android.framework.util.jar.Manifest.java

private static Field getByteArrayInputStreamField(String name) {
    try {/*from w ww  .  ja v a  2 s.  c  om*/
        Field f = ByteArrayInputStream.class.getDeclaredField(name);
        f.setAccessible(true);
        return f;
    } catch (Exception ex) {
        throw new AssertionError(ex);
    }
}