List of usage examples for java.lang AssertionError getMessage
public String getMessage()
From source file:Main.java
public static void main(String[] argv) throws Exception { try {//w w w. j av a2s .c o m assert argv.length > 0; } catch (AssertionError e) { String message = e.getMessage(); System.out.println(message); } }
From source file:Main.java
public static void main(String[] argv) throws Exception { try {/*www. java2 s .co m*/ assert argv.length > 0 : "my message"; } catch (AssertionError e) { String message = e.getMessage(); System.out.println(message); } }
From source file:Main.java
public static boolean isAndroidGetsocknameError(AssertionError e) { return e.getCause() != null && e.getMessage() != null && e.getMessage().contains("getsockname failed"); }
From source file:org.sonar.test.i18n.I18nMatchers.java
/** * Checks that all the translation bundles found on the classpath are up to date with the corresponding default ones found in the classpath. *//* ww w .ja v a2s. co m*/ public static void assertBundlesUpToDate() { File bundleFolder = TestUtils.getResource(BundleSynchronizedMatcher.L10N_PATH); if (bundleFolder == null || !bundleFolder.isDirectory()) { fail("No bundle found in: " + BundleSynchronizedMatcher.L10N_PATH); } Collection<File> bundles = FileUtils.listFiles(bundleFolder, new String[] { "properties" }, false); Map<String, String> failedAssertionMessages = Maps.newHashMap(); for (File bundle : bundles) { String bundleName = bundle.getName(); if (bundleName.indexOf('_') > 0) { try { assertThat(bundleName, isBundleUpToDate()); } catch (AssertionError e) { failedAssertionMessages.put(bundleName, e.getMessage()); } } } if (!failedAssertionMessages.isEmpty()) { StringBuilder message = new StringBuilder(); message.append(failedAssertionMessages.size()); message.append(" bundles are not up-to-date: "); message.append(StringUtils.join(failedAssertionMessages.keySet(), ", ")); message.append("\n\n"); message.append(StringUtils.join(failedAssertionMessages.values(), "\n\n")); fail(message.toString()); } }
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 {//from ww w .j av a 2s . c o m 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.magnet.tools.tests.FileSystemStepDefs.java
@Then("^the directory structure for \"([^\"]*)\" should not be:$") public static void the_directory_should_not_be(String directory, List<String> entries) throws Throwable { the_directory_should_exist(directory); try {// w w w .j av a 2s. c om for (String entry : entries) { the_file_does_not_exist(directory + "/" + entry); } } catch (AssertionError e) { StringBuilder tree = new StringBuilder( "Entry found: " + e.getMessage() + "\nThe directory structure for " + directory + " was:\n"); for (File f : FileUtils.listFilesAndDirs(new File(directory), TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE)) { tree.append(f).append("\n"); } throw new AssertionError(tree.toString(), e); } }
From source file:com.predic8.membrane.test.AssertUtils.java
public static String getAndAssert(int expectedHttpStatusCode, String url, String[] header) throws ParseException, IOException { if (hc == null) hc = new DefaultHttpClient(); HttpGet get = new HttpGet(url); try {//from w w w. ja v a 2 s.c o m if (header != null) for (int i = 0; i < header.length; i += 2) get.addHeader(header[i], header[i + 1]); HttpResponse res = hc.execute(get); try { assertEquals(expectedHttpStatusCode, res.getStatusLine().getStatusCode()); } catch (AssertionError e) { throw new AssertionError(e.getMessage() + " while fetching " + url); } HttpEntity entity = res.getEntity(); return entity == null ? "" : EntityUtils.toString(entity); } finally { get.releaseConnection(); } }
From source file:com.taobao.itest.matcher.AssertPropertiesEquals.java
/** * assertPropertiesEquals //from ww w .j av a 2 s. co m * Mainly used to compare two objects of the specified attribute value is equal, * to support complex type of attribute comparison * * <li>Eg: Person class contains a type of property Address: * address, Address type contains a String property: street.<br> * Then compare two Person objects are equal when the street can be written<br> * AssertUtil.assertPropertiesEquals(person1,person2,"address.street")<br> * Written about the time when the form<br> * AssertUtil.assertPropertiesEquals(person1,person2,"address")<br> * Can compare the address of each property is equal to * * @param expect Expect the object * @param actual actual the object * @param propertyNames Need to compare the property values, * support for complex types, you can enter multiple comma-separated string, * you can also enter the array * */ public static void assertPropertiesEquals(Object expect, Object actual, String... propertyNames) { Assert.assertNotNull("bean is null" + expect, expect); Assert.assertNotNull("bean is null" + actual, actual); //Assert.assertFalse("to compare the property is empty", ArrayUtils.isEmpty(propertyNames)); Object valueExpect = null; Object valueActual = null; List<String> errorMessages = new ArrayList<String>(); /* * If the attribute name is empty, then compare the two object * the current value of all the fields. * This parameter is empty, * the situation has in the upper control and verified directly through reflection */ if (ArrayUtils.isEmpty(propertyNames)) { PropertyDescriptor[] props = BeanUtilsBean.getInstance().getPropertyUtils() .getPropertyDescriptors(expect); propertyNames = new String[props.length - 1]; int j = 0; for (int i = 0; i < props.length; i++) { if (!props[i].getName().equals("class")) { propertyNames[j] = props[i].getName(); j++; } } } //Cycle to compare different properties for (int i = 0; i < propertyNames.length; i++) { try { valueExpect = BeanUtilsBean.getInstance().getPropertyUtils().getProperty(expect, propertyNames[i]); valueActual = BeanUtilsBean.getInstance().getPropertyUtils().getProperty(actual, propertyNames[i]); if (valueExpect == null || valueActual == null) Assert.assertEquals(valueExpect, valueActual); else if (valueExpect.getClass().getName().startsWith("java.lang") || valueExpect instanceof Date) { Assert.assertEquals(valueExpect, valueActual); /* * If taken out of the object is still a complex structure, * then the recursive call, then the property name set to null, * compare the value of all the attributes of the object */ } else { assertPropertiesEquals(valueExpect, valueActual); } } catch (Exception e) { throw new RuntimeException("error property" + propertyNames[i], e.fillInStackTrace()); } catch (AssertionError err) { errorMessages.add("\nexpect property" + propertyNames[i] + " value is " + valueExpect + "but actual value is" + valueActual); if (StringUtils.isNotBlank(err.getMessage())) { errorMessages.add("\ncaused by" + err.getMessage()); } } } if (errorMessages.size() > 0) { throw new ComparisonFailure(errorMessages.toString(), "", ""); } }
From source file:com.magnet.tools.tests.FileSystemStepDefs.java
@Then("^the directory structure for \"([^\"]*)\" should be:$") public static void the_directory_should_be(String directory, List<String> entries) throws Throwable { the_directory_should_exist(directory); List<AssertionError> errors = new ArrayList<AssertionError>(); for (String entry : entries) { try {// w w w . j a v a2 s . co m if (entry.endsWith("/") || entry.endsWith("\\")) { ScenarioUtils.the_directory_under_directory_should_exist(directory, entry); } else { ScenarioUtils.the_file_under_directory_should_exist(directory, entry); } } catch (AssertionError e) { errors.add(e); } } if (!errors.isEmpty()) { String dir = ScenarioUtils.expandVariables(directory); StringBuilder tree = new StringBuilder(); for (AssertionError e : errors) { tree.append("Entry not found: ").append(e.getMessage()).append("\n"); } tree.append("\n").append("The directory structure for ").append(dir).append(" was:").append("\n"); for (File f : FileUtils.listFilesAndDirs(new File(dir), TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE)) { tree.append(f).append("\n"); } throw new AssertionError(tree.toString(), errors.get(0)); } }
From source file:com.aliyun.openservices.odps.console.utils.CommandParserUtils.java
private static void parseCommandLineCommand(List<AbstractCommand> commandList, List<String> optionList, ExecutionContext sessionContext) throws ODPSConsoleException { for (int i = 0; i < COMMANDLINE_COMMANDS.length; i++) { String commandName = COMMAND_PACKAGE + "." + COMMANDLINE_COMMANDS[i]; AbstractCommand cmd = reflectCommandObject(commandName, new Class<?>[] { List.class, ExecutionContext.class }, optionList, sessionContext); addCommand(commandList, cmd, sessionContext); }/* www. jav a 2 s. co m*/ if (ecList == null) { ecList = PluginUtil.getExtendCommandList(); } for (PluginPriorityCommand command : ecList) { String commandName = command.getCommandName(); if (commandName != null && !"".equals(commandName.trim())) { AbstractCommand cmd = null; try { cmd = reflectCommandObject(commandName, new Class<?>[] { List.class, ExecutionContext.class }, optionList, sessionContext); } catch (AssertionError e) { // ?,console??? sessionContext.getOutputWriter().writeDebug(e.getMessage()); System.err.println("fail to load user command, pls check:" + commandName); } if (cmd != null) { addCommand(commandList, cmd, sessionContext); return; } } } }