List of usage examples for junit.framework Assert fail
static public void fail()
From source file:com.qcadoo.model.internal.classconverter.ModelXmlToClassConverterTest.java
@Test public void shouldHashCodeDoNotHaveCycleWithHasManyFields() throws Exception { // given/* w w w . ja v a2 s . co m*/ Object firstEntity = classes.get(ClassNameUtils.getFullyQualifiedClassName("full", "firstEntity")) .newInstance(); Object thirdEntity = classes.get(ClassNameUtils.getFullyQualifiedClassName("full", "thirdEntity")) .newInstance(); BeanUtils.setProperty(firstEntity, "fieldHasMany", Sets.newHashSet(thirdEntity)); BeanUtils.setProperty(thirdEntity, "fieldFirstEntity", firstEntity); // when & then try { firstEntity.hashCode(); thirdEntity.hashCode(); } catch (StackOverflowError t) { Assert.fail(); } }
From source file:com.espertech.esper.regression.rowrecog.TestRowPatternRecognitionDataSet.java
private static void compare(Object[] row, int rowCount, Object theEvent, SupportUpdateListener listener) { if (row.length < 3 || row[2] == null) { if (listener.isInvoked()) { EventBean[] matches = listener.getLastNewData(); if (matches != null) { for (int i = 0; i < matches.length; i++) { log.info("Received matches: " + getProps(matches[i])); }/*from w w w .j a v a2 s.c o m*/ } } assertFalse("For event " + theEvent + " row " + rowCount, listener.isInvoked()); return; } String[] expected = (String[]) row[2]; EventBean[] matches = listener.getLastNewData(); String[] matchesText = null; if (matches != null) { matchesText = new String[matches.length]; for (int i = 0; i < matches.length; i++) { matchesText[i] = getProps(matches[i]); log.debug(getProps(matches[i])); } } else { if (expected != null) { log.info("Received no matches but expected: "); for (int i = 0; i < expected.length; i++) { log.info(expected[i]); } Assert.fail(); } } Arrays.sort(expected); Arrays.sort(matchesText); assertEquals("For event " + theEvent, matches.length, expected.length); for (int i = 0; i < expected.length; i++) { if (!expected[i].equals(matchesText[i])) { log.info("expected:" + expected[i]); log.info(" actual:" + expected[i]); assertEquals("Sending event " + theEvent + " row " + rowCount, expected[i], matchesText[i]); } } listener.reset(); }
From source file:com.qcadoo.model.internal.classconverter.ModelXmlToClassConverterTest.java
@Test public void shouldHashCodeDoNotHaveCycleWithManyToManyFields() throws Exception { // given//from w w w . j av a 2s . com Object firstEntity = classes.get(ClassNameUtils.getFullyQualifiedClassName("full", "firstEntity")) .newInstance(); Object thirdEntity = classes.get(ClassNameUtils.getFullyQualifiedClassName("full", "thirdEntity")) .newInstance(); BeanUtils.setProperty(firstEntity, "fieldManyToMany", Sets.newHashSet(thirdEntity)); BeanUtils.setProperty(thirdEntity, "fieldManyToMany", Sets.newHashSet(firstEntity)); // when & then try { firstEntity.hashCode(); thirdEntity.hashCode(); } catch (StackOverflowError t) { Assert.fail(); } }
From source file:com.qcadoo.model.internal.classconverter.ModelXmlToClassConverterTest.java
@Test public void shouldHashCodeDoNotHaveCycleWithBelongsToAndManyToManyFields() throws Exception { // given/*from w w w. j av a 2s. co m*/ Object firstEntity = classes.get(ClassNameUtils.getFullyQualifiedClassName("full", "firstEntity")) .newInstance(); Object thirdEntity = classes.get(ClassNameUtils.getFullyQualifiedClassName("full", "thirdEntity")) .newInstance(); BeanUtils.setProperty(firstEntity, "fieldThirdEntity", thirdEntity); BeanUtils.setProperty(thirdEntity, "fieldManyToMany", Sets.newHashSet(firstEntity)); // when & then try { firstEntity.hashCode(); thirdEntity.hashCode(); } catch (StackOverflowError t) { Assert.fail(); } }
From source file:com.bumptech.glide.disklrucache.DiskLruCacheTest.java
@Test public void nullKeyThrows() throws Exception { try {// w w w . j a v a 2s . c o m cache.edit(null); Assert.fail(); } catch (NullPointerException expected) { } }
From source file:com.bumptech.glide.disklrucache.DiskLruCacheTest.java
@Test public void createNewEntryWithTooFewValuesFails() throws Exception { DiskLruCache.Editor creator = cache.edit("k1"); creator.set(1, "A"); try {/*from w w w .j a v a2s . com*/ creator.commit(); Assert.fail(); } catch (IllegalStateException expected) { } assertThat(getCleanFile("k1", 0).exists()).isFalse(); assertThat(getCleanFile("k1", 1).exists()).isFalse(); assertThat(getDirtyFile("k1", 0).exists()).isFalse(); assertThat(getDirtyFile("k1", 1).exists()).isFalse(); assertThat(cache.get("k1")).isNull(); DiskLruCache.Editor creator2 = cache.edit("k1"); creator2.set(0, "B"); creator2.set(1, "C"); creator2.commit(); }
From source file:com.microsoft.windowsazure.mobileservices.sdk.testapp.test.LoginTests.java
private void testLoginShouldThrowError(final MobileServiceAuthenticationProvider provider) throws Throwable { final ResultsContainer result = new ResultsContainer(); final String errorMessage = "fake error"; final String errorJson = "{error:'" + errorMessage + "'}"; // Create client MobileServiceClient client = null;//from www. java 2 s .c om try { client = new MobileServiceClient(appUrl, appKey, getInstrumentation().getTargetContext()); } catch (MalformedURLException e) { } // Add a new filter to the client client = client.withFilter(new ServiceFilter() { @Override public ListenableFuture<ServiceFilterResponse> handleRequest(ServiceFilterRequest request, NextServiceFilterCallback nextServiceFilterCallback) { result.setRequestUrl(request.getUrl()); ServiceFilterResponseMock response = new ServiceFilterResponseMock(); response.setContent(errorJson); response.setStatus(new StatusLine() { @Override public int getStatusCode() { return 400; } @Override public String getReasonPhrase() { return errorMessage; } @Override public ProtocolVersion getProtocolVersion() { return null; } }); final SettableFuture<ServiceFilterResponse> resultFuture = SettableFuture.create(); resultFuture.set(response); return resultFuture; } }); try { client.login(provider, "{myToken:123}").get(); Assert.fail(); } catch (Exception exception) { assertTrue(exception.getCause() instanceof MobileServiceException); MobileServiceException cause = (MobileServiceException) exception.getCause().getCause(); assertEquals(errorMessage, cause.getMessage()); } }
From source file:org.alfresco.mobile.android.test.api.services.ActivityStreamServiceTest.java
/** * All Tests forActivityStreamService public methods which create an error. * // w w w . j a v a 2s. c o m * @Requirement 3F1, 5F1, 5F2, 6F1, 6F2 */ public void testActivityServiceMethodsError() { try { // /////////////////////////////////////////////////////////////////////////// // Method getActivityStream() // /////////////////////////////////////////////////////////////////////////// try { Assert.assertNotNull(activityStreamService.getActivityStream((String) null)); Assert.fail(); } catch (IllegalArgumentException e) { Assert.assertTrue(true); } if (!isOnPremise()) { try { activityStreamService.getSiteActivityStream("adm1n"); } catch (AlfrescoServiceException e) { // Nothing special } } else { Assert.assertTrue(activityStreamService.getSiteActivityStream("adm1n").isEmpty()); } // /////////////////////////////////////////////////////////////////////////// // Method getSiteActivityStream() // /////////////////////////////////////////////////////////////////////////// try { Assert.assertNotNull(activityStreamService.getSiteActivityStream((String) null)); Assert.fail(); } catch (IllegalArgumentException e) { Assert.assertTrue(true); } // Check Error activity if (!isOnPremise()) { try { activityStreamService.getSiteActivityStream("bestsite").isEmpty(); } catch (AlfrescoServiceException e) { // Nothing special } } else { Assert.assertTrue(activityStreamService.getSiteActivityStream("bestsite").isEmpty()); } AlfrescoSession session = createSession(CONSUMER, CONSUMER_PASSWORD, null); if (session != null) { if (!isOnPremise()) { try { Assert.assertFalse(session.getServiceRegistry().getActivityStreamService() .getSiteActivityStream("privatesite").isEmpty()); } catch (AlfrescoServiceException e) { // Nothing special } } else { // @since site service management it's not null. Assert.assertTrue(session.getServiceRegistry().getActivityStreamService() .getSiteActivityStream("privatesite").isEmpty()); } Assert.assertTrue(session.getServiceRegistry().getActivityStreamService() .getSiteActivityStream("moderatedsite").isEmpty()); } checkSession(session); } catch (Exception e) { Log.e(TAG, "Error during Activity Tests"); Log.e("TAG", Log.getStackTraceString(e)); } }
From source file:com.microsoft.windowsazure.mobileservices.sdk.testapp.test.LoginTests.java
public void testAuthenticatedRequest() throws Throwable { final MobileServiceUser user = new MobileServiceUser("dummyUser"); user.setAuthenticationToken("123abc"); // Create client MobileServiceClient client = null;//from ww w. j a v a2 s . c om try { client = new MobileServiceClient(appUrl, appKey, getInstrumentation().getTargetContext()); client.setCurrentUser(user); } catch (MalformedURLException e) { } // Add a new filter to the client client = client.withFilter(new ServiceFilter() { @Override public ListenableFuture<ServiceFilterResponse> handleRequest(ServiceFilterRequest request, NextServiceFilterCallback nextServiceFilterCallback) { int headerIndex = -1; Header[] headers = request.getHeaders(); for (int i = 0; i < headers.length; i++) { if (headers[i].getName() == "X-ZUMO-AUTH") { headerIndex = i; } } if (headerIndex == -1) { Assert.fail(); } assertEquals(user.getAuthenticationToken(), headers[headerIndex].getValue()); ServiceFilterResponseMock response = new ServiceFilterResponseMock(); response.setContent("{}"); final SettableFuture<ServiceFilterResponse> resultFuture = SettableFuture.create(); resultFuture.set(response); return resultFuture; } }); client.getTable("dummy").execute().get(); }
From source file:com.microsoft.windowsazure.mobileservices.sdk.testapp.test.LoginTests.java
public void testLoginWithEmptyTokenShouldFail() throws Throwable { // Create client MobileServiceClient client = null;/*from w w w . j av a 2 s . c o m*/ try { client = new MobileServiceClient(appUrl, appKey, getInstrumentation().getTargetContext()); } catch (MalformedURLException e) { } String token = null; try { client.login(MobileServiceAuthenticationProvider.Facebook, token).get(); Assert.fail(); } catch (IllegalArgumentException e) { // It should throw an exception } try { client.login(MobileServiceAuthenticationProvider.Facebook, "").get(); Assert.fail(); } catch (IllegalArgumentException e) { // It should throw an exception } }