Java Code Examples for junit.framework.TestCase#fail()
The following examples show how to use
junit.framework.TestCase#fail() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Utils.java From netbeans with Apache License 2.0 | 6 votes |
public static void phaseOnePOne( TestData data, String installerType ) { try { String wd = System.getenv("WORKSPACE"); TestCase.assertNotNull(wd); data.setWorkDir(new File(wd)); data.CreateInstallPaths( ); } catch (IOException ex) { TestCase.fail("Can not get WorkDir"); } data.setInstallerType(installerType); System.setProperty("nbi.dont.use.system.exit", "true"); System.setProperty("nbi.utils.log.to.console", "false"); System.setProperty("servicetag.allow.register", "false"); System.setProperty("show.uninstallation.survey", "false"); System.setProperty("user.home", data.getWorkDirCanonicalPath()); if (Boolean.valueOf(System.getProperty("test.use.build.number"))) { TestCase.assertNotNull("Determine build number", Utils.determineBuildNumber(data)); } //data.setBuildNumber(null); }
Example 2
Source File: TestQueueMuxBatchmgr.java From oodt with Apache License 2.0 | 6 votes |
public void testExecuteRemotely() { try { //Test that the jobs are put in seperate mock-backends based on queues ResourceNode node1 = new ResourceNode(); ResourceNode node2 = new ResourceNode(); JobSpec spec1 = this.getSpecFromQueue("queue-1"); queue.executeRemotely(spec1, node1); JobSpec spec2 = this.getSpecFromQueue("queue-2"); queue.executeRemotely(spec2, node2); //Yes...use reference equality, as these must be the exact same object TestCase.assertEquals(spec1,mock1.getCurrentJobSpec()); TestCase.assertEquals(spec2,mock2.getCurrentJobSpec()); TestCase.assertEquals(node1,mock1.getCurrentResourceNode()); TestCase.assertEquals(node2,mock2.getCurrentResourceNode()); //Throws exception on bad queue try { queue.executeRemotely(this.getSpecFromQueue("queue-3"),node1); TestCase.fail("Failed to throw JobExecutionException on unknown queue."); } catch(JobExecutionException ignored) {} } catch (JobExecutionException e) { TestCase.fail("Unexpected Exception: "+e.getMessage()); } }
Example 3
Source File: AnalyticsSpec.java From android-perftracking with MIT License | 6 votes |
@Test public void shouldCatchExceptions() { Analytics exceptionAnalytics = new Analytics() { @SuppressWarnings("unchecked") @Override public void sendEvent(String name, Map<String, ?> data) { throw new RuntimeException("Error message"); } }; try { exceptionAnalytics.sendUrlMeasurement(measurement, null, 0); } catch (Exception e) { TestCase.fail(); } }
Example 4
Source File: BatchSyntaxTest.java From Concurnas with MIT License | 6 votes |
@Test public void batchTest() throws Exception { List<File> ftt = filesToTest("./tests"); boolean allpass = true; int n=0; for(File tt : ftt){ String sname = tt.getName(); if(skip.contains(sname)){ System.out.println("skip: " + sname); }else{ if(!testFile(tt, n, ftt.size())){ allpass = false; } } n++; } if(!allpass){ TestCase.fail("Not all tests passed"); } }
Example 5
Source File: NBTTestCase.java From NBT with MIT License | 5 votes |
protected void assertThrowsRuntimeException(Runnable r, boolean printStackTrace) { try { r.run(); TestCase.fail(); } catch (Exception ex) { if (printStackTrace) { ex.printStackTrace(); } } }
Example 6
Source File: IntegerValueConverterTest.java From mobi with GNU Affero General Public License v3.0 | 5 votes |
@Test public void testEmpty() { try { valueConverter.convertValue(valueFactory.createLiteral(""), null, type); TestCase.fail("Empty string should cause ValueConversionException"); } catch (ValueConversionException e) { TestCase.assertTrue("Cause of error should have been NumberFormatException", e.getCause() instanceof NumberFormatException); } }
Example 7
Source File: ShortValueConverterTest.java From mobi with GNU Affero General Public License v3.0 | 5 votes |
@Test public void testEmpty() { try { valueConverter.convertValue(valueFactory.createLiteral(""), null, type); TestCase.fail("Empty string should cause ValueConversionException"); } catch (ValueConversionException e) { TestCase.assertTrue("Cause of error should have been NumberFormatException", e.getCause() instanceof NumberFormatException); } }
Example 8
Source File: ASecureSharedPreferencesTest.java From armadillo with Apache License 2.0 | 5 votes |
@Test public void testSameKeyDifferentTypeShouldOverwrite() { //this is a similar behavior to normal shared preferences SharedPreferences pref = create("testSameKeyDifferentTypeShouldOverwrite", null).build(); pref.edit().putInt("id", 1).commit(); pref.edit().putString("id", "testNotInt").commit(); TestCase.assertEquals("testNotInt", pref.getString("id", null)); try { pref.getInt("id", -1); TestCase.fail("string should be overwritten with int"); } catch (Exception ignored) { } }
Example 9
Source File: EventOrderFunction.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 5 votes |
/** * Receives notification that a group of item bands has been completed. * <p/> * The itemBand is finished, the report starts to close open groups. * * @param event * The event. */ public void itemsFinished( final ReportEvent event ) { if ( ( event.getType() & ReportEvent.ITEMS_FINISHED ) != ReportEvent.ITEMS_FINISHED ) { TestCase.fail( "ReportEvent was expected to be of type ITEMS_FINISHED" ); } if ( ( lastEventType & ReportEvent.ITEMS_ADVANCED ) != ReportEvent.ITEMS_ADVANCED ) { TestCase.fail( "Unexpected Event: ItemsFinished: " + lastEventType ); } lastEventType = ReportEvent.ITEMS_FINISHED; }
Example 10
Source File: TestQueueMuxMonitor.java From oodt with Apache License 2.0 | 5 votes |
public void testAddNode() { try { ResourceNode node = new ResourceNode("a-new-node",null,2); qm.addNodeToQueue(node.getNodeId(), "queue-1"); monitor.addNode(node); TestCase.assertEquals(node,mock1.getAdded()); } catch(MonitorException e) { TestCase.fail("Unanticipated monitor exception caught: "+e.getMessage()); } catch (QueueManagerException e1) { TestCase.fail("Unanticipated queue manager exception caught: "+e1.getMessage()); } }
Example 11
Source File: NBTTestCase.java From NBT with MIT License | 5 votes |
protected <T, E extends Exception> T assertThrowsNoException(ExceptionSupplier<T, E> r, boolean printStackTrace) { try { return r.run(); } catch (Exception ex) { if (printStackTrace) { ex.printStackTrace(); } TestCase.fail("Threw exception " + ex.getClass().getName() + " with message \"" + ex.getMessage() + "\""); } return null; }
Example 12
Source File: EventWriterSpec.java From android-perftracking with MIT License | 5 votes |
@Test public void shouldNotFailOnWriteWithoutBegin() { try { Measurement measurement = new Measurement(); measurement.type = Measurement.CUSTOM; measurement.a = ""; measurement.startTime = 0L; measurement.endTime = 999; writer.write(measurement, ""); } catch(Exception e) { TestCase.fail(); } }
Example 13
Source File: AbstractTestStage.java From stream-registry with Apache License 2.0 | 5 votes |
public void assertRequiresObjectIsAbsent(Mutation m) { try { client.invoke(m); TestCase.fail("Expected a ValidationException"); } catch (RuntimeException e) { assertTrue(e.getMessage().contains("Can't create because it already exists")); } }
Example 14
Source File: SecurePayServiceTest.java From scipio-erp with Apache License 2.0 | 5 votes |
public void testdoRefund() throws Exception { Debug.logInfo("=====[testdoRefund] starting....", module); try { Map<String, Object> serviceInput = UtilMisc.toMap( "paymentConfig", configFile, "orderPaymentPreference", orderPaymentPreference ); serviceInput.put("refundAmount", refundAmount); // run the service Map<String, Object> result = dispatcher.runSync("ofbScRefund", serviceInput); // verify the results String responseMessage = (String) result.get(ModelService.RESPONSE_MESSAGE); Debug.logInfo("[testdoRefund] responseMessage: " + responseMessage, module); TestCase.assertEquals("Service result is success", ModelService.RESPOND_SUCCESS, responseMessage); if (((Boolean) result.get("refundResult")).equals(Boolean.FALSE)) { // returnCode ok? Debug.logInfo("[testdoRefund] Error Messages from SecurePay: " + result.get("internalRespMsgs"), module); TestCase.fail("Returned messages:" + result.get("internalRespMsgs")); } else { Debug.logInfo("[testdoRefund] Result from SecurePay: " + result, module); } } catch (GenericServiceException ex) { TestCase.fail(ex.getMessage()); } }
Example 15
Source File: MetricSpec.java From android-perftracking with MIT License | 5 votes |
@Test public void shouldNotFailOnNullTrackingManager() { TrackingManager.INSTANCE = null; try { Metric.start("id1"); } catch(NullPointerException e) { TestCase.fail("Should not throw an Exception when TrackingManager is null."); } }
Example 16
Source File: Typing.java From netbeans with Apache License 2.0 | 5 votes |
public void assertDocumentTextEquals(final String textWithPipe) { int caretOffset = textWithPipe.indexOf('|'); String text; if (caretOffset != -1) { text = textWithPipe.substring(0, caretOffset) + textWithPipe.substring(caretOffset + 1); } else { text = textWithPipe; } try { // Use debug text to prefix special chars for easier readability text = CharSequenceUtilities.debugText(text); String docText = document().getText(0, document().getLength()); docText = CharSequenceUtilities.debugText(docText); if (!text.equals(docText)) { int diffIndex = 0; int minLen = Math.min(docText.length(), text.length()); while (diffIndex < minLen) { if (text.charAt(diffIndex) != docText.charAt(diffIndex)) { break; } diffIndex++; } TestCase.fail("Invalid document text - diff at index " + diffIndex + "\nExpected: \"" + text + "\"\n Actual: \"" + docText + "\""); } } catch (BadLocationException e) { throw new IllegalStateException(e); } if (caretOffset != -1) { TestCase.assertEquals("Invalid caret offset", caretOffset, pane.getCaretPosition()); } }
Example 17
Source File: TileUtils.java From geopackage-java with MIT License | 5 votes |
/** * Validate the row type * * @param rowColumnType * row column type * @param expectedColumnType * expected column type */ private static void validateRowColumnType(int rowColumnType, int expectedColumnType) { if (rowColumnType == ResultUtils.FIELD_TYPE_NULL) { TestCase.fail("Tile columns should all non nullable. Expected Column Type: " + expectedColumnType); } else { TestCase.assertEquals(expectedColumnType, rowColumnType); } }
Example 18
Source File: TextTest.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 5 votes |
public void testGraphemeClusterGenerationOldMac() { CodePointBuffer buffer = Utf16LE.getInstance().decodeString( "T\r\r\rT", null ); //$NON-NLS-1$ final int[] data = buffer.getBuffer(); final boolean[] result = new boolean[] { true, true, true, true, true }; GraphemeClusterProducer prod = new GraphemeClusterProducer(); for ( int i = 0; i < buffer.getLength(); i++ ) { final int codepoint = data[i]; if ( prod.createGraphemeCluster( codepoint ) != result[i] ) { TestCase.fail(); } } }
Example 19
Source File: TransactionTest.java From geopackage-android with MIT License | 4 votes |
/** * Test an ORMLite transaction * * @param geoPackage GeoPackage * @param successful true for a successful transaction * @throws SQLException upon error */ private void testORMLite(final GeoPackage geoPackage, final boolean successful) throws SQLException { final String tableName = "test_table"; final Contents contents = new Contents(); contents.setTableName(tableName); contents.setDataType(ContentsDataType.ATTRIBUTES); if (!geoPackage.isTable(tableName)) { geoPackage.execSQL("CREATE TABLE " + tableName + " (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL)"); } final SpatialReferenceSystemDao srsDao = geoPackage .getSpatialReferenceSystemDao(); final ContentsDao contentsDao = geoPackage.getContentsDao(); long srsCount = srsDao.countOf(); long contentsCount = contentsDao.countOf(); Callable<Void> callable = new Callable<Void>() { public Void call() throws Exception { SpatialReferenceSystem srs = srsDao.createWgs84Geographical3D(); contents.setSrs(srs); contentsDao.create(contents); if (!successful) { throw new SQLException(); } return null; } }; try { geoPackage.callInTransaction(callable); } catch (SQLException e) { if (successful) { TestCase.fail(e.getMessage()); } } TestCase.assertEquals(successful ? srsCount + 1 : srsCount, srsDao.countOf()); TestCase.assertEquals(successful ? contentsCount + 1 : contentsCount, contentsDao.countOf()); TestCase.assertEquals(successful, geoPackage.isAttributeTable(tableName)); }
Example 20
Source File: ViewUpdatesTesting.java From netbeans with Apache License 2.0 | 4 votes |
/** * Ensure a part of view hierarchy has local views of certain length and class * * @param startOffset * @param endOffset * @param viewLengthsAndTypes pairs of integer length of local view and its class. */ public static void checkViews(DocumentView docView, int startOffset, int endOffset, Object... viewLengthsAndTypes) { int argCount = viewLengthsAndTypes.length; if ((argCount & 1) != 0) { throw new IllegalArgumentException("viewLengthsAndTypes.length=" + argCount + " % 2 != 0"); } int origStartOffset = startOffset; if (startOffset == -1) { startOffset = docView.getStartOffset(); } int origEndOffset = endOffset; if (endOffset == -1) { endOffset = docView.getEndOffset(); } int argIndex = 0; int pIndex = docView.getViewIndex(startOffset); String errorMsg = null; StringBuilder sbCall = new StringBuilder(2048); if (pIndex != -1) { ParagraphView pView = docView.getParagraphView(pIndex); int index = !pView.isChildrenNull() ? pView.getViewIndex(startOffset) : 0; int viewCount = pView.getViewCount(); for (int offset = startOffset; offset < endOffset;) { EditorView view = !pView.isChildrenNull() ? pView.getEditorView(index) : pView; if (errorMsg == null) { if (argIndex >= argCount) { errorMsg = "Unexpected view found: " + view; } else if (offset != view.getStartOffset()) { errorMsg = "offset=" + offset + " != viewStartOffset=" + view.getStartOffset(); } else if (view.getLength() != (Integer) viewLengthsAndTypes[argIndex]) { errorMsg = "view.getLength()=" + view.getLength() + " != arg=" + viewLengthsAndTypes[argIndex]; } else if (view.getClass() != (Class) viewLengthsAndTypes[argIndex + 1]) { errorMsg = "view.getClass()=" + view.getClass() + " != arg=" + viewLengthsAndTypes[argIndex + 1]; } } offset += view.getLength(); index++; if (index >= viewCount) { pIndex++; if (pIndex < docView.getViewCount()) { pView = docView.getParagraphView(pIndex); viewCount = pView.getViewCount(); } index = 0; } argIndex += 2; String viewType; if (view instanceof HighlightsView) { viewType = "HI_VIEW"; } else if (view instanceof TabView) { viewType = "TAB_VIEW"; } else if (view instanceof NewlineView) { viewType = "NL_VIEW /* e:" + offset + " */"; } else if (view instanceof ParagraphView) { viewType = "P_VIEW /* e:" + offset + " */"; } else { viewType = "CUSTOM_VIEW"; } sbCall.append(" ").append(view.getLength()).append(", ").append(viewType).append(",\n"); } if (argIndex < argCount && errorMsg == null) { errorMsg = "checkViews() called with " + argCount + " arguments but only " + argIndex + " used."; } } else { // No pViews if (argCount == 0) { // No pViews => Ok return; } errorMsg = "No pViews but viewLengthsAndTypes.length=" + argCount + " > 0"; } if (errorMsg != null) { if (sbCall.length() >= 2) { sbCall.setLength(sbCall.length() - 2); // Remove ending ",\n" and just append '\n' sbCall.append('\n'); } TestCase.fail(errorMsg + "\n" + // " private static final Class HI_VIEW = HighlightsView.class;\n" + // " private static final Class TAB_VIEW = TabView.class;\n" + // " private static final Class NL_VIEW = NewlineView.class;\n" + // " private static final Class P_VIEW = ParagraphView.class;\n" + " ViewUpdatesTesting.checkViews(docView, " + origStartOffset + ", " + origEndOffset + ",\n" + sbCall.toString() + " );"); } }