Example usage for java.lang Error toString

List of usage examples for java.lang Error toString

Introduction

In this page you can find the example usage for java.lang Error toString.

Prototype

public String toString() 

Source Link

Document

Returns a short description of this throwable.

Usage

From source file:com.nabla.project.fronter.selenium.tests.helper.SeleniumHelper.java

public static void testDragDrop(final String draggable, final String droppable, String expectedResult,
        final WebDriver driver, final StringBuffer verificationErrors) {

    final WebElement source = driver.findElement(By.id(draggable));
    final WebElement target = driver.findElement(By.id(droppable));

    final Actions builder = new Actions(driver);
    builder.dragAndDrop(source, target).perform();
    try {//w w w  .j  av  a  2 s  .  c  o m
        if (null == expectedResult) {
            expectedResult = "Dropped!";
        }
        Assert.assertEquals(expectedResult, target.getText());
    } catch (final Error e) {
        verificationErrors.append(e.toString());
    }
}

From source file:org.soaplab.services.GenUtils.java

/*************************************************************************
 * Find the resource with the given 'filename', read it and return
 * it. A resource is some data (images, audio, text, etc) that can
 * be accessed by class code in a way that is independent of the
 * location of the code, typically such resource file sits
 * anywhere on the CLASSPATH. <p>//from ww  w .  j  av  a2  s .c  om
 *
 * @param filename of a resource is a '/'-separated path name that
 * identifies the resource
 *
 * @param resourceOwner is a class whose class loader is used
 * to find and get the resource; typically one would put here
 * "this.getClass()" when calling this method
 *
 * @return contents of the resource
 *
 * @throws IOException if resource was found but an error occured
 * during its reading (IO problem, memory problem etc.)
 *
 * @throws FileNotFoundException if resource could not be found
 *************************************************************************/
public static String readResource(String filename, Class resourceOwner) throws IOException {

    // load it as a resource of the given class
    InputStream ins = resourceOwner.getClassLoader().getResourceAsStream(filename);

    if (ins == null) {
        // ...or extend the path by the package name of the given
        // class
        String className = resourceOwner.getName();
        int pkgEndIndex = className.lastIndexOf('.');
        if (pkgEndIndex > 0) {
            String packageName = className.substring(0, pkgEndIndex);

            // TBD: platform-dependent file separator?
            String newPath = packageName.replace('.', '/') + "/" + filename;
            ins = resourceOwner.getClassLoader().getResourceAsStream(newPath);
        }
    }
    if (ins == null)
        throw new FileNotFoundException(filename);

    try {
        return IOUtils.toString(ins);
    } catch (Error e) { // be prepare for "out-of-memory" error
        throw new IOException("Problem when reading resource '" + filename + "'. " + e.toString());
    } finally {
        try {
            if (ins != null)
                ins.close();
        } catch (IOException e) {
        }
    }
}

From source file:mujava.cli.genmutes.java

public static void generateMutants(String[] file_list, HashMap<String, List<String>> traditional_ops) {

    for (int i = 0; i < file_list.length; i++) {
        // file_name = ABSTRACT_PATH - MutationSystem.SRC_PATH
        // For example: org/apache/bcel/Class.java
        String file_name = file_list[i];
        try {//  w w  w .jav a2s. c  o m
            System.out.println((i + 1) + " : " + file_name);
            // [1] Examine if the target class is interface or abstract
            // class
            // In that case, we can't apply mutation testing.

            // Generate class name from file_name
            String temp = file_name.substring(0, file_name.length() - ".java".length());
            String class_name = "";

            for (int j = 0; j < temp.length(); j++) {
                if ((temp.charAt(j) == '\\') || (temp.charAt(j) == '/')) {
                    class_name = class_name + ".";
                } else {
                    class_name = class_name + temp.charAt(j);
                }
            }

            int class_type = MutationSystem.getClassType(class_name);

            if (class_type == MutationSystem.NORMAL) { // do nothing
            } else if (class_type == MutationSystem.MAIN) {
                System.out.println(" -- " + file_name + " class contains 'static void main()' method.");
                System.out.println(
                        "    Pleas note that mutants are not generated for the 'static void main()' method");
            } else {
                switch (class_type) {
                case MutationSystem.INTERFACE:
                    System.out.println(" -- Can't apply because " + file_name + " is 'interface' ");
                    break;
                case MutationSystem.ABSTRACT:
                    System.out.println(" -- Can't apply because " + file_name + " is 'abstract' class ");
                    break;
                case MutationSystem.APPLET:
                    System.out.println(" -- Can't apply because " + file_name + " is 'applet' class ");
                    break;
                case MutationSystem.GUI:
                    System.out.println(" -- Can't apply because " + file_name + " is 'GUI' class ");
                    break;
                case -1:
                    System.out.println(" -- Can't apply because class not found ");
                    break;
                }

                deleteDirectory();
                continue;
            }

            // [2] Apply mutation testing
            setMutationSystemPathFor(file_name);

            File original_file = new File(MutationSystem.SRC_PATH, file_name);

            String[] opArray = traditional_ops.keySet().toArray(new String[0]);

            TraditionalMutantsGeneratorCLI tmGenEngine;
            tmGenEngine = new TraditionalMutantsGeneratorCLI(original_file, opArray);
            tmGenEngine.makeMutants();
            tmGenEngine.compileMutants();

            // Lin add printing total mutants
            // get all file names
            File folder = new File(
                    MutationSystem.MUTANT_HOME + "/" + class_name + "/" + MutationSystem.TM_DIR_NAME);
            File[] listOfMethods = folder.listFiles();

            //ArrayList<String> fileNameList = new ArrayList<>();
            int total_mutants = 0;
            for (File method : listOfMethods) {
                //fileNameList.add(method.getName());
                if (method.isDirectory()) {
                    File[] listOfMutants = method.listFiles();
                    total_mutants = total_mutants + listOfMutants.length;

                }
            }

            //            File muTotalFile = new File(MutationSystem.MUTANT_PATH,"mutation_log");
            //            String strLine;
            //               LineNumberReader lReader = new LineNumberReader(new FileReader(muTotalFile));
            //               int line = 0;
            //               while ((strLine=lReader.readLine()) != null)
            //               {
            //                  line++;
            //               }

            System.out.println("------------------------------------------------------------------");
            System.out.println(
                    "Total mutants gnerated for " + file_name + ": " + Integer.toString(total_mutants));

        } catch (OpenJavaException oje) {
            System.out.println("[OJException] " + file_name + " " + oje.toString());
            // System.out.println("Can't generate mutants for " +file_name +
            // " because OpenJava " + oje.getMessage());
            deleteDirectory();
        } catch (Exception exp) {
            System.out.println("[Exception] " + file_name + " " + exp.toString());
            exp.printStackTrace();
            // System.out.println("Can't generate mutants for " +file_name +
            // " due to exception" + exp.getClass().getName());
            // exp.printStackTrace();
            deleteDirectory();
        } catch (Error er) {
            System.out.println("[Error] " + file_name + " " + er.toString());
            // System.out.println("Can't generate mutants for " +file_name +
            // " due to error" + er.getClass().getName());
            deleteDirectory();
        }
    }
    // runB.setEnabled(true);
    // parent_frame.cvPanel.refreshEnv();
    // parent_frame.tvPanel.refreshEnv();
    // System.out
    // .println("------------------------------------------------------------------");
    // System.out.println(" All files are handled"); // need to say how many
    // mutants are generated

}

From source file:com.bna.ezrxlookup.ui.web.EZRxInitialPage.java

@Test
public void testEZRxInitialPage() throws Exception {
    driver.get(baseUrl + "/EZRxLookup");
    try {/*from  w  w  w .  j  ava 2  s .  c o  m*/
        assertTrue(isElementPresent(By.id("j_idt5:j_idt18:drugName_input")));
    } catch (Error e) {
        verificationErrors.append(e.toString());

    }

}

From source file:com.jungle.mediaplayer.demo.RecordAudioActivity.java

private void initAudioRecorder() {
    mAudioRecorder = new SystemImplAudioRecorder(new RecorderListener() {
        @Override//from  www .j ava 2 s.c  o m
        public void onError(Error error) {
            showToast("Record Audio ERROR! " + error.toString());
            mPlayAudioBtn.setEnabled(false);
        }

        @Override
        public void onStartRecord() {
            mPlayAudioBtn.setEnabled(false);
            mRecordAudioBtn.setText(R.string.stop_record);
        }

        @Override
        public void onStopRecord() {
            mRecordAudioBtn.setText(R.string.record_audio);
            mPlayAudioBtn.setEnabled(true);
        }
    }, this);
}

From source file:com.peapod.matchflare.GCMIntentService.java

private void dumpEvent(String event, Intent message) {

    if (event.equals("onMessage")) {

        //Handled received remote notification
        Intent intent = new Intent("com.peapod.matchflare.push_notification");
        String jsonData = message.getStringExtra("data");
        Gson gson = new Gson();

        try {/*  w  w  w.  j a v  a  2 s  . co  m*/
            Notification notification = gson.fromJson(jsonData, Notification.class);
            if (notification != null) {

                intent.putExtra("notification", notification);
                String notificationTitle = "Matchflare Notification!";

                //Set notifcation title based on notification type
                if (notification.notification_type != null) {
                    if (notification.notification_type.equals("USER_REMINDER")) {
                        notificationTitle = "What do you think of them?";
                    } else if (notification.notification_type.equals("MATCHER_ONE_MATCH_ACCEPTED")) {
                        notificationTitle = "Match Accepted!";
                    } else if (notification.notification_type.equals("MATCHER_MESSAGING_STARTED")) {
                        notificationTitle = "They started talking!";
                    } else if (notification.notification_type.equals("MATCHER_QUESTION_ASKED")) {
                        notificationTitle = "New Question?";
                    } else if (notification.notification_type.equals("MATCHEE_NEW_MATCH")) {
                        notificationTitle = "New Match!";
                    } else if (notification.notification_type.equals("MATCHEE_MATCH_ACCEPTED")) {
                        notificationTitle = "Match made!";
                    } else if (notification.notification_type.equals("MATCHEE_QUESTION_ANSWERED")) {
                        notificationTitle = "Question Answered!";
                    } else if (notification.notification_type.equals("MATCHEE_MESSAGE_SENT")) {
                        notificationTitle = "New Message!";
                    }
                }

                //If no local activity received the notification, then set phone notification
                if (!LocalBroadcastManager.getInstance(this).sendBroadcast(intent)) {
                    NotificationCompat.Builder b = new NotificationCompat.Builder(this);
                    Intent ui = new Intent(this, SplashActivity.class);
                    ui.putExtra("notification", notification);
                    ui.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    long[] vibrate = { 0, 100 };
                    b.setAutoCancel(true).setContentTitle(notificationTitle)
                            .setContentText(notification.push_message).setSmallIcon(R.drawable.ic_launcher)
                            .setTicker(notification.push_message)
                            .setLights(Color.argb(255, 250, 69, 118), 2000, 500).setVibrate(vibrate)
                            .setContentIntent(
                                    PendingIntent.getActivity(this, 0, ui, PendingIntent.FLAG_UPDATE_CURRENT));

                    NotificationManager mgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
                    mgr.notify(NOTIFY_ID, b.build());
                }
            }

        } catch (Error e) {
            Log.e("Cant parse notification", e.toString());

            //Google Analytics
            Tracker t = ((Global) getApplication()).getTracker();
            t.send(new HitBuilders.ExceptionBuilder()
                    .setDescription("(GCMIntentService) Could not parse notification push message: "
                            + new StandardExceptionParser(this, null)
                                    .getDescription(Thread.currentThread().getName(), e))
                    .setFatal(false).build());
        }
    }
}

From source file:com.redhat.lightblue.util.ErrorTest.java

@Test
public void testToString() throws JSONException {
    // alias for toJson, so not going to test all cases
    Error e = Error.get("a", "b", "c");
    String s = e.toString();
    JSONAssert.assertEquals("{objectType:error,context:a,errorCode:b,msg:c}", s, false);
}

From source file:com.orange.ngsi2.model.ErrorTest.java

@Test
public void checkToString() {
    Error parseError = new Error("400", Optional.of("The incoming JSON payload cannot be parsed"),
            Optional.empty());//from  w w w.  j  av a  2 s. c  o m
    assertEquals("error: 400 | description: The incoming JSON payload cannot be parsed | affectedItems: []",
            parseError.toString());
    parseError.setAffectedItems(Optional.of(Collections.singleton("entities")));
    assertEquals(
            "error: 400 | description: The incoming JSON payload cannot be parsed | affectedItems: [entities]",
            parseError.toString());
}

From source file:com.hammurapi.jcapture.CaptureFrame.java

protected void capture() throws Exception {
    try {/*  www .j  a  v  a2  s. c  om*/
        Thread.sleep(200); // For Ubuntu.
    } catch (InterruptedException ie) {
        // Ignore
    }

    BufferedImage screenShot = captureConfig.createScreenShot(null, null).call().getRegions().get(0).getImage()
            .getImage();

    String prefix = getDatePrefix();

    String defaultImageFormat = applet.getParameter("imageFormat");
    if (defaultImageFormat == null || defaultImageFormat.trim().length() == 0) {
        defaultImageFormat = "PNG";
    }
    final String defaultFileExtension = defaultImageFormat.toLowerCase();

    final String fileName = JOptionPane.showInputDialog(CaptureFrame.this, "Upload as",
            applet.getParameter("pageName") + "-capture-" + prefix + "-" + nextCounter() + "."
                    + defaultFileExtension);
    if (fileName != null) {
        try {
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            int idx = fileName.lastIndexOf('.');
            String imageFormat = idx == -1 ? defaultImageFormat : fileName.substring(idx + 1).toUpperCase();
            ImageIO.write(screenShot, imageFormat, baos);
            final byte[] imageBytes = baos.toByteArray();
            System.out.println("Image size: " + imageBytes.length);
            // Uploading
            SwingWorker<Boolean, Long> task = new SwingWorker<Boolean, Long>() {

                @Override
                protected Boolean doInBackground() throws Exception {

                    System.out.println("Uploading in background");
                    try {
                        HttpResponse iResponse = applet.post(CaptureFrame.this,
                                new ByteArrayInputStream(imageBytes), imageBytes.length, fileName,
                                "application/octet-stream");

                        System.out.println("Response status line: " + iResponse.getStatusLine());
                        if (iResponse.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
                            errorMessage = iResponse.getStatusLine();
                            errorTitle = "Error saving image";
                            return false;
                        }
                        return true;
                    } catch (Error e) {
                        errorMessage = e.toString();
                        errorTitle = "Upload error";
                        e.printStackTrace();
                        return false;
                    }
                }

                private Object errorMessage;
                private String errorTitle;

                protected void done() {
                    try {
                        if (get()) {
                            JSObject window = JSObject.getWindow(applet);
                            String toEval = "insertAtCarret('" + applet.getParameter("edid") + "','{{:"
                                    + fileName + "|}}')";
                            System.out.println("Evaluating: " + toEval);
                            window.eval(toEval);
                            CaptureFrame.this.setVisible(false);
                        } else {
                            JOptionPane.showMessageDialog(CaptureFrame.this, errorMessage, errorTitle,
                                    JOptionPane.ERROR_MESSAGE);
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                        JOptionPane.showMessageDialog(CaptureFrame.this, e.toString(), "Exception",
                                JOptionPane.ERROR_MESSAGE);
                    }
                };

            };

            task.execute();
        } catch (IOException ex) {
            JOptionPane.showMessageDialog(applet, ex.toString(), "Error saving image",
                    JOptionPane.ERROR_MESSAGE);
        }
    }
}

From source file:google.geofence.GooglegeofenceModule.java

@Kroll.method
public void startMonitoringForRegions(String regions) throws JSONException {

    /**/*from   w  w  w. j a v a 2s.c  o  m*/
     * Used to persist application state about whether geofences were added.
     */

    // Retrieve an instance of the SharedPreferences object.
    mSharedPreferences = appContext.getSharedPreferences(Constants.SHARED_PREFERENCES_NAME,
            Context.MODE_PRIVATE);

    // Get the value of mGeofencesAdded from SharedPreferences. Set to false
    // as a default.
    mGeofencesAdded = mSharedPreferences.getBoolean(Constants.GEOFENCES_ADDED_KEY, false);
    if (monitoringFences != null) {
        oldFences = monitoringFences;
    }
    monitoringFences = regions;
    EventHandler handler = new EventHandler();
    EventBus.getDefault().register(handler);
    JSONArray jsonarray = new JSONArray(regions);

    mGeofenceList = new ArrayList<Geofence>();
    for (int i = 0; i < jsonarray.length(); i++) {

        JSONObject region = jsonarray.getJSONObject(i);

        JSONObject center = region.getJSONObject("center");

        Double lat = center.getDouble("latitude");

        Double lng = center.getDouble("longitude");

        int radius = region.getInt("radius");

        String identifier = region.getString("identifier");

        System.out.println(lat);

        System.out.println(lng);

        System.out.println(radius);

        System.out.println(identifier);

        createGeofences(lng, lat, radius, identifier);

    }

    if (mGoogleApiClient == null) {
        buildGoogleApiClient();
    }

    try {
        if (mGoogleApiClient.isConnected()) {
            System.out.println("You are connected to google api client...");

            sendGeoFences();

        } else if (mGoogleApiClient.isConnecting()) {
            System.out.println("Still connecting...");
        } else {
            System.out.println("not connected...");

            try {
                mGoogleApiClient.connect();
            } catch (Error err) {
                System.out.println("error is: " + err.toString());
            }

        }

    } catch (SecurityException securityException) {
        // Catch exception generated if the app does not use
        // ACCESS_FINE_LOCATION permission.
        // logSecurityException(securityException);
        System.out.println("security error...");
    }

}