Java Code Examples for org.junit.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 aether-core, under directory /aether-test-util/src/main/java/org/eclipse/aether/internal/test/util/.

Source file: TestFileUtils.java

  16 
vote

public static void assertContent(String expected,File file) throws IOException {
  byte[] content=getContent(file);
  String msg=new String(content,"UTF-8");
  if (msg.length() > 10) {
    msg=msg.substring(0,10) + "...";
  }
  Assert.assertArrayEquals("content was '" + msg + "'\n",expected.getBytes("UTF-8"),content);
}
 

Example 2

From project ACLS-protocol-library, under directory /aclslib/src/test/java/au/edu/uq/cmm/acslib/service/.

Source file: MonitoredThreadServiceBaseTest.java

  15 
vote

@Test public void testStartupShutdown() throws InterruptedException {
  BlockingDeque<String> status=new LinkedBlockingDeque<String>();
  AtomicBoolean killSwitch=new AtomicBoolean();
  Service service=new MTSBTestService(status,killSwitch,1,1,500);
  Assert.assertNull(status.pollFirst());
  Assert.assertEquals(State.INITIAL,service.getState());
  service.startup();
  Assert.assertEquals(State.STARTED,service.getState());
  Assert.assertEquals("running",status.pollFirst(2,TimeUnit.SECONDS));
  service.shutdown();
  Assert.assertEquals(State.STOPPED,service.getState());
  Assert.assertEquals("finished",status.pollFirst(2,TimeUnit.SECONDS));
}
 

Example 3

From project ACLS-protocol-library, under directory /aclslib/src/test/java/au/edu/uq/cmm/acslib/service/.

Source file: MonitoredThreadServiceBaseTest.java

  15 
vote

@Test public void testStartupDieRestartShutdown() throws InterruptedException {
  BlockingDeque<String> status=new LinkedBlockingDeque<String>();
  AtomicBoolean killSwitch=new AtomicBoolean();
  Service service=new MTSBTestService(status,killSwitch,1,1,500);
  Assert.assertNull(status.pollFirst());
  Assert.assertEquals(State.INITIAL,service.getState());
  service.startup();
  Assert.assertEquals("running",status.pollFirst(2,TimeUnit.SECONDS));
  Assert.assertEquals(State.STARTED,service.getState());
  killSwitch.set(true);
  Assert.assertEquals("arrggghhh",status.pollFirst(2,TimeUnit.SECONDS));
  Assert.assertEquals("running",status.pollFirst(2,TimeUnit.SECONDS));
  Assert.assertEquals(State.STARTED,service.getState());
  service.shutdown();
  Assert.assertEquals(State.STOPPED,service.getState());
  Assert.assertEquals("finished",status.pollFirst(2,TimeUnit.SECONDS));
}
 

Example 4

From project AdServing, under directory /modules/tools/import/src/test/java/net/mad/ads/base/api/importer/reader/.

Source file: AdReaderTest.java

  15 
vote

public static void main(String[] args) throws Exception {
  AdDefinition banner=AdXmlReader.readBannerDefinition("testdata/data/importer/demo/banner01.xml");
  Assert.assertNotNull(banner.getType());
  Assert.assertNotNull(banner.getFormat());
  System.out.println(banner.getType().getName());
  System.out.println(banner.getFormat().getName());
  if (banner.hasConditionDefinition(ConditionDefinitions.DAY)) {
    System.out.println(((DayConditionDefinition)banner.getConditionDefinition(ConditionDefinitions.DAY)).getDays().size());
  }
  if (banner.hasConditionDefinition(ConditionDefinitions.STATE)) {
    System.out.println(((StateConditionDefinition)banner.getConditionDefinition(ConditionDefinitions.STATE)).getStates().size());
  }
  if (banner.hasConditionDefinition(ConditionDefinitions.DISTANCE)) {
    System.out.println("distance");
    DistanceConditionDefinition dd=(DistanceConditionDefinition)banner.getConditionDefinition(ConditionDefinitions.DISTANCE);
    System.out.println(dd.getGeoRadius());
    System.out.println(dd.getGeoLocation().getLatitude());
    System.out.println(dd.getGeoLocation().getLongitude());
  }
  if (banner.hasConditionDefinition(ConditionDefinitions.VIEW_EXPIRATION)) {
    ViewExpirationConditionDefinition dd=(ViewExpirationConditionDefinition)banner.getConditionDefinition(ConditionDefinitions.VIEW_EXPIRATION);
    System.out.println("view expiration");
    for (    ExpirationResolution res : dd.getViewExpirations().keySet()) {
      System.out.println(res.getName() + " = " + dd.getViewExpirations().get(res));
    }
  }
  if (banner.hasConditionDefinition(ConditionDefinitions.CLICK_EXPIRATION)) {
    ClickExpirationConditionDefinition dd=(ClickExpirationConditionDefinition)banner.getConditionDefinition(ConditionDefinitions.CLICK_EXPIRATION);
    System.out.println("click expiration");
    for (    ExpirationResolution res : dd.getClickExpirations().keySet()) {
      System.out.println(res.getName() + " = " + dd.getClickExpirations().get(res));
    }
  }
}
 

Example 5

From project aerogear-controller, under directory /src/test/java/org/jboss/aerogear/controller/.

Source file: TypeNameExtractorTest.java

  15 
vote

@Test public void shouldDecapitalizeSomeCharsUntilItFindsOneUppercased() throws NoSuchMethodException {
  Assert.assertEquals("urlClassLoader",extractor.nameFor(URLClassLoader.class));
  Assert.assertEquals("bigDecimal",extractor.nameFor(BigDecimal.class));
  Assert.assertEquals("string",extractor.nameFor(String.class));
  Assert.assertEquals("aClass",extractor.nameFor(AClass.class));
  Assert.assertEquals("url",extractor.nameFor(URL.class));
}
 

Example 6

From project aerogear-controller, under directory /src/test/java/org/jboss/aerogear/controller/.

Source file: TypeNameExtractorTest.java

  15 
vote

@Test public void shouldDecapitalizeSomeCharsUntilItFindsOneUppercasedForListsAndArrays() throws NoSuchMethodException, SecurityException, NoSuchFieldException {
  Assert.assertEquals("stringList",extractor.nameFor(getField("strings")));
  Assert.assertEquals("bigDecimalList",extractor.nameFor(getField("bigs")));
  Assert.assertEquals("hashSet",extractor.nameFor(getField("bigsOld")));
  Assert.assertEquals("class",extractor.nameFor(getField("clazz")));
  Assert.assertEquals("aClassList",extractor.nameFor(AClass[].class));
  Assert.assertEquals("urlClassLoaderList",extractor.nameFor(getField("urls")));
}
 

Example 7

From project agorava-core, under directory /agorava-core-impl/src/test/java/org/agorava/core/oauth/.

Source file: PropertySettingsBuilderTest.java

  15 
vote

@Test public void testDefaultBuild(){
  OAuthAppSettingsBuilder builderOAuthApp=new PropertyOAuthAppSettingsBuilder();
  OAuthAppSettings settings=builderOAuthApp.build();
  Assert.assertEquals(settings.getApiKey(),"dummy");
  Assert.assertEquals(settings.getApiSecret(),"dummySecret");
  Assert.assertEquals(settings.getScope(),"dummyScope");
  Assert.assertEquals(settings.getCallback(),"undefineddummyCallback");
}
 

Example 8

From project agorava-core, under directory /agorava-core-impl/src/test/java/org/agorava/core/oauth/.

Source file: PropertySettingsBuilderTest.java

  15 
vote

@Test public void testDefaultBuildWithPrefix(){
  PropertyOAuthAppSettingsBuilder builder=new PropertyOAuthAppSettingsBuilder();
  builder.prefix("test");
  OAuthAppSettings settings=builder.build();
  Assert.assertEquals(settings.getApiKey(),"dummy2");
  Assert.assertEquals(settings.getApiSecret(),"dummySecret2");
}
 

Example 9

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

Source file: AGConnPoolSessionTest.java

  15 
vote

@Test @Category(TestSuites.Prepush.class) public void testPlain() throws Exception {
  AGServer server=closeLater(new AGServer(AGAbstractTest.findServerUrl(),AGAbstractTest.username(),AGAbstractTest.password()));
  AGCatalog catalog=server.getCatalog("/");
  AGRepository repo=closeLater(catalog.createRepository("pool.testPlain"));
  AGRepositoryConnection conn=closeLater(repo.getConnection());
  Assert.assertTrue(conn.toString(),conn.getHttpRepoClient().getRoot().contains(AGAbstractTest.findServerUrl()));
  Assert.assertEquals(0,conn.size());
  conn.deleteDatatypeMapping(XMLSchema.DOUBLE);
  conn.setSessionLifetime(60);
  conn.setAutoCommit(true);
  conn.deleteDatatypeMapping(XMLSchema.FLOAT);
  Assert.assertEquals(0,conn.size());
}
 

Example 10

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

Source file: AGConnPoolSessionTest.java

  15 
vote

@Test @Category(TestSuites.Prepush.class) public void testPoolDedicated() throws Exception {
  AGConnPool pool=closeLater(AGConnPool.create(AGConnProp.serverUrl,AGAbstractTest.findServerUrl(),AGConnProp.username,AGAbstractTest.username(),AGConnProp.password,AGAbstractTest.password(),AGConnProp.catalog,"/",AGConnProp.repository,"pool.testPoolDedicated",AGConnProp.session,AGConnProp.Session.DEDICATED,AGConnProp.sessionLifetime,TimeUnit.MINUTES.toSeconds(1),AGPoolProp.shutdownHook,true,AGPoolProp.testOnBorrow,true,AGPoolProp.maxWait,TimeUnit.SECONDS.toMillis(30)));
  AGRepositoryConnection conn=closeLater(pool.borrowConnection());
  Assert.assertFalse(conn.toString(),conn.getHttpRepoClient().getRoot().contains(AGAbstractTest.findServerUrl()));
  Assert.assertEquals(0,conn.size());
  conn.deleteDatatypeMapping(XMLSchema.DOUBLE);
  conn.deleteDatatypeMapping(XMLSchema.FLOAT);
  Assert.assertEquals(0,conn.size());
}
 

Example 11

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

Source file: ZipCodeTest.java

  15 
vote

/** 
 * Test alpha chars
 */
@Test(expected=IllegalZipCodeFormatException.class) public void alphaChars(){
  final ZipCode test=new ZipCode();
  test.setZip(null);
  test.setZip4("abs");
  Assert.assertNull(test.toString());
}
 

Example 12

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

Source file: ZipCodeTest.java

  15 
vote

/** 
 * Test alphanumeric chars
 */
@Test(expected=IllegalZipCodeFormatException.class) public void alphaNumericChars(){
  final ZipCode test=new ZipCode();
  test.setZip(null);
  test.setZip4("12345abs");
  Assert.assertNull(test.toString());
}
 

Example 13

From project AlgorithmsNYC, under directory /SlidingPuzzle/test/.

Source file: TestBoard.java

  15 
vote

@Test public void testBoardEquals() throws Exception {
  Board board=new Board(4);
  System.out.println("\ncom.oti.Board: ");
  board.describeBoard();
  Board otherBoard=new Board(4);
  System.out.println("\nOther com.oti.Board: ");
  otherBoard.describeBoard();
  Board clonedBoard=board.clone();
  System.out.println("\nCloned com.oti.Board: ");
  clonedBoard.describeBoard();
  Assert.assertThat(board,is(otherBoard));
  Assert.assertThat(board,is(clonedBoard));
}
 

Example 14

From project AlgorithmsNYC, under directory /SlidingPuzzle/test/.

Source file: TestBoard.java

  15 
vote

@Test public void testBoardRandomAndCustom() throws Exception {
  Board board=new Board(4);
  board.randomSolvableInitialState(1000,3,true);
  System.out.println("\nRandom com.oti.Board: ");
  board.describeBoard();
  Board customBoard=new Board(4,1,2,3,4,5,6,0,7,9,10,11,8,13,14,15,12);
  System.out.println("\nCustom com.oti.Board: ");
  customBoard.describeBoard();
  Assert.assertEquals(board,customBoard);
  Board differentBoard=new Board(4,1,2,3,4,5,6,7,8,9,0,11,12,13,10,15,14);
  System.out.println("\nDifferent com.oti.Board: ");
  differentBoard.describeBoard();
  Assert.assertFalse(board.equals(differentBoard));
}
 

Example 15

From project almira-sample, under directory /almira-sample-api/src/test/java/almira/sample/domain/.

Source file: CatapultObjectTest.java

  15 
vote

@Test public void toStringContainsIdAndName(){
  String id="" + x.getId();
  String name=x.getName();
  Assert.assertTrue("String contains id",x.toString().contains("id=" + id));
  Assert.assertTrue("String contains name",x.toString().contains("name=" + name));
}
 

Example 16

From project almira-sample, under directory /almira-sample-api/src/test/java/almira/sample/domain/.

Source file: CatapultObjectTest.java

  15 
vote

@Test public void compareToIsTransitive(){
  Catapult z=new CatapultBuilder(2L,"cata3").build();
  Assert.assertTrue(x.compareTo(y) < 0);
  Assert.assertTrue(y.compareTo(z) < 0);
  Assert.assertTrue(x.compareTo(z) < 0);
}
 

Example 17

From project alphaportal_dev, under directory /sys-src/alphaportal/core/src/test/java/alpha/portal/dao/.

Source file: AlphaCardDaoTest.java

  15 
vote

/** 
 * Test get version.
 * @throws Exception the exception
 */
@Test public void testGetVersion() throws Exception {
  AlphaCase aCase=new AlphaCase();
  aCase.setName("Test Case");
  aCase=this.caseDao.save(aCase);
  this.flush();
  AlphaCard card=new AlphaCard(aCase);
  card=this.alphaCardDao.save(card);
  this.flush();
  Assert.assertTrue(this.alphaCardDao.exists(card.getAlphaCardIdentifier()));
  AlphaCard aCard=this.alphaCardDao.getVersion(new AlphaCardIdentifier());
  Assert.assertNull(aCard);
  aCard=this.alphaCardDao.get(new AlphaCardIdentifier());
  Assert.assertNull(aCard);
  Assert.assertFalse(this.alphaCardDao.exists(new AlphaCardIdentifier()));
}
 

Example 18

From project alphaportal_dev, under directory /sys-src/alphaportal/core/src/test/java/alpha/portal/dao/.

Source file: AlphaCardDaoTest.java

  15 
vote

/** 
 * Test remove.
 * @throws Exception the exception
 */
@Test(expected=AccessDeniedException.class) public void testRemove() throws Exception {
  AlphaCase aCase=new AlphaCase();
  aCase.setName("Test Case");
  aCase=this.caseDao.save(aCase);
  this.flush();
  AlphaCard card=new AlphaCard(aCase);
  card=this.alphaCardDao.save(card);
  this.flush();
  Assert.assertTrue(this.alphaCardDao.exists(card.getAlphaCardIdentifier()));
  this.alphaCardDao.remove(card.getAlphaCardIdentifier());
}
 

Example 19

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

Source file: OAuthASResponseTest.java

  15 
vote

@Test public void testAuthzResponse() throws Exception {
  HttpServletRequest request=createMock(HttpServletRequest.class);
  OAuthResponse oAuthResponse=OAuthASResponse.authorizationResponse(request,200).location("http://www.example.com").setCode("code").setAccessToken("access_111").setExpiresIn(400l).setState("ok").setParam("testValue","value2").buildQueryMessage();
  String url=oAuthResponse.getLocationUri();
  Assert.assertEquals("http://www.example.com?testValue=value2&code=code" + "#access_token=access_111&state=ok&expires_in=400",url);
  Assert.assertEquals(200,oAuthResponse.getResponseStatus());
}
 

Example 20

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

Source file: OAuthASResponseTest.java

  15 
vote

@Test public void testAuthzResponseWithState() throws Exception {
  HttpServletRequest request=createMock(HttpServletRequest.class);
  expect(request.getParameter(OAuth.OAUTH_STATE)).andStubReturn("ok");
  replay(request);
  OAuthResponse oAuthResponse=OAuthASResponse.authorizationResponse(request,200).location("http://www.example.com").setCode("code").setAccessToken("access_111").setExpiresIn("400").setParam("testValue","value2").buildQueryMessage();
  String url=oAuthResponse.getLocationUri();
  Assert.assertEquals("http://www.example.com?testValue=value2&code=code" + "#access_token=access_111&state=ok&expires_in=400",url);
  Assert.assertEquals(200,oAuthResponse.getResponseStatus());
}
 

Example 21

From project android-rindirect, under directory /maven-rindirect-plugin-it/src/test/java/de/akquinet/android/rindirect/.

Source file: ClassnameTest.java

  15 
vote

@Test public void testClassname() throws VerificationException, FileNotFoundException, IOException {
  Verifier verifier=new Verifier(ROOT.getAbsolutePath());
  Properties props=Constants.getSystemProperties();
  props.put("rindirect.classname","MyS");
  verifier.setSystemProperties(props);
  verifier.executeGoal("package");
  verifier.verifyTextInLog("BUILD SUCCESS");
  Helper.checkExecution(verifier);
  verifier.resetStreams();
  File result=new File(ROOT + Constants.GENERATE_FOLDER + "/my/application/MyS.java");
  Assert.assertTrue(result.exists());
}
 

Example 22

From project android-rindirect, under directory /maven-rindirect-plugin-it/src/test/java/de/akquinet/android/rindirect/.

Source file: HelloTest.java

  15 
vote

@Test public void testHello() throws VerificationException, FileNotFoundException, IOException {
  Verifier verifier=new Verifier(ROOT.getAbsolutePath());
  verifier.setSystemProperties(Constants.getSystemProperties());
  verifier.executeGoal("package");
  verifier.verifyTextInLog("BUILD SUCCESS");
  Helper.checkExecution(verifier);
  verifier.resetStreams();
  File result=new File(ROOT + Constants.GENERATE_FOLDER + "/my/application/R.java");
  Assert.assertTrue(result.exists());
  String clazz=Helper.readInputStream(new FileInputStream(result));
  Helper.assertContains(clazz,"package my.application;");
  Helper.assertContains(clazz,"public final class R {");
  Helper.assertContains(clazz,"public static final class string {");
  Helper.assertNotContains(clazz,"public static final class attr {");
  Assert.assertEquals(5,Helper.getNumberOfOccurence(clazz,"R."));
  try {
    verifier.verifyTextInLog("INFO: Lauch R visit");
    Assert.fail("Unexpected test in log");
  }
 catch (  VerificationException e) {
  }
}