本文整理匯總了Java中junit.framework.AssertionFailedError類的典型用法代碼示例。如果您正苦於以下問題:Java AssertionFailedError類的具體用法?Java AssertionFailedError怎麽用?Java AssertionFailedError使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
AssertionFailedError類屬於junit.framework包,在下文中一共展示了AssertionFailedError類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: compareResultsForThisListOfStimuli
import junit.framework.AssertionFailedError; //導入依賴的package包/類
private void compareResultsForThisListOfStimuli() {
int removes = Collections.frequency(Arrays.asList(stimuli), remove);
if ((!features.contains(IteratorFeature.SUPPORTS_REMOVE) && removes > 1)
|| (stimuli.length >= 5 && removes > 2)) {
// removes are the most expensive thing to test, since they often throw exceptions with stack
// traces, so we test them a bit less aggressively
return;
}
MultiExceptionListIterator reference = new MultiExceptionListIterator(expectedElements);
I target = newTargetIterator();
for (int i = 0; i < stimuli.length; i++) {
try {
stimuli[i].executeAndCompare(reference, target);
verify(reference.getElements());
} catch (AssertionFailedError cause) {
Helpers.fail(cause, "failed with stimuli " + subListCopy(stimuli, i + 1));
}
}
}
示例2: displayProblems
import junit.framework.AssertionFailedError; //導入依賴的package包/類
private void displayProblems( PrintWriter writer, String kind, int count, Enumeration enumeration ) {
if (count != 0) {
displayProblemTitle( writer, getFormatted( count, kind ) );
Enumeration e = enumeration;
for (int i = 1; e.hasMoreElements(); i++) {
TestFailure failure = (TestFailure) e.nextElement();
displayProblemDetailHeader( writer, i, failure.failedTest().toString() );
if (failure.thrownException() instanceof AssertionFailedError) {
displayProblemDetail( writer, failure.thrownException().getMessage() );
} else {
displayProblemDetail( writer, BaseTestRunner.getFilteredTrace( failure.thrownException() ) );
}
displayProblemDetailFooter( writer );
}
}
}
示例3: testFieldSetterWithArray
import junit.framework.AssertionFailedError; //導入依賴的package包/類
@Test
public void testFieldSetterWithArray() {
FieldAttributes fieldAttributes =
ClassAttributes.create(Person.class)
.getFields().stream()
.filter(f -> "secretName".equals(f.getName()))
.findFirst().orElseThrow(AssertionFailedError::new);
BiConsumer setter = fieldAttributes.getSetter();
Person instance = new Person();
Character[] secretName = {'s', 'u', 'p', 'e', 'r', 'm', 'a', 'n'};
setter.accept(instance, secretName);
char[] fromInstance = instance.getSecretName();
for (int i = 0; i < secretName.length; i++) {
assertTrue(secretName[i].equals(fromInstance[i]));
}
}
示例4: expectEvent
import junit.framework.AssertionFailedError; //導入依賴的package包/類
/**
* Expects a single event to be fired.
* After this call, the list of received events is reset, so each call checks events since the last call.
* @param propertyName optional property name which is expected (or null for any)
* @param timeout a timeout in milliseconds (zero means no timeout)
*/
public synchronized void expectEvent(String expectedPropertyName, long timeout) throws AssertionFailedError {
try {
if (events.isEmpty()) {
try {
wait(timeout);
} catch (InterruptedException x) {
fail(compose("Timed out waiting for event"));
}
}
assertFalse(compose("Did not get event"), events.isEmpty());
assertFalse(compose("Got too many events"), events.size() > 1);
PropertyChangeEvent received = events.iterator().next();
if (expectedPropertyName != null) {
assertEquals(msg, expectedPropertyName, received.getPropertyName());
}
} finally {
reset();
}
}
示例5: testTest_hash
import junit.framework.AssertionFailedError; //導入依賴的package包/類
public void testTest_hash() {
Object group1Item1 = new TestObject(1, 1);
Object group1Item2 = new TestObject(1, 2);
equivalenceMock.expectEquivalent(group1Item1, group1Item2);
equivalenceMock.expectEquivalent(group1Item2, group1Item1);
equivalenceMock.expectHash(group1Item1, 1);
equivalenceMock.expectHash(group1Item2, 2);
equivalenceMock.replay();
try {
tester.addEquivalenceGroup(group1Item1, group1Item2).test();
} catch (AssertionFailedError expected) {
String expectedMessage =
"the hash (1) of TestObject{group=1, item=1} [group 1, item 1] must be "
+ "equal to the hash (2) of TestObject{group=1, item=2} [group 1, item 2]";
if (!expected.getMessage().contains(expectedMessage)) {
fail("<" + expected.getMessage() + "> expected to contain <" + expectedMessage + ">");
}
return;
}
fail();
}
示例6: assertAlternatives
import junit.framework.AssertionFailedError; //導入依賴的package包/類
protected void assertAlternatives(ResolvedProperty propertyValue, String... expected) {
Set<ValueGrammarElement> alternatives = propertyValue.getAlternatives();
Collection<String> alts = convert(alternatives);
Collection<String> expc = new ArrayList<String>(Arrays.asList(expected));
if (alts.size() > expc.size()) {
alts.removeAll(expc);
throw new AssertionFailedError(String.format("Found %s unexpected alternative(s): %s", alts.size(), toString(alts)));
} else if (alts.size() < expc.size()) {
expc.removeAll(alts);
throw new AssertionFailedError(String.format("There're %s expected alternative(s) missing : %s", expc.size(), toString(expc)));
} else {
Collection<String> alts2 = new ArrayList<String>(alts);
Collection<String> expc2 = new ArrayList<String>(expc);
alts2.removeAll(expc);
expc2.removeAll(alts);
assertTrue(String.format("Missing expected: %s; Unexpected: %s", toString(expc2), toString(alts2)), alts2.isEmpty() && expc2.isEmpty());
}
}
示例7: addFailure
import junit.framework.AssertionFailedError; //導入依賴的package包/類
@Override
public void addFailure(Test arg0, AssertionFailedError arg1) {
String testName = arg0.toString();
testName = testName.substring(0, testName.indexOf('('));
out.println(" " + testName + " failed an assertion.");
StackTraceElement[] st = arg1.getStackTrace();
int i = 0;
for (StackTraceElement ste : st) {
if (ste.getClassName().contains("org.voltdb") == false)
continue;
out.printf(" %s(%s:%d)\n", ste.getClassName(), ste.getFileName(), ste.getLineNumber());
if (++i == 3) break;
}
m_failures++;
}
示例8: testInvalidHashCode
import junit.framework.AssertionFailedError; //導入依賴的package包/類
/**
* Test for an invalid hashCode method, i.e., one that returns different
* value for objects that are equal according to the equals method
*/
public void testInvalidHashCode() {
Object a = new InvalidHashCodeObject(1, 2);
Object b = new InvalidHashCodeObject(1, 2);
equalsTester.addEqualityGroup(a, b);
try {
equalsTester.testEquals();
} catch (AssertionFailedError e) {
assertErrorMessage(
e, "the Object#hashCode (" + a.hashCode() + ") of " + a
+ " [group 1, item 1] must be equal to the Object#hashCode ("
+ b.hashCode() + ") of " + b);
return;
}
fail("Should get invalid hashCode error");
}
示例9: testInvalidPath
import junit.framework.AssertionFailedError; //導入依賴的package包/類
@Test public void testInvalidPath() throws Exception {
final String[] invalidSchemaUris = {
"",
":",
"sms:",
":sms",
"sms:?goto=fail",
"sms:?goto=fail&fail=goto"
};
for (String uri : invalidSchemaUris) {
try {
new Rfc5724Uri(uri);
throw new AssertionFailedError("URISyntaxException should be thrown");
} catch (URISyntaxException e) {
// success
}
}
}
示例10: runRepeatingIfNecessary
import junit.framework.AssertionFailedError; //導入依賴的package包/類
/**
* Invokes the {@link #run} method. If AssertionFailedError is thrown,
* and repeatTimeoutMs is >0, then repeat the {@link #run} method until
* it either succeeds or repeatTimeoutMs milliseconds have passed. The
* AssertionFailedError is only thrown to the caller if the last run
* still throws it.
*/
public final void runRepeatingIfNecessary(long repeatTimeoutMs) {
long start = System.currentTimeMillis();
AssertionFailedError lastErr = null;
do {
try {
lastErr = null;
this.run();
CacheFactory.getAnyInstance().getLogger().fine("Completed " + this);
} catch (AssertionFailedError err) {
CacheFactory.getAnyInstance().getLogger().fine("Repeating " + this);
lastErr = err;
try {
Thread.sleep(50);
} catch (InterruptedException ex) {
throw new TestException("interrupted", ex);
}
}
} while (lastErr != null && System.currentTimeMillis() - start < repeatTimeoutMs);
if (lastErr != null) throw lastErr;
}
示例11: shutdown
import junit.framework.AssertionFailedError; //導入依賴的package包/類
private void shutdown(int idx) throws Exception {
qu.shutdown(idx);
// leader will shutdown, remaining followers will elect a new leader
PeerStruct peer = qu.getPeer(idx);
Assert.assertTrue("Waiting for server down", ClientBase.waitForServerDown(
"127.0.0.1:" + peer.clientPort, ClientBase.CONNECTION_TIMEOUT));
// if idx is the the leader then everyone will get disconnected,
// otherwise if idx is a follower then just that client will get
// disconnected
if (idx == idxLeader) {
checkClientDisconnected(idx);
try {
checkClientsDisconnected();
} catch (AssertionFailedError e) {
// the clients may or may not have already reconnected
// to the recovered cluster, force a check, but ignore
}
} else {
checkClientDisconnected(idx);
}
}
示例12: assertJson
import junit.framework.AssertionFailedError; //導入依賴的package包/類
/**
* compare JSON to the content of the specified file
*
* @param actualJson JSON to compare
* @param expectedFileName file name from which to load expected content
* @throws IOException if an I/O error occurs
* @throws NullPointerException if the file doesn't exist
*/
public void assertJson(String actualJson, String expectedFileName) throws IOException {
String path = String.format(PATH, testClass.getSimpleName(), methodName, expectedFileName);
try (InputStream resourceAsStream = testClass.getClassLoader().getResourceAsStream(path)) {
String expectedJson = IOUtils.toString(resourceAsStream, Charset.defaultCharset());
JsonNode actual = objectMapper.readTree(actualJson);
JsonNode expected = objectMapper.readTree(expectedJson);
LOGGER.info("EXPECTED JSON: " + expectedJson);
LOGGER.info("ACTUAL JSON: " + actualJson);
String diff = JsonDiff.asJson(actual, expected).toString();
if (!diff.equals("[]")) {
throw new AssertionFailedError("Json objects are not equal: " + diff);
}
}
}
示例13: testMappedToNull
import junit.framework.AssertionFailedError; //導入依賴的package包/類
@MapFeature.Require({SUPPORTS_PUT, ALLOWS_NULL_VALUES})
@CollectionSize.Require(absent = ZERO)
public void testMappedToNull() {
initMapWithNullValue();
assertEquals(
"Map.merge(keyMappedToNull, value, function) should return value",
v3(),
getMap()
.merge(
getKeyForNullValue(),
v3(),
(oldV, newV) -> {
throw new AssertionFailedError(
"Should not call merge function if key was mapped to null");
}));
expectReplacement(entry(getKeyForNullValue(), v3()));
}
示例14: testConfWithInvalidFile
import junit.framework.AssertionFailedError; //導入依賴的package包/類
@Test
public void testConfWithInvalidFile() throws Throwable {
String[] args = new String[1];
args[0] = "--conf=invalidFile";
Throwable th = null;
try {
FsShell.main(args);
} catch (Exception e) {
th = e;
}
if (!(th instanceof RuntimeException)) {
throw new AssertionFailedError("Expected Runtime exception, got: " + th)
.initCause(th);
}
}
示例15: testTransformAsync_interruptPropagatesToInput
import junit.framework.AssertionFailedError; //導入依賴的package包/類
public void testTransformAsync_interruptPropagatesToInput() throws Exception {
SettableFuture<Foo> input = SettableFuture.create();
AsyncFunction<Foo, Bar> function = new AsyncFunction<Foo, Bar>() {
@Override
public ListenableFuture<Bar> apply(Foo unused) {
throw new AssertionFailedError("Unexpeted call to apply.");
}
};
assertTrue(transformAsync(input, function, directExecutor()).cancel(true));
assertTrue(input.isCancelled());
assertTrue(input.wasInterrupted());
}