Java Code Examples for junit.framework.Assert

The following code examples are extracted from open source projects. You can click to vote up the examples that are useful to you.

Example 1

From project Aardvark, under directory /aardvark-core/src/test/java/gw/vark/.

Source file: TestprojectTest.java

  29 
vote

@Test public void enhancementContributedTargetIsPresent(){
  IType type=TypeSystem.getByFullNameIfValid("vark.SampleVarkFileEnhancement");
  if (!type.isValid()) {
    Assert.fail("Enhancement should be valid: " + ((IGosuClass)type).getParseResultsException().getFeedback());
  }
  InMemoryLogger logger=varkP();
  assertThat(logger).containsLinesThatContain("target-from-enhancement");
  assertThat(logger).excludesLinesThatContain("not-a-target-from-enhancement");
}
 

Example 2

From project addis, under directory /application/src/test/java/org/drugis/addis/presentation/wizard/.

Source file: SelectableOptionsModelTest.java

  29 
vote

@Test public void testClear(){
  d_model.addOption("Bladerdeeg",false);
  d_model.addOption("Geitenkaas",true);
  d_model.addOption("Komijn",false);
  d_model.addOption("Makreel",true);
  final ModifiableHolder<Integer> count=new ModifiableHolder<Integer>(0);
  ObservableList<String> list=d_model.getSelectedOptions();
  ListDataListener counter=new ListDataListener(){
    @Override public void intervalRemoved(    ListDataEvent e){
      count.setValue(count.getValue() + (e.getIndex1() - e.getIndex0()) + 1);
    }
    @Override public void intervalAdded(    ListDataEvent e){
      Assert.fail("Expected INTERVAL_REMOVED, but got " + e);
    }
    @Override public void contentsChanged(    ListDataEvent e){
      Assert.fail("Expected INTERVAL_REMOVED, but got " + e);
    }
  }
;
  list.addListDataListener(counter);
  d_model.clear();
  list.removeListDataListener(counter);
  assertEquals(new Integer(2),count.getValue());
  assertEquals(Collections.emptyList(),d_model.getSelectedOptions());
}
 

Example 3

From project adt-maven-plugin, under directory /src/test/java/com/yelbota/plugins/adt/.

Source file: PackageAdtMojoTest.java

  29 
vote

@Test public void validateCertificateTest(){
  PackageAdtMojo mojo=new PackageAdtMojo();
  mojo.target="air";
  commonRequiredCertificateTest(mojo);
  mojo.target="apk";
  commonRequiredCertificateTest(mojo);
  mojo.target="ipa";
  mojo.provisioningProfile=FileUtils.resolveFile(wd,"src/test/resources/unit/application.mobileprovision");
  commonRequiredCertificateTest(mojo);
  mojo.target="airi";
  mojo.storetype=null;
  mojo.keystore=null;
  mojo.storepass=null;
  try {
    mojo.validateCertificate();
  }
 catch (  AdtConfigurationException e) {
    Assert.fail();
  }
}
 

Example 4

From project AeminiumRuntime, under directory /src/aeminium/runtime/tests/.

Source file: AtomicTaskDeadLock.java

  29 
vote

@Test(timeout=2000) public void createAtomicTaskDeadLock(){
  final AtomicBoolean deadlock=new AtomicBoolean(false);
  Runtime rt=getRuntime();
  rt.init();
  rt.addErrorHandler(new ErrorHandler(){
    @Override public void handleTaskException(    Task task,    Throwable t){
    }
    @Override public void handleTaskDuplicatedSchedule(    Task task){
    }
    @Override public void handleLockingDeadlock(){
      deadlock.set(true);
    }
    @Override public void handleInternalError(    Error err){
    }
    @Override public void handleDependencyCycle(    Task task){
    }
  }
);
  DataGroup dg1=rt.createDataGroup();
  DataGroup dg2=rt.createDataGroup();
  Task t1=createAtomicTask(rt,dg1,dg2);
  rt.schedule(t1,Runtime.NO_PARENT,Runtime.NO_DEPS);
  Task t2=createAtomicTask(rt,dg2,dg1);
  rt.schedule(t2,Runtime.NO_PARENT,Runtime.NO_DEPS);
  try {
    Thread.sleep(1500);
  }
 catch (  InterruptedException e1) {
  }
  if (!deadlock.get()) {
    Assert.fail("Could not find deadlock");
    rt.shutdown();
  }
}
 

Example 5

From project agraph-java-client, under directory /src/test/.

Source file: AGGraphQueryTests.java

  29 
vote

@Test @Category(TestSuites.Prepush.class) public void graphQuery_count_rfe10447() throws Exception {
  conn.add(new File("src/test/example.nq"),null,AGRDFFormat.NQUADS);
  String queryString="construct {?s ?p ?o} where {?s ?p ?o}";
  AGGraphQuery q=conn.prepareGraphQuery(QueryLanguage.SPARQL,queryString);
  Assert.assertEquals("expected size 10",10,q.count());
  queryString="construct {?s ?p ?o} where " + "{GRAPH <http://example.org/alice/foaf.rdf> {?s ?p ?o}}";
  q=conn.prepareGraphQuery(QueryLanguage.SPARQL,queryString);
  Assert.assertEquals("expected size 7",7,q.count());
  queryString="construct {?s ?p ?o} where " + "{GRAPH <http://example.org/bob/foaf.rdf> {?s ?p ?o}}";
  q=conn.prepareGraphQuery(QueryLanguage.SPARQL,queryString);
  Assert.assertEquals("expected size 3",3,q.count());
  queryString="construct {?s ?p ?o} where " + "{GRAPH <http://example.org/carol/foaf.rdf> {?s ?p ?o}}";
  q=conn.prepareGraphQuery(QueryLanguage.SPARQL,queryString);
  Assert.assertEquals("expected size 0",0,q.count());
  queryString="describe <http://example.org/alice/foaf.rdf#me>";
  q=conn.prepareGraphQuery(QueryLanguage.SPARQL,queryString);
  Assert.assertEquals("expected size 7",7,q.count());
}
 

Example 6

From project Aion-Extreme, under directory /AE-go_GameServer/test/com/aionemu/gameserver/utils/.

Source file: IteratorIteratorTest.java

  29 
vote

@Test public void testIt(){
  Map<Integer,Set<Integer>> map1=new HashMap<Integer,Set<Integer>>();
  Set set1=new HashSet<Integer>();
  Collections.addAll(set1,50,60,70,80);
  Set set2=new HashSet<Integer>();
  Collections.addAll(set2,1);
  Set set3=new HashSet<Integer>();
  Collections.addAll(set3);
  Set set4=new HashSet<Integer>();
  Collections.addAll(set4,99,100);
  map1.put(1,set1);
  map1.put(2,set2);
  map1.put(3,set3);
  map1.put(4,set4);
  List<Integer> res=new ArrayList<Integer>();
  IteratorIterator<Integer> it=new IteratorIterator<Integer>(map1.values());
  int valNum=0;
  while (it.hasNext()) {
    valNum++;
    Integer v=it.next();
    res.add(v);
  }
  List<Integer> goodRes=new ArrayList<Integer>();
  Collections.addAll(goodRes,50,60,70,80,1,99,100);
  Assert.assertEquals(7,valNum);
  Assert.assertTrue(res.containsAll(goodRes) && goodRes.containsAll(res));
}
 

Example 7

From project ajah, under directory /ajah-image/src/test/java/test/ajah/image/.

Source file: ImageUtilsTest.java

  29 
vote

/** 
 * Test extracting infromation from a GIF.
 * @throws IOException
 */
@Test public void testGif() throws IOException {
  final byte[] data=StreamUtils.toByteArray(getClass().getResourceAsStream("/test.gif"));
  final ImageInfo info=ImageUtils.getInfo(data);
  Assert.assertEquals(50,info.getHeight());
  Assert.assertEquals(50,info.getWidth());
  Assert.assertEquals("gif",info.getFormat().getSuffix());
}
 

Example 8

From project alphaportal_dev, under directory /sys-src/alphaportal/web/src/test/java/alpha/portal/webapp/filter/.

Source file: LocaleFilterTest.java

  29 
vote

/** 
 * Test set locale in session when session is null.
 * @throws Exception the exception
 */
public void testSetLocaleInSessionWhenSessionIsNull() throws Exception {
  final MockHttpServletRequest request=new MockHttpServletRequest();
  request.addParameter("locale","es");
  final MockHttpServletResponse response=new MockHttpServletResponse();
  this.filter.doFilter(request,response,new MockFilterChain());
  Assert.assertNull(request.getSession().getAttribute(Constants.PREFERRED_LOCALE_KEY));
  Assert.assertNotNull(LocaleContextHolder.getLocale());
}
 

Example 9

From project amber, under directory /oauth-2.0/authzserver/src/test/java/org/apache/amber/oauth2/as/.

Source file: MD5GeneratorTest.java

  29 
vote

@Test public void testGenerateValue() throws Exception {
  ValueGenerator g=new MD5Generator();
  Assert.assertNotNull(g.generateValue());
  Assert.assertNotNull(g.generateValue("test"));
  try {
    g.generateValue(null);
    fail("Exception not thrown");
  }
 catch (  OAuthSystemException e) {
  }
}
 

Example 10

From project and-bible, under directory /jsword-tweaks/src/util/java/net/andbible/util/.

Source file: Test.java

  29 
vote

public void testInvalidKey(){
  Book book=Books.installed().getBook("Pilgrim");
  if (book != null) {
    Key key=book.getGlobalKeyList();
    try {
      book.getRawText(key);
    }
 catch (    NullPointerException e) {
      Assert.fail("test for bad key should not have thrown an NPE.");
    }
catch (    BookException e) {
      System.out.println(e.getMessage());
      Assert.assertEquals("testing for a bad key","No entry for '' in Pilgrim.",e.getMessage());
    }
  }
}
 

Example 11

From project Android-automation, under directory /Tmts_Java/src/com/taobao/tmts/framework/utils/.

Source file: ActivityUtils.java

  29 
vote

/** 
 * Returns to the given  {@link Activity}.
 * @param name the name of the  {@code Activity} to return to, e.g.{@code "MyActivity"}
 */
public void goBackToActivity(String name){
  boolean found=false;
  for (  Activity activity : activityList) {
    if (activity.getClass().getSimpleName().equals(name))     found=true;
  }
  if (found) {
    while (!getCurrentActivity().getClass().getSimpleName().equals(name)) {
      try {
        inst.sendKeyDownUpSync(KeyEvent.KEYCODE_BACK);
      }
 catch (      SecurityException e) {
        Assert.assertTrue("Activity named " + name + " can not be returned to",false);
      }
    }
  }
 else {
    for (int i=0; i < activityList.size(); i++)     Log.d("Robotium","Activity priorly opened: " + activityList.get(i).getClass().getSimpleName());
    Assert.assertTrue("No Activity named " + name + " has been priorly opened",false);
  }
}
 

Example 12

From project android-flip, under directory /FlipView/FlipLibrary/src/com/aphidmobile/flip/.

Source file: FlipViewController.java

  29 
vote

@Override public void setSelection(int position){
  if (adapter == null)   return;
  Assert.assertTrue("Invalid selection position",position >= 0 && position < adapter.getCount());
  releaseViews();
  View selectedView=viewFromAdapter(position,true);
  bufferedViews.add(selectedView);
  for (int i=1; i <= sideBufferSize; i++) {
    int previous=position - i;
    int next=position + i;
    if (previous >= 0)     bufferedViews.addFirst(viewFromAdapter(previous,false));
    if (next < adapter.getCount())     bufferedViews.addLast(viewFromAdapter(next,true));
  }
  bufferIndex=bufferedViews.indexOf(selectedView);
  adapterIndex=position;
  requestLayout();
  updateVisibleView(inFlipAnimation ? -1 : bufferIndex);
}
 

Example 13

From project android-marvin, under directory /marvin/src/main/java/de/akquinet/android/marvin/actions/.

Source file: BaseAction.java

  29 
vote

public void click(float x,float y){
  MotionEvent downEvent=MotionEvent.obtain(SystemClock.uptimeMillis(),SystemClock.uptimeMillis(),MotionEvent.ACTION_DOWN,x,y,0);
  MotionEvent upEvent=MotionEvent.obtain(SystemClock.uptimeMillis(),SystemClock.uptimeMillis(),MotionEvent.ACTION_UP,x,y,0);
  try {
    instrumentation.sendPointerSync(downEvent);
    instrumentation.sendPointerSync(upEvent);
  }
 catch (  SecurityException e) {
    Assert.fail("Click on (" + x + ","+ y+ ") failed.");
  }
}
 

Example 14

From project androidannotations, under directory /AndroidAnnotations/functional-test-1-5-tests/src/test/java/com/googlecode/androidannotations/test15/.

Source file: SSLConnectionTest.java

  29 
vote

@Test public void truststoreProvided(){
  assertNotNull(activity.mHttpsClientTest1);
  ClientConnectionManager ccm=activity.mHttpsClientTest1.getConnectionManager();
  assertNotNull(ccm);
  Scheme httpsScheme=ccm.getSchemeRegistry().getScheme("https");
  assertNotNull(httpsScheme);
  assertEquals(443,httpsScheme.getDefaultPort());
  SocketFactory socketFactHttps=httpsScheme.getSocketFactory();
  if (!(socketFactHttps instanceof SSLSocketFactory)) {
    Assert.fail("wrong instance should be org.apache.http.conn.ssl.SSLSocketFactory, getting " + socketFactHttps);
  }
  assertEquals(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER,((SSLSocketFactory)socketFactHttps).getHostnameVerifier());
}
 

Example 15

From project Android_1, under directory /org.eclipse.ecf.android/src/org/eclipse/ecf/android/.

Source file: AddRegistrationRequest.java

  29 
vote

/** 
 * @since 3.0
 */
public AddRegistrationRequest(ID targetID,String service,RegularExpression filter2,AddRegistrationRequest parent){
  this.targetID=null;
  Assert.assertNotNull(service);
  this.service=service;
  this.filter=filter2;
  this.parent=parent;
}
 

Example 16

From project android_packages_apps_Gallery2, under directory /tests/src/com/android/gallery3d/util/.

Source file: ProfileTest.java

  29 
vote

private void checkIsFirstEntry(Entry entry){
  Assert.assertEquals(0,entry.sampleCount);
  Assert.assertEquals(3,entry.stackId.length);
  Assert.assertEquals(1,entry.stackId[0]);
  Assert.assertTrue(entry.stackId[1] > 0);
  Assert.assertEquals(0,entry.stackId[2]);
}
 

Example 17

From project android_packages_apps_QuickSearchBox, under directory /tests/src/com/android/quicksearchbox/.

Source file: ShortcutRepositoryTest.java

  29 
vote

/** 
 * an implementation of  {@link MoreAsserts#assertContentsInOrder(String,Iterable,Object[])}that isn't busted.  a bug has been filed about that, but for now this works.
 */
static void assertContentsInOrder(String message,Iterable<?> actual,Object... expected){
  ArrayList actualList=new ArrayList();
  for (  Object o : actual) {
    actualList.add(o);
  }
  Assert.assertEquals(message,Arrays.asList(expected),actualList);
}
 

Example 18

From project androlog, under directory /androlog-it/src/test/android/de/akquinet/gomobile/androlog/test/.

Source file: AndrologInitTest.java

  29 
vote

public void testDefaultInit(){
  Log.init();
  Assert.assertEquals(Constants.INFO,Log.getDefaultLogLevel());
  String message="This is a INFO test";
  String tag="my.log.info";
  int expected=tag.length() + message.length() + 3;
  int x=Log.d(tag,message);
  Assert.assertEquals(0,x);
  x=Log.i(tag,message);
  Assert.assertEquals(expected,x);
  x=Log.w(tag,message);
  Assert.assertEquals(expected,x);
}
 

Example 19

From project ant4eclipse, under directory /org.ant4eclipse.lib.pde.test/src/org/ant4eclipse/lib/pde/model/launcher/.

Source file: SimpleConfiguratorBundlesTest.java

  29 
vote

@Test public void loadBundlesInfo(){
  File bundlesfile=Utilities.exportResource("/org/ant4eclipse/testframework/bundles.info");
  SimpleConfiguratorBundles bundles=new SimpleConfiguratorBundles(bundlesfile);
  BundleStartRecord[] records=bundles.getBundleStartRecords();
  Assert.assertNotNull(records);
  Assert.assertEquals(DATA.length,records.length);
  for (int i=0; i < records.length; i++) {
    Assert.assertNotNull(records[i]);
    Object[] expected=DATA[i];
    Assert.assertEquals(expected[2],records[i].getId());
    Assert.assertEquals(expected[0],Integer.valueOf(records[i].getStartLevel()));
    Assert.assertEquals(expected[1],Boolean.valueOf(records[i].isAutoStart()));
  }
}
 

Example 20

From project any23, under directory /core/src/test/java/org/apache/any23/.

Source file: Any23Test.java

  29 
vote

/** 
 * Tests out the first code snipped used in <i>Developer Manual</i>.
 * @throws IOException
 * @throws org.apache.any23.extractor.ExtractionException
 */
@Test public void testDemoCodeSnippet1() throws Exception {
  Any23 runner=new Any23();
  final String content="@prefix foo: <http://example.org/ns#> .   " + "@prefix : <http://other.example.org/ns#> ." + "foo:bar foo: : .                          "+ ":bar : foo:bar .                           ";
  DocumentSource source=new StringDocumentSource(content,"http://host.com/service");
  ByteArrayOutputStream out=new ByteArrayOutputStream();
  TripleHandler handler=new NTriplesWriter(out);
  try {
    runner.extract(source,handler);
  }
  finally {
    handler.close();
  }
  String nt=out.toString("UTF-8");
  logger.debug("nt: " + nt);
  Assert.assertTrue(nt.length() > 0);
}