List of usage examples for java.lang AssertionError AssertionError
public AssertionError(double detailMessage)
double
, which is converted to a string as defined in section 15.18.1.1 of The Java™ Language Specification. From source file:org.primeframework.mvc.test.RequestResult.java
/** * Verifies that the body does not contain any of the given Strings. * * @param strings The strings to check.//from w ww .ja va2 s . co m * @return This. */ public RequestResult assertBodyDoesNotContain(String... strings) { for (String string : strings) { if (body.contains(string)) { throw new AssertionError( "Body shouldn't contain [" + string + "]\nRedirect: [" + redirect + "]\nBody:\n" + body); } } return this; }
From source file:org.authme.android.util.AuthMeHttpClient.java
private SSLSocketFactory newSslSocketFactory() { try {/*from ww w. ja v a 2 s .c o m*/ // Get an instance of the Bouncy Castle KeyStore format KeyStore trusted = KeyStore.getInstance("BKS"); // Could probably load the main keystore and then append, but this works trusted.load(null, null); InputStream is = context.getResources().openRawResource(R.raw.cacert_root); CertificateFactory certificateFactory = CertificateFactory.getInstance("X509"); Certificate certificate = certificateFactory.generateCertificate(is); trusted.setCertificateEntry("CACertRoot", certificate); // Now continue on using this keystore SSLSocketFactory sf = new SSLSocketFactory(trusted); // Hostname verification from certificate // http://hc.apache.org/httpcomponents-client-ga/tutorial/html/connmgmt.html#d4e506 sf.setHostnameVerifier(SSLSocketFactory.STRICT_HOSTNAME_VERIFIER); return sf; } catch (Exception e) { throw new AssertionError(e); } }
From source file:org.silverpeas.components.blankApp.rest.BlankAppRESTTest.java
protected Statement query(String sql) { Statement stmt = null;/*from w w w. j a v a 2 s. c o m*/ try { Connection conn = databaseTester.getConnection().getConnection(); stmt = conn.createStatement(); stmt.execute(sql); } catch (SQLException ex) { close(stmt); throw new AssertionError(ex); } catch (Exception ex) { throw new AssertionError(ex); } return stmt; }
From source file:com.android.i18n.addressinput.AndroidAsyncRequestApi.java
/** * A quick hack to transform a string into an RFC 3986 compliant URL. * * TODO: Refactor the code to stop passing URLs around as strings, to eliminate the need for * this broken hack.// ww w. jav a 2 s. c om */ private static String encodeUrl(String url) { int length = url.length(); StringBuilder tmp = new StringBuilder(length); try { for (int i = 0; i < length; i++) { int j = i; char c = '\0'; for (; j < length; j++) { c = url.charAt(j); if (c == ':' || c == '/') { break; } } if (j == length) { tmp.append(URLEncoder.encode(url.substring(i), "UTF-8")); break; } else if (j > i) { tmp.append(URLEncoder.encode(url.substring(i, j), "UTF-8")); tmp.append(c); i = j; } else { tmp.append(c); } } } catch (UnsupportedEncodingException e) { throw new AssertionError(e); // Impossible. } return tmp.toString(); }
From source file:com.baidu.qa.service.test.verify.VerifyResponseImpl.java
public void verifyTestResultBySoapRequest(File file, Config config, VariableGenerator vargen) { try {/*from ww w. ja va 2 s . c o m*/ SoapReqImpl req = new SoapReqImpl(); req.requestSoap(file, config, vargen); } catch (Exception e) { throw new AssertionError("verify test result by soap request fail"); } }
From source file:com.mousefeed.eclipse.TextActionHandlerActionLocator.java
/** * Finds an action inside of <code>searchTarget</code>. * @param action the action to search. Not <code>null</code>. * @param searchTarget where to search. Not <code>null</code>. * @return the action definition id for the global action for the same * command as <code>action</code>, if it */// w w w . ja va 2 s . c om public String findActionDefinitionId(final IAction action, final IAction searchTarget) { try { return doFindActionDefinitionId(action, searchTarget); } catch (final SecurityException e) { throw new AssertionError(e); } catch (final NoSuchFieldException e) { throw new AssertionError(e); } catch (final IllegalAccessException e) { throw new AssertionError(e); } }
From source file:com.predic8.membrane.core.transport.ExceptionHandlingTest.java
public static String getAndAssert(int expectedHttpStatusCode, HttpUriRequest request) throws ParseException, IOException { if (hc == null) hc = HttpClientBuilder.create().build(); HttpResponse res = hc.execute(request); try {/*www . j a v a2s . c om*/ assertEquals(expectedHttpStatusCode, res.getStatusLine().getStatusCode()); } catch (AssertionError e) { throw new AssertionError(e.getMessage() + " while fetching " + request.getURI()); } HttpEntity entity = res.getEntity(); return entity == null ? "" : EntityUtils.toString(entity); }
From source file:com.joyent.manta.serialization.EncryptedMultipartManagerSerializationTest.java
public void canSerializeEncryptedServerSideMultipartUpload() throws IOException { final UUID uploadId = new UUID(0L, 0L); final String path = "/user/stor/myObject"; final String partsDir = "/user/uploads/0/" + uploadId; final ServerSideMultipartUpload inner = new ServerSideMultipartUpload(uploadId, path, partsDir); final EncryptionContext encryptionContext = new EncryptionContext(secretKey, cipherDetails); final EncryptionState encryptionState = new EncryptionState(encryptionContext); Field cipherStreamField = ReflectionUtils.getField(EncryptionState.class, "cipherStream"); MultipartOutputStream multipartStream = new MultipartOutputStream(cipherDetails.getBlockSizeInBytes()); OutputStream cipherStream = EncryptingEntityHelper.makeCipherOutputForStream(multipartStream, encryptionContext);//from w w w. j ava 2 s.com try { FieldUtils.writeField(cipherStreamField, encryptionState, cipherStream); } catch (IllegalAccessException e) { throw new AssertionError(e); } final EncryptedMultipartUpload<?> upload = newUploadInstance(inner, encryptionState); final byte[] serializedData; try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); Output output = new Output(outputStream)) { this.kryo.writeObject(output, upload); output.flush(); serializedData = outputStream.toByteArray(); } try (Input input = new Input(serializedData)) { final EncryptedMultipartUpload<?> actual = kryo.readObject(input, EncryptedMultipartUpload.class); Assert.assertEquals(actual, upload); } }
From source file:com.wantscart.jade.core.JadeOperationFactoryImpl.java
@Override public JadeOperation getOperation(DataAccess dataAccess, Modifier modifier) { // Annotation SQL sql = modifier.getAnnotation(SQL.class); Assert.notNull(sql, "@SQL is required for method " + modifier); String sqlString = sql.value(); SQLType sqlType = sql.type(); if (sqlType == SQLType.TEMPLATE) { TableSchema schema = TableSchema.getSchema(modifier.getDefinition().getDAOGenericsClazz()); for (String T : TableSchema.ALL_TEMPLATE) { sqlString = StringUtils.replace(sqlString, T, schema.getByTemplate(T)); }//from w ww . j a v a 2 s. c o m sqlType = SQLType.AUTO_DETECT; } if (sqlType == SQLType.AUTO_DETECT) { for (int i = 0; i < SELECT_PATTERNS.length; i++) { // ?? SELECT ? if (SELECT_PATTERNS[i].matcher(sqlString).find()) { sqlType = SQLType.READ; break; } } if (sqlType == SQLType.AUTO_DETECT) { sqlType = SQLType.WRITE; } } // if (SQLType.READ == sqlType) { // RowMapper RowMapper rowMapper = rowMapperFactory.getRowMapper(modifier); // SELECT return new SelectOperation(dataAccess, sqlString, modifier, rowMapper); } else if (SQLType.WRITE == sqlType) { // INSERT / UPDATE / DELETE return new UpdateOperation(dataAccess, sqlString, modifier); } // throw new AssertionError("Unknown SQL type: " + sqlType); }
From source file:com.phonty.improved.PhontyHttpClient.java
private SSLSocketFactory newSslSocketFactory() { try {/*from www. ja va2 s . co m*/ // Get an instance of the Bouncy Castle KeyStore format KeyStore trusted = KeyStore.getInstance("BKS"); // Get the raw resource, which contains the keystore with // your trusted certificates (root and any intermediate certs) InputStream in = context.getResources().openRawResource(R.raw.keystore); try { // Initialize the keystore with the provided trusted certificates // Also provide the password of the keystore trusted.load(in, "pqoeponkjlcnvkjenenobnervoerovneokrnvoie".toCharArray()); } finally { in.close(); } // Pass the keystore to the SSLSocketFactory. The factory is responsible // for the verification of the server certificate. SSLSocketFactory sf = new SSLSocketFactory(trusted); // Hostname verification from certificate // http://hc.apache.org/httpcomponents-client-ga/tutorial/html/connmgmt.html#d4e506 sf.setHostnameVerifier(SSLSocketFactory.STRICT_HOSTNAME_VERIFIER); return sf; } catch (Exception e) { throw new AssertionError(e); } }