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

The following are Jave code examples for showing how to use fail() of the junit.framework.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: incubator-netbeans   File: ExecutionCompatibilityTest.java   View Source Code Vote up 6 votes
/** Executes the execution compatibility kit tests on the provided instance
 * of execution engine.
 */
public static Test suite(ExecutionEngine engine) {
    System.setProperty("org.openide.util.Lookup", ExecutionCompatibilityTest.class.getName() + "$Lkp");
    Object o = Lookup.getDefault();
    if (!(o instanceof Lkp)) {
        Assert.fail("Wrong lookup object: " + o);
    }
    
    Lkp l = (Lkp)o;
    l.assignExecutionEngine(engine);
    
    if (engine != null) {
        Assert.assertEquals("Same engine found", engine, ExecutionEngine.getDefault());
    } else {
        o = ExecutionEngine.getDefault();
        Assert.assertNotNull("Engine found", o);
        Assert.assertEquals(ExecutionEngine.Trivial.class, o.getClass());
    }
    
    TestSuite ts = new TestSuite();
    ts.addTestSuite(ExecutionEngineHid.class);
    
    return ts;
}
 
Example 2
Project: googles-monorepo-demo   File: Helpers.java   View Source Code Vote up 6 votes
public static void assertEqualIgnoringOrder(Iterable<?> expected, Iterable<?> actual) {
  List<?> exp = copyToList(expected);
  List<?> act = copyToList(actual);
  String actString = act.toString();

  // Of course we could take pains to give the complete description of the
  // problem on any failure.

  // Yeah it's n^2.
  for (Object object : exp) {
    if (!act.remove(object)) {
      Assert.fail(
          "did not contain expected element "
              + object
              + ", "
              + "expected = "
              + exp
              + ", actual = "
              + actString);
    }
  }
  assertTrue("unexpected elements: " + act, act.isEmpty());
}
 
Example 3
Project: Pogamut3   File: UT2004Test07_UT2004Server_SetGameMap.java   View Source Code Vote up 6 votes
private void changeMap(IUT2004Server server, String map) {
   	if (awaitAgentUp((AbstractAgent)server)) {
   		System.out.println("Changing map to '" + map + "'...");
   		Future<Boolean> future = server.setGameMap(map);
   		try {
   			System.out.println("Waiting for the GB2004 to change the map (60sec timeout).");
   			Boolean result = future.get(99990000, TimeUnit.MILLISECONDS);
       		if (result == null || !result) {
       			Assert.fail("Failed to change map to '" + map + "'.");
       		}
   		} catch (Exception e) {
   			Assert.fail("Failed to change map to '" + map + "'.");
   		}
   	} else {
   		Assert.fail("Failed to connect to GB2004...");
   	}
}
 
Example 4
Project: JavaGraph   File: GrammarsTest.java   View Source Code Vote up 6 votes
private void testDir(String dirName) {
    File location = new File(dirName);
    if (!location.isDirectory()) {
        try {
            Assert.fail(String.format("Directory %s cannot be found",
                location.getCanonicalPath()));
        } catch (IOException e) {
            Assert.fail(String.format("Directory %s cannot be parsed",
                location.getAbsolutePath()));
        }
    }
    for (File file : location.listFiles()) {
        if (FileType.GRAMMAR.hasExtension(file)) {
            testGrammar(file);
        }
    }
}
 
Example 5
Project: android-dev-challenge   File: PollingCheck.java   View Source Code Vote up 6 votes
public void run() {
    if (check()) {
        return;
    }

    long timeout = mTimeout;
    while (timeout > 0) {
        try {
            Thread.sleep(TIME_SLICE);
        } catch (InterruptedException e) {
            Assert.fail("unexpected InterruptedException");
        }

        if (check()) {
            return;
        }

        timeout -= TIME_SLICE;
    }

    Assert.fail("unexpected timeout");
}
 
Example 6
Project: incubator-netbeans   File: MeasureStartupTimeTestCase.java   View Source Code Vote up 6 votes
private static File findPlatform() {
    try {
        Class<?> lookup = Class.forName("org.openide.util.Lookup"); // NOI18N
        File util = new File(lookup.getProtectionDomain().getCodeSource().getLocation().toURI());
        Assert.assertTrue("Util exists: " + util, util.exists());

        return util.getParentFile().getParentFile();
    } catch (Exception ex) {
        try {
            File nbjunit = new File(MeasureStartupTimeTestCase.class.getProtectionDomain().getCodeSource().getLocation().toURI());
            File harness = nbjunit.getParentFile().getParentFile();
            Assert.assertEquals("NbJUnit is in harness", "harness", harness.getName());
            TreeSet<File> sorted = new TreeSet<>();
            for (File p : harness.getParentFile().listFiles()) {
                if (p.getName().startsWith("platform")) {
                    sorted.add(p);
                }
            }
            Assert.assertFalse("Platform shall be found in " + harness.getParent(), sorted.isEmpty());
            return sorted.last();
        } catch (Exception ex2) {
            Assert.fail("Cannot find utilities JAR: " + ex + " and: " + ex2);
        }
        return null;
    }
}
 
Example 7
Project: android-dev-challenge   File: PollingCheck.java   View Source Code Vote up 5 votes
public static void check(CharSequence message, long timeout, Callable<Boolean> condition)
        throws Exception {
    while (timeout > 0) {
        if (condition.call()) {
            return;
        }

        Thread.sleep(TIME_SLICE);
        timeout -= TIME_SLICE;
    }

    Assert.fail(message.toString());
}
 
Example 8
Project: dubbocloud   File: DubboProtocolTest.java   View Source Code Vote up 5 votes
@Test
public void testNonSerializedParameter() throws Exception
{
    DemoService service = new DemoServiceImpl();
    protocol.export(proxy.getInvoker(service, DemoService.class, URL.valueOf("dubbo://127.0.0.1:9050/" + DemoService.class.getName() + "?codec=exchange")));
    service = proxy.getProxy(protocol.refer(DemoService.class, URL.valueOf("dubbo://127.0.0.1:9050/" + DemoService.class.getName() + "?codec=exchange")));
    try {
        service.nonSerializedParameter(new NonSerialized());
        Assert.fail();
    } catch (RpcException e) {
        Assert.assertTrue(e.getMessage().contains("com.alibaba.dubbo.rpc.protocol.dubbo.support.NonSerialized must implement java.io.Serializable"));
    }
}
 
Example 9
Project: dubbocloud   File: ConfigTest.java   View Source Code Vote up 5 votes
@Test
public void testReferGenericExport() throws Exception {
    ApplicationConfig ac = new ApplicationConfig("test-refer-generic-export");
    RegistryConfig rc = new RegistryConfig();
    rc.setAddress(RegistryConfig.NO_AVAILABLE);

    ServiceConfig<GenericService> sc = new ServiceConfig<GenericService>();
    sc.setApplication(ac);
    sc.setRegistry(rc);
    sc.setInterface(DemoService.class.getName());
    sc.setRef(new GenericService() {

        public Object $invoke(String method, String[] parameterTypes, Object[] args) throws GenericException {
            return null;
        }
    });

    ReferenceConfig<DemoService> ref = new ReferenceConfig<DemoService>();
    ref.setApplication(ac);
    ref.setRegistry(rc);
    ref.setInterface(DemoService.class.getName());

    try {
        sc.export();
        ref.get();
        Assert.fail();
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        sc.unexport();
        ref.destroy();
    }
}
 
Example 10
Project: flume-release-1.7.0   File: TestJMSSource.java   View Source Code Vote up 5 votes
@Test
public void testProcessNoStart() throws Exception {
  try {
    source.process();
    Assert.fail();
  } catch (EventDeliveryException expected) {

  }
}
 
Example 11
Project: Pogamut3   File: EventDrivenWorldViewTester.java   View Source Code Vote up 5 votes
protected void test() {
	
	try {
		if (log.isLoggable(Level.INFO)) log.info("Starting worldview...");
		worldViewStarter.manualStart("starting worldview");
		if (log.isLoggable(Level.INFO)) log.info("Starting mediator...");
		mediator.start();
	} catch (PogamutException e) {
		e.printStackTrace();
		Assert.fail("WorldView failed to start.");
	}

	testBody();
	
	new WaitForFlagChange(mediator.getRunning(), false).await(900000, TimeUnit.MILLISECONDS);
	
	if (mediator.getEventQueueLength() != 0) {
		Assert.fail("Mediator failed to process all events in the queue...");
	}

	// STOP THE WORLDVIEW
	if (log.isLoggable(Level.INFO)) log.info("Stopping worldview...");
	worldViewStarter.manualStop("Stopping the test.");

	// VERIFY LISTENERS
	if (log.isLoggable(Level.INFO)) log.info("Verifying listeners...");
	verifyListeners();	
	
	Assert.assertFalse("Mediator did not stopped.", mediator.getRunning().getFlag());
}
 
Example 12
Project: flume-release-1.7.0   File: TestEventQueueBackingStoreFactory.java   View Source Code Vote up 5 votes
@Test(expected = BadCheckpointException.class)
public void testDecreaseCapacity() throws Exception {
  Assert.assertTrue(checkpoint.delete());
  EventQueueBackingStore backingStore =
      EventQueueBackingStoreFactory.get(checkpoint, 10, "test");
  backingStore.close();
  EventQueueBackingStoreFactory.get(checkpoint, 9, "test");
  Assert.fail();
}
 
Example 13
Project: android-dev-challenge   File: PollingCheck.java   View Source Code Vote up 5 votes
public static void check(CharSequence message, long timeout, Callable<Boolean> condition)
        throws Exception {
    while (timeout > 0) {
        if (condition.call()) {
            return;
        }

        Thread.sleep(TIME_SLICE);
        timeout -= TIME_SLICE;
    }

    Assert.fail(message.toString());
}
 
Example 14
Project: JavaGraph   File: IOTest.java   View Source Code Vote up 5 votes
@Test
public void testLoadAltStart() {
    int nodecount = 12;
    int edgecount = 14;
    try {
        testControl(Groove.loadGrammar(DIRECTORY),
            ALT_START,
            DEF_CONTROL,
            nodecount,
            edgecount);
    } catch (IOException e) {
        Assert.fail(e.toString());
    }
}
 
Example 15
Project: JavaGraph   File: ReteNetworkTest.java   View Source Code Vote up 5 votes
private Grammar loadGrammar(String grammarName, String startGraphName) {
    Grammar result = null;
    try {
        GrammarModel model = GrammarModel.newInstance(new File(INPUT_DIR, grammarName), false);
        model.setLocalActiveNames(ResourceKind.HOST, QualName.parse(startGraphName));
        result = model.toGrammar();
    } catch (IOException exc) {
        throw new RuntimeException(exc);
    } catch (FormatException ex) {
        Assert.fail("Could not load grammar. " + ex.getMessage());
    }
    return result;
}
 
Example 16
Project: android-dev-challenge   File: PollingCheck.java   View Source Code Vote up 5 votes
public static void check(CharSequence message, long timeout, Callable<Boolean> condition)
        throws Exception {
    while (timeout > 0) {
        if (condition.call()) {
            return;
        }

        Thread.sleep(TIME_SLICE);
        timeout -= TIME_SLICE;
    }

    Assert.fail(message.toString());
}
 
Example 17
Project: android-mobile-engage-sdk   File: InboxInternalTest.java   View Source Code Vote up 5 votes
@Test
public void testResetBadgeCount_shouldNotFail_withNullListener_failureWithException() {
    inbox.setAppLoginParameters(appLoginParameters_withCredentials);

    Exception expectedException = new Exception("FakeRestClientException");
    inbox.client = new FakeRestClient(expectedException);

    try {
        inbox.resetBadgeCount(null);
        Thread.sleep(150);
    } catch (Exception e) {
        Assert.fail("Should not throw exception!");
    }
}
 
Example 18
Project: flume-release-1.7.0   File: CipherProviderTestSuite.java   View Source Code Vote up 5 votes
public void testNullCipherText() throws Exception {
  try {
    decryptor.decrypt(null);
    Assert.fail();
  } catch (NullPointerException e) {
    // expected
  }
}
 
Example 19
Project: flume-release-1.7.0   File: TestLoadBalancingLog4jAppender.java   View Source Code Vote up 5 votes
@Test
public void testRandomBackoff() throws Exception {
  File TESTFILE = new File(TestLoadBalancingLog4jAppender.class
      .getClassLoader()
      .getResource("flume-loadbalancing-backoff-log4jtest.properties")
      .getFile());
  startSources(TESTFILE, false, new int[] { 25430, 25431, 25432 });

  sources.get(0).setFail();
  sources.get(2).setFail();

  sendAndAssertMessages(50);

  Assert.assertEquals(50, sources.get(1).appendCount.intValue());
  Assert.assertEquals(0, sources.get(0).appendCount.intValue());
  Assert.assertEquals(0, sources.get(2).appendCount.intValue());
  sources.get(0).setOk();
  sources.get(1).setFail(); // s0 should still be backed off
  try {
    send(1);
    // nothing should be able to process right now
    Assert.fail("Expected EventDeliveryException");
  } catch (FlumeException e) {
    Assert.assertTrue(e.getCause() instanceof EventDeliveryException);
  }
  Thread.sleep(2500); // wait for s0 to no longer be backed off

  sendAndAssertMessages(50);

  Assert.assertEquals(50, sources.get(0).appendCount.intValue());
  Assert.assertEquals(50, sources.get(1).appendCount.intValue());
  Assert.assertEquals(0, sources.get(2).appendCount.intValue());
}
 
Example 20
Project: aws-sdk-java-v2   File: ServiceIntegrationTest.java   View Source Code Vote up 5 votes
private String getVpcId() {
    List<Vpc> vpcs = ec2Client.describeVpcs(DescribeVpcsRequest.builder().build()).vpcs();
    if (vpcs.isEmpty()) {
        Assert.fail("No VPC found in this account.");
    }
    return vpcs.get(0).vpcId();
}