Java Code Examples for org.junit.Assert.fail()

The following are Jave code examples for showing how to use fail() of the org.junit.Assert class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: jpl-framework   File: LoadLearningAlgorithmsCommandTest.java   View Source Code Vote up 7 votes
/**
 * Checks if the {@link CommandResult} and the console output is correct.
 * 
 * @param consoleOutput the redirected console output
 * @throws NoSuchFieldException if reflection did not work
 * @throws SecurityException if reflection did not work
 * @throws IllegalArgumentException if reflection did not work
 * @throws IllegalAccessException if reflection did not work
 */
private void assertCorrectCommandResultAndConsoleOutput(String consoleOutput)
      throws NoSuchFieldException,
         SecurityException,
         IllegalArgumentException,
         IllegalAccessException {
   Pair<ICommand, CommandResult> latestPairInHistory = TestUtils.getLatestPairOfCommandAndCommandResultInCommandHistory();
   TestUtils.assertCorrectCommandType(latestPairInHistory.getFirst(), LoadLearningAlgorithmsCommand.class);
   TestUtils.assertCorrectSuccessfulCommandResult(latestPairInHistory.getSecond());

   @SuppressWarnings("unchecked")
   List<CommandResult> addAlgorithmCommandResultList = (List<CommandResult>) latestPairInHistory.getSecond().getResult();
   if (addAlgorithmCommandResultList.isEmpty()) {
      Assert.fail(ERROR_EMPTY_LIST_OF_COMMAND_RESULTS);
   }

   TestUtils.assertCorrectFailedEmptyCommandResult(addAlgorithmCommandResultList.get(0), ParameterValidationFailedException.class);
   TestUtils.assertCorrectSuccessfulCommandResultWhichIsNotEmpty(addAlgorithmCommandResultList.get(1), ILearningAlgorithm.class);

   assertCorrectFailedCommandResultAndConsoleOutputForAddingLearningAlgorithmsWithCorrectAndWrongParameters(consoleOutput,
         addAlgorithmCommandResultList);
}
 
Example 2
Project: https-github.com-apache-zookeeper   File: EphemeralTypeTest.java   View Source Code Vote up 7 votes
@Test
public void testTtls() {
    long ttls[] = {100, 1, EphemeralType.MAX_TTL};
    for (long ttl : ttls) {
        long ephemeralOwner = EphemeralType.ttlToEphemeralOwner(ttl);
        Assert.assertEquals(EphemeralType.TTL, EphemeralType.get(ephemeralOwner));
        Assert.assertEquals(ttl, EphemeralType.getTTL(ephemeralOwner));
    }

    EphemeralType.validateTTL(CreateMode.PERSISTENT_WITH_TTL, 100);
    EphemeralType.validateTTL(CreateMode.PERSISTENT_SEQUENTIAL_WITH_TTL, 100);

    try {
        EphemeralType.validateTTL(CreateMode.EPHEMERAL, 100);
        Assert.fail("Should have thrown IllegalArgumentException");
    } catch (IllegalArgumentException dummy) {
        // expected
    }
}
 
Example 3
Project: linkifier   File: RegressionTest.java   View Source Code Vote up 7 votes
@Test
public void test175() throws Throwable {
    if (debug)
        System.out.format("%n%s%n", "RegressionTest0.test175");
    Relationship relationship0 = new Relationship();
    Column column1 = relationship0.getPk();
    String str2 = relationship0.getSchema();
    Boolean b3 = relationship0.getDataTypeCategoryAgree();
    Boolean b4 = relationship0.isEstimatedFk();
    relationship0.setEstimatedFk(true);
    Connection connection7 = null;
    try {
        relationship0.setSlowFeatures(connection7);
        Assert.fail("Expected exception of type java.lang.NullPointerException");
    } catch (NullPointerException e) {
    }
    Assert.assertNull(column1);
    Assert.assertNull(str2);
    Assert.assertNull(b3);
    Assert.assertTrue("'" + b4 + "' != '" + false + "'", b4.equals(false));
}
 
Example 4
Project: hadoop   File: TestOpensslCipher.java   View Source Code Vote up 6 votes
@Test(timeout=120000)
public void testDoFinalArguments() throws Exception {
  Assume.assumeTrue(OpensslCipher.getLoadingFailureReason() == null);
  OpensslCipher cipher = OpensslCipher.getInstance("AES/CTR/NoPadding");
  Assert.assertTrue(cipher != null);
  
  cipher.init(OpensslCipher.ENCRYPT_MODE, key, iv);
  
  // Require direct buffer
  ByteBuffer output = ByteBuffer.allocate(1024);
  
  try {
    cipher.doFinal(output);
    Assert.fail("Output buffer should be direct buffer.");
  } catch (IllegalArgumentException e) {
    GenericTestUtils.assertExceptionContains(
        "Direct buffer is required", e);
  }
}
 
Example 5
Project: crnk-framework   File: AbstractInheritanceTest.java   View Source Code Vote up 6 votes
@Test
public void testMeta() {
	MetaEntity baseMeta = module.getJpaMetaProvider().getMeta(baseClass);
	MetaEntity childMeta = module.getJpaMetaProvider().getMeta(childClass);
	Assert.assertSame(baseMeta, childMeta.getSuperType());

	Assert.assertEquals(1, childMeta.getDeclaredAttributes().size());
	Assert.assertEquals(2, baseMeta.getAttributes().size());
	Assert.assertEquals(3, childMeta.getAttributes().size());

	Assert.assertNotNull(baseMeta.getAttribute("id"));
	Assert.assertNotNull(baseMeta.getAttribute("stringValue"));
	try {
		Assert.assertNull(baseMeta.getAttribute("intValue"));
		Assert.fail();
	} catch (Exception e) {
		// ok
	}
	Assert.assertNotNull(childMeta.getAttribute("id"));
	Assert.assertNotNull(childMeta.getAttribute("stringValue"));
	Assert.assertNotNull(childMeta.getAttribute("intValue"));
}
 
Example 6
Project: hadoop   File: FSMainOperationsBaseTest.java   View Source Code Vote up 6 votes
@Test
public void testRenameFileAsExistingFile() throws Exception {
  if (!renameSupported()) return;
  
  Path src = getTestRootPath(fSys, "test/hadoop/file");
  createFile(src);
  Path dst = getTestRootPath(fSys, "test/new/existingFile");
  createFile(dst);
  
  // Fails without overwrite option
  try {
    rename(src, dst, false, true, false, Rename.NONE);
    Assert.fail("Expected exception was not thrown");
  } catch (IOException e) {
    Assert.assertTrue(unwrapException(e) instanceof FileAlreadyExistsException);
  }
  
  // Succeeds with overwrite option
  rename(src, dst, true, false, true, Rename.OVERWRITE);
}
 
Example 7
Project: hadoop   File: TestFileBasedCopyListing.java   View Source Code Vote up 6 votes
private void caseGlobTargetMissingMultiLevel(boolean sync) {

    try {
      Path listFile = new Path("/tmp1/listing");
      Path target = new Path("/tmp/target");

      addEntries(listFile, "/tmp/*/*");
      createFiles("/tmp/multifile/file3", "/tmp/multifile/file4", "/tmp/multifile/file5");
      createFiles("/tmp/singledir1/dir3/file7", "/tmp/singledir1/dir3/file8",
          "/tmp/singledir1/dir3/file9");

      runTest(listFile, target, sync);

      checkResult(listFile, 6);
    } catch (IOException e) {
      LOG.error("Exception encountered while testing build listing", e);
      Assert.fail("build listing failure");
    } finally {
      TestDistCpUtils.delete(fs, "/tmp");
      TestDistCpUtils.delete(fs, "/tmp1");
    }
  }
 
Example 8
Project: appslandia-sweetsop   File: HttpPostTest.java   View Source Code Vote up 6 votes
@Test
public void test_jsonBody() {
	MappingBuilder mockReq = post(urlPathMatching("/action"));
	ResponseDefinitionBuilder mockResp = aResponse();
	mockReq.withRequestBody(equalTo("{\"id\":1,\"name\":\"user1\"}"));

	httpMock.stubFor(mockReq.willReturn(mockResp));

	HttpClient httpClient = null;
	try {
		String url = baseUrl();
		httpClient = HttpClient.post(url);

		httpClient.setRequestBody(new JsonBody(new User(1, "user1"), CharsetUtils.UTF_8));
		httpClient.execute();

		Assert.assertEquals(httpClient.getResponseCode(), 200);

	} catch (IOException ex) {
		Assert.fail(ex.getMessage());
	}
}
 
Example 9
Project: hadoop   File: TestHttpExceptionUtils.java   View Source Code Vote up 6 votes
@Test
public void testValidateResponseNonJsonErrorMessage() throws IOException {
  String msg = "stream";
  InputStream is = new ByteArrayInputStream(msg.getBytes());
  HttpURLConnection conn = Mockito.mock(HttpURLConnection.class);
  Mockito.when(conn.getErrorStream()).thenReturn(is);
  Mockito.when(conn.getResponseMessage()).thenReturn("msg");
  Mockito.when(conn.getResponseCode()).thenReturn(
      HttpURLConnection.HTTP_BAD_REQUEST);
  try {
    HttpExceptionUtils.validateResponse(conn, HttpURLConnection.HTTP_CREATED);
    Assert.fail();
  } catch (IOException ex) {
    Assert.assertTrue(ex.getMessage().contains("msg"));
    Assert.assertTrue(ex.getMessage().contains("" +
        HttpURLConnection.HTTP_BAD_REQUEST));
  }
}
 
Example 10
Project: hadoop   File: TestAppManager.java   View Source Code Vote up 6 votes
@Test (timeout = 30000)
public void testRMAppSubmitDuplicateApplicationId() throws Exception {
  ApplicationId appId = MockApps.newAppID(0);
  asContext.setApplicationId(appId);
  RMApp appOrig = rmContext.getRMApps().get(appId);
  Assert.assertTrue("app name matches but shouldn't", "testApp1" != appOrig.getName());

  // our testApp1 should be rejected and original app with same id should be left in place
  try {
    appMonitor.submitApplication(asContext, "test");
    Assert.fail("Exception is expected when applicationId is duplicate.");
  } catch (YarnException e) {
    Assert.assertTrue("The thrown exception is not the expectd one.",
        e.getMessage().contains("Cannot add a duplicate!"));
  }

  // make sure original app didn't get removed
  RMApp app = rmContext.getRMApps().get(appId);
  Assert.assertNotNull("app is null", app);
  Assert.assertEquals("app id doesn't match", appId, app.getApplicationId());
  Assert.assertEquals("app state doesn't match", RMAppState.FINISHED, app.getState());
}
 
Example 11
Project: CorePatch   File: RandomAccessObjectTest.java   View Source Code Vote up 6 votes
@Test
public void mmapReadIntTest() throws IOException {
  File tmpFile = storeInTempFile(new ByteArrayInputStream(BLOB));

  try {
    RandomAccessObject obj =
        new RandomAccessObject.RandomAccessMmapObject(new RandomAccessFile(tmpFile, "r"), "r");
    readIntTest(obj);

    try {
      obj.readInt();
      Assert.fail("Should've thrown an BufferUnderflowException");
    } catch (BufferUnderflowException expected) {
    }
  } finally {
    tmpFile.delete();
  }
}
 
Example 12
Project: rskj   File: CorsConfigurationTest.java   View Source Code Vote up 5 votes
@Test
public void raisedIfHeaderContainsNewLine() {
    try {
        new CorsConfiguration("host1\nhost2");
        Assert.fail();
    }
    catch (IllegalArgumentException ex) {
        Assert.assertEquals("corsheader", ex.getMessage());
    }
}
 
Example 13
Project: hadoop   File: TestOptionsParser.java   View Source Code Vote up 5 votes
@Test
public void testSourceListingAndSourcePath() {
  try {
    OptionsParser.parse(new String[] {
        "-f",
        "hdfs://localhost:8020/source/first",
        "hdfs://localhost:8020/source/first",
        "hdfs://localhost:8020/target/"});
    Assert.fail("Both source listing & source paths allowed");
  } catch (IllegalArgumentException ignore) {}
}
 
Example 14
Project: zucchini   File: ClickStep.java   View Source Code Vote up 5 votes
@When("^I click on element having (id|name|class|xpath|css) \"([^\"]*)\" on row containing \"([^\"]*)\" at table with (id|name|class|xpath|css) \"([^\"]*)\"$")
public void clickElementHavingOnRow(String type, String element, String text, String tableType, String tableElement) {
    WebElement table = getWebElement(tableType, tableElement);
    List<WebElement> rows = table.findElements(By.tagName("tr"));

    WebElement row = findTextAtRow(text, rows);
    if(row != null){
        WebElement el = row.findElement(TypeEnum.getBy(type, element));
        el.click();
    }else {
        Assert.fail(String.format("Didn't found %s on row",text));
    }
}
 
Example 15
Project: saladium   File: SaladiumDriver.java   View Source Code Vote up 5 votes
@Override
public void cliquer(String type, String selector) {
    this.logger.info("cliquer type:" + type + " selector:" + selector);
    try {
        By locator = BySelec.get(type, selector);
        wait.until(ExpectedConditions.elementToBeClickable(locator)).click();
    } catch (TimeoutException e) {
        e.printStackTrace();
        String pathScreenShot = takeScreenShot();
        Assert.fail("Cliquer impossible ! (type" + type + ", selector" + selector + ") pathScreenShot=" + pathScreenShot);
    }
}
 
Example 16
Project: neo-java   File: TestCoreExceptions.java   View Source Code Vote up 5 votes
/**
 * test TransactionType.valueOfByte.
 */
@Test
public void test001TransactionTypeValueOf() {
	try {
		TransactionType.valueOf("");
		Assert.fail(TestUtil.EXPECTED_A_RUNTIME_EXCEPTION_TO_BE_THROWN);
	} catch (final RuntimeException e) {
		Assert.assertEquals("No enum constant neo.model.core.TransactionType.", e.getMessage());
	}
}
 
Example 17
Project: hadoop-oss   File: TestJvmMetrics.java   View Source Code Vote up 5 votes
@Test
public void testStopBeforeInit() throws Throwable {
  pauseMonitor = new JvmPauseMonitor();
  try {
    pauseMonitor.stop();
    pauseMonitor.init(new Configuration());
    Assert.fail("Expected an exception, got " + pauseMonitor);
  } catch (ServiceStateException e) {
    GenericTestUtils.assertExceptionContains("cannot enter state", e);
  }
}
 
Example 18
Project: rskj   File: BlockTest.java   View Source Code Vote up 5 votes
@Test
public void sealedBlockSetBitcoinMergedMiningCoinbaseTransaction() {
    Block block = BlockGenerator.getInstance().createBlock(10, 0);

    block.seal();

    try {
        block.setBitcoinMergedMiningCoinbaseTransaction(new byte[32]);
        Assert.fail();
    }
    catch (SealedBlockException ex) {
        Assert.assertEquals("Sealed block: trying to alter bitcoin merged mining coinbase transaction", ex.getMessage());
    }
}
 
Example 19
Project: sling-org-apache-sling-testing-rules   File: FilterRuleExcludeCategoryIgnoreIfTest.java   View Source Code Vote up 4 votes
@Test
@IgnoreIfProperty(name = "test.filterrule.a", value = "a")
@Category(FailingTest.class)
public void testIgnoreIfPropExixtsandExcludedCategoryNotExists() {
    Assert.fail("Test should be Ignored");
}
 
Example 20
Project: linkifier   File: RegressionTest.java   View Source Code Vote up 4 votes
@Test
public void test168() throws Throwable {
    if (debug)
        System.out.format("%n%s%n", "RegressionTest0.test168");
    Column column4 = new Column(",", "");
    column4.setEstimatedRowCount((int) (byte) 0);
    Boolean b7 = column4.isBestAttemptPk();
    column4.setEstimatedPk(true);
    int i10 = column4.getDecimalDigits();
    Relationship relationship11 = new Relationship();
    Column column12 = relationship11.getPk();
    Boolean b13 = relationship11.getDataTypeCategoryAgree();
    Table table16 = new Table("", ",");
    relationship11.setPkTable(table16);
    List<Column> list_column18 = table16.getPk();
    table16.setColumnTokenWeight();
    String str20 = table16.toProbability();
    String str21 = table16.toProbability();
    column4.setDoppelganger(table16);
    Table table25 = new Table("", ",");
    table25.setTrimmedName("hi!");
    String str28 = table25.getLowerCaseTrimmedName();
    List<Column> list_column29 = table25.getEstimatedPk();
    column4.setDoppelganger(table25);
    Column column31 = new Column("schema,pk_table,pk_column,pk_dataTypeName,pk_isUnique,pk_isUniqueConstraint,pk_columnSize,pk_decimalDigits,pk_isDecimal,pk_hasDefault,pk_ordinalPosition,pk_ordinalPositionEnd,pk_tableColumnCount,pk_tableContainsLob,pk_estimatedRowCount,pk_isAutoincrement,pk_isNotNull,pk_nullRatio,pk_isNullable,pk_uniqueRatio,pk_minValue,pk_maxValue,pk_avgWidth,pk_avgWidthBigger10,pk_correlationAbs,pk_isKeywordSingleton,pk_isJunctionTable,pk_hasMultiplePK,pk_levenshteinDistance,pk_minLDOtherTable,pk_isDoppelganger,pk_contains,pk_isPrimaryKey,fk_table,fk_column,fk_dataTypeName,fk_isUnique,fk_isUniqueConstraint,fk_columnSize,fk_decimalDigits,fk_isDecimal,fk_hasDefault,fk_ordinalPosition,fk_ordinalPositionEnd,fk_tableColumnCount,fk_tableContainsLob,fk_estimatedRowCount,fk_isAutoincrement,fk_isNotNull,fk_nullRatio,fk_isNullable,fk_uniqueRatio,fk_minValue,fk_maxValue,fk_avgWidth,fk_avgWidthBigger10,fk_correlationAbs,fk_isKeywordSingleton,fk_isJunctionTable,fk_hasMultiplePK,fk_levenshteinDistance,fk_minLDOtherTable,fk_isDoppelganger,fk_contains,fk_isPrimaryKey,dataTypeAgree,dataTypeCategoryAgree,dataLengthAgree,decimalAgree,isTheSameColumn,isTheSameTable,firstCharAgree,nameAgree,levenshteinColumns,levenshteinToTable,levenshteinFromTable,tpcSimilarity,tokenShareRatioLd,chenColumnSimilarity,chenTableSimilarity,pkDoesNotHaveMoreTokensThanFk,avgWidthDiff,violatesCardinalityConstraint,isInRange,satisfiesFKConstraint,satisfiedFKRatio,rangeCoverage,histogramOverlap,violatesSpecialization,contains,isForeignKey", "null --> null", table25);
    DatabaseMetaData databaseMetaData32 = null;
    try {
        table25.getUniqueConstraint(databaseMetaData32, "hi!", ",", "hi!");
        Assert.fail("Expected exception of type java.lang.NullPointerException");
    } catch (NullPointerException e) {
    }
    Assert.assertTrue("'" + b7 + "' != '" + false + "'", b7.equals(false));
    Assert.assertTrue(i10 == 0);
    Assert.assertNull(column12);
    Assert.assertNull(b13);
    Assert.assertNotNull(list_column18);
    Assert.assertTrue("'" + str20 + "' != '" + "" + "'", str20.equals(""));
    Assert.assertTrue("'" + str21 + "' != '" + "" + "'", str21.equals(""));
    Assert.assertNull(str28);
    Assert.assertNotNull(list_column29);
}