Example usage for org.json JSONException toString

List of usage examples for org.json JSONException toString

Introduction

In this page you can find the example usage for org.json JSONException toString.

Prototype

public String toString() 

Source Link

Document

Returns a short description of this throwable.

Usage

From source file:com.google.testing.testify.risk.frontend.server.api.impl.UploadApiImpl.java

@Override
public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
    BufferedReader reader = req.getReader();
    StringBuilder input = new StringBuilder();
    while (reader.ready()) {
        input.append(req.getReader().readLine());
    }//from w w w.j a va2 s .com
    LOG.info("Input received: " + input.toString());
    JSONArray json;
    try {
        json = new JSONArray(input.toString());
    } catch (JSONException e) {
        LOG.warning("Couldn't parse JSON: " + e.toString());
        error(resp, "Malformed JSON could not be parsed: " + e.toString());
        return;
    }
    LOG.info("JSON received: " + json.toString());
    JSONObject o;
    TaskOptions task;
    String email = userService.getEmail();
    for (int i = 0; i < json.length(); i++) {
        try {
            o = json.getJSONObject(i);
            task = TaskOptions.Builder.withUrl(UploadDataTask.URL).method(Method.POST)
                    .param("json", o.toString()).param("user", email);
            ServletUtils.queueWithRetries(UploadDataTask.QUEUE, task, "Processing data item upload");
        } catch (JSONException e) {
            LOG.warning("Couldn't parse item " + i + " in JSON array: " + e.toString());
            resp.getOutputStream().print("<p>Couldn't parse item " + i + "</p>\n");
        }
    }
}

From source file:com.reecedunn.espeak.test.VoiceSettingsTest.java

public void testNoPreferences() {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
    SharedPreferences.Editor editor = prefs.edit();
    editor.clear();// w w w  .  ja  v a2 s. c o  m
    editor.commit();

    SpeechSynthesis synth = new SpeechSynthesis(getContext(), mCallback);
    VoiceSettings settings = new VoiceSettings(prefs, synth);
    assertThat(settings.getVoiceVariant().toString(), is("male"));
    assertThat(settings.getRate(), is(synth.Rate.getDefaultValue()));
    assertThat(settings.getPitch(), is(synth.Pitch.getDefaultValue()));
    assertThat(settings.getPitchRange(), is(synth.PitchRange.getDefaultValue()));
    assertThat(settings.getVolume(), is(synth.Volume.getDefaultValue()));
    assertThat(settings.getPunctuationLevel(), is(SpeechSynthesis.PUNCT_NONE));
    assertThat(settings.getPunctuationCharacters(), is(nullValue()));

    try {
        JSONObject json = settings.toJSON();
        assertThat(json.opt(VoiceSettings.PRESET_VARIANT), is(instanceOf(String.class)));
        assertThat((String) json.opt(VoiceSettings.PRESET_VARIANT), is("male"));
        assertThat(json.opt(VoiceSettings.PRESET_RATE), is(instanceOf(Integer.class)));
        assertThat((Integer) json.opt(VoiceSettings.PRESET_RATE), is(synth.Rate.getDefaultValue()));
        assertThat(json.opt(VoiceSettings.PRESET_PITCH), is(instanceOf(Integer.class)));
        assertThat((Integer) json.opt(VoiceSettings.PRESET_PITCH), is(synth.Pitch.getDefaultValue()));
        assertThat(json.opt(VoiceSettings.PRESET_PITCH_RANGE), is(instanceOf(Integer.class)));
        assertThat((Integer) json.opt(VoiceSettings.PRESET_PITCH_RANGE),
                is(synth.PitchRange.getDefaultValue()));
        assertThat(json.opt(VoiceSettings.PRESET_VOLUME), is(instanceOf(Integer.class)));
        assertThat((Integer) json.opt(VoiceSettings.PRESET_VOLUME), is(synth.Volume.getDefaultValue()));
        assertThat(json.opt(VoiceSettings.PRESET_PUNCTUATION_LEVEL), is(instanceOf(String.class)));
        assertThat((String) json.opt(VoiceSettings.PRESET_PUNCTUATION_LEVEL), is("none"));
        assertThat(json.opt(VoiceSettings.PRESET_PUNCTUATION_CHARACTERS), is(nullValue()));
    } catch (JSONException e) {
        assertThat(e.toString(), is(nullValue())); // This will be false; used to report exception.
    }
}

From source file:com.reecedunn.espeak.test.VoiceSettingsTest.java

public void testDefaultGenderMale() {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
    SharedPreferences.Editor editor = prefs.edit();
    editor.clear();//from   w  w  w . j  a v  a2  s  . c o m
    editor.putString("default_gender", Integer.toString(SpeechSynthesis.GENDER_MALE));
    editor.commit();

    SpeechSynthesis synth = new SpeechSynthesis(getContext(), mCallback);
    VoiceSettings settings = new VoiceSettings(prefs, synth);
    assertThat(settings.getVoiceVariant().toString(), is("male"));
    assertThat(settings.getRate(), is(synth.Rate.getDefaultValue()));
    assertThat(settings.getPitch(), is(synth.Pitch.getDefaultValue()));
    assertThat(settings.getPitchRange(), is(synth.PitchRange.getDefaultValue()));
    assertThat(settings.getVolume(), is(synth.Volume.getDefaultValue()));
    assertThat(settings.getPunctuationLevel(), is(SpeechSynthesis.PUNCT_NONE));
    assertThat(settings.getPunctuationCharacters(), is(nullValue()));

    try {
        JSONObject json = settings.toJSON();
        assertThat(json.opt(VoiceSettings.PRESET_VARIANT), is(instanceOf(String.class)));
        assertThat((String) json.opt(VoiceSettings.PRESET_VARIANT), is("male"));
        assertThat(json.opt(VoiceSettings.PRESET_RATE), is(instanceOf(Integer.class)));
        assertThat((Integer) json.opt(VoiceSettings.PRESET_RATE), is(synth.Rate.getDefaultValue()));
        assertThat(json.opt(VoiceSettings.PRESET_PITCH), is(instanceOf(Integer.class)));
        assertThat((Integer) json.opt(VoiceSettings.PRESET_PITCH), is(synth.Pitch.getDefaultValue()));
        assertThat(json.opt(VoiceSettings.PRESET_PITCH_RANGE), is(instanceOf(Integer.class)));
        assertThat((Integer) json.opt(VoiceSettings.PRESET_PITCH_RANGE),
                is(synth.PitchRange.getDefaultValue()));
        assertThat(json.opt(VoiceSettings.PRESET_VOLUME), is(instanceOf(Integer.class)));
        assertThat((Integer) json.opt(VoiceSettings.PRESET_VOLUME), is(synth.Volume.getDefaultValue()));
        assertThat(json.opt(VoiceSettings.PRESET_PUNCTUATION_LEVEL), is(instanceOf(String.class)));
        assertThat((String) json.opt(VoiceSettings.PRESET_PUNCTUATION_LEVEL), is("none"));
        assertThat(json.opt(VoiceSettings.PRESET_PUNCTUATION_CHARACTERS), is(nullValue()));
    } catch (JSONException e) {
        assertThat(e.toString(), is(nullValue())); // This will be false; used to report exception.
    }
}

From source file:com.reecedunn.espeak.test.VoiceSettingsTest.java

public void testDefaultGenderFemale() {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
    SharedPreferences.Editor editor = prefs.edit();
    editor.clear();//from w  ww  .  java  2 s.c  o  m
    editor.putString("default_gender", Integer.toString(SpeechSynthesis.GENDER_FEMALE));
    editor.commit();

    SpeechSynthesis synth = new SpeechSynthesis(getContext(), mCallback);
    VoiceSettings settings = new VoiceSettings(prefs, synth);
    assertThat(settings.getVoiceVariant().toString(), is("female"));
    assertThat(settings.getRate(), is(synth.Rate.getDefaultValue()));
    assertThat(settings.getPitch(), is(synth.Pitch.getDefaultValue()));
    assertThat(settings.getPitchRange(), is(synth.PitchRange.getDefaultValue()));
    assertThat(settings.getVolume(), is(synth.Volume.getDefaultValue()));
    assertThat(settings.getPunctuationLevel(), is(SpeechSynthesis.PUNCT_NONE));
    assertThat(settings.getPunctuationCharacters(), is(nullValue()));

    try {
        JSONObject json = settings.toJSON();
        assertThat(json.opt(VoiceSettings.PRESET_VARIANT), is(instanceOf(String.class)));
        assertThat((String) json.opt(VoiceSettings.PRESET_VARIANT), is("female"));
        assertThat(json.opt(VoiceSettings.PRESET_RATE), is(instanceOf(Integer.class)));
        assertThat((Integer) json.opt(VoiceSettings.PRESET_RATE), is(synth.Rate.getDefaultValue()));
        assertThat(json.opt(VoiceSettings.PRESET_PITCH), is(instanceOf(Integer.class)));
        assertThat((Integer) json.opt(VoiceSettings.PRESET_PITCH), is(synth.Pitch.getDefaultValue()));
        assertThat(json.opt(VoiceSettings.PRESET_PITCH_RANGE), is(instanceOf(Integer.class)));
        assertThat((Integer) json.opt(VoiceSettings.PRESET_PITCH_RANGE),
                is(synth.PitchRange.getDefaultValue()));
        assertThat(json.opt(VoiceSettings.PRESET_VOLUME), is(instanceOf(Integer.class)));
        assertThat((Integer) json.opt(VoiceSettings.PRESET_VOLUME), is(synth.Volume.getDefaultValue()));
        assertThat(json.opt(VoiceSettings.PRESET_PUNCTUATION_LEVEL), is(instanceOf(String.class)));
        assertThat((String) json.opt(VoiceSettings.PRESET_PUNCTUATION_LEVEL), is("none"));
        assertThat(json.opt(VoiceSettings.PRESET_PUNCTUATION_CHARACTERS), is(nullValue()));
    } catch (JSONException e) {
        assertThat(e.toString(), is(nullValue())); // This will be false; used to report exception.
    }
}

From source file:com.reecedunn.espeak.test.VoiceSettingsTest.java

public void defaultRateTest(int prefValue, int settingValue, SpeechSynthesis synth) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
    SharedPreferences.Editor editor = prefs.edit();
    editor.clear();/*from   www . j ava  2  s  . co m*/
    editor.putString("default_rate", Integer.toString(prefValue));
    editor.commit();

    VoiceSettings settings = new VoiceSettings(prefs, synth);
    assertThat(settings.getVoiceVariant().toString(), is("male"));
    assertThat(settings.getRate(), is(settingValue));
    assertThat(settings.getPitch(), is(synth.Pitch.getDefaultValue()));
    assertThat(settings.getPitchRange(), is(synth.PitchRange.getDefaultValue()));
    assertThat(settings.getVolume(), is(synth.Volume.getDefaultValue()));
    assertThat(settings.getPunctuationLevel(), is(SpeechSynthesis.PUNCT_NONE));
    assertThat(settings.getPunctuationCharacters(), is(nullValue()));

    try {
        JSONObject json = settings.toJSON();
        assertThat(json.opt(VoiceSettings.PRESET_VARIANT), is(instanceOf(String.class)));
        assertThat((String) json.opt(VoiceSettings.PRESET_VARIANT), is("male"));
        assertThat(json.opt(VoiceSettings.PRESET_RATE), is(instanceOf(Integer.class)));
        assertThat((Integer) json.opt(VoiceSettings.PRESET_RATE), is(settingValue));
        assertThat(json.opt(VoiceSettings.PRESET_PITCH), is(instanceOf(Integer.class)));
        assertThat((Integer) json.opt(VoiceSettings.PRESET_PITCH), is(synth.Pitch.getDefaultValue()));
        assertThat(json.opt(VoiceSettings.PRESET_PITCH_RANGE), is(instanceOf(Integer.class)));
        assertThat((Integer) json.opt(VoiceSettings.PRESET_PITCH_RANGE),
                is(synth.PitchRange.getDefaultValue()));
        assertThat(json.opt(VoiceSettings.PRESET_VOLUME), is(instanceOf(Integer.class)));
        assertThat((Integer) json.opt(VoiceSettings.PRESET_VOLUME), is(synth.Volume.getDefaultValue()));
        assertThat(json.opt(VoiceSettings.PRESET_PUNCTUATION_LEVEL), is(instanceOf(String.class)));
        assertThat((String) json.opt(VoiceSettings.PRESET_PUNCTUATION_LEVEL), is("none"));
        assertThat(json.opt(VoiceSettings.PRESET_PUNCTUATION_CHARACTERS), is(nullValue()));
    } catch (JSONException e) {
        assertThat(e.toString(), is(nullValue())); // This will be false; used to report exception.
    }
}

From source file:com.reecedunn.espeak.test.VoiceSettingsTest.java

public void defaultPitchTest(int prefValue, int settingValue, SpeechSynthesis synth) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
    SharedPreferences.Editor editor = prefs.edit();
    editor.clear();//from  ww w. j  av a  2s.c o m
    editor.putString("default_pitch", Integer.toString(prefValue));
    editor.commit();

    VoiceSettings settings = new VoiceSettings(prefs, synth);
    assertThat(settings.getVoiceVariant().toString(), is("male"));
    assertThat(settings.getRate(), is(synth.Rate.getDefaultValue()));
    assertThat(settings.getPitch(), is(settingValue));
    assertThat(settings.getPitchRange(), is(synth.PitchRange.getDefaultValue()));
    assertThat(settings.getVolume(), is(synth.Volume.getDefaultValue()));
    assertThat(settings.getPunctuationLevel(), is(SpeechSynthesis.PUNCT_NONE));
    assertThat(settings.getPunctuationCharacters(), is(nullValue()));

    try {
        JSONObject json = settings.toJSON();
        assertThat(json.opt(VoiceSettings.PRESET_VARIANT), is(instanceOf(String.class)));
        assertThat((String) json.opt(VoiceSettings.PRESET_VARIANT), is("male"));
        assertThat(json.opt(VoiceSettings.PRESET_RATE), is(instanceOf(Integer.class)));
        assertThat((Integer) json.opt(VoiceSettings.PRESET_RATE), is(synth.Rate.getDefaultValue()));
        assertThat(json.opt(VoiceSettings.PRESET_PITCH), is(instanceOf(Integer.class)));
        assertThat((Integer) json.opt(VoiceSettings.PRESET_PITCH), is(settingValue));
        assertThat(json.opt(VoiceSettings.PRESET_PITCH_RANGE), is(instanceOf(Integer.class)));
        assertThat((Integer) json.opt(VoiceSettings.PRESET_PITCH_RANGE),
                is(synth.PitchRange.getDefaultValue()));
        assertThat(json.opt(VoiceSettings.PRESET_VOLUME), is(instanceOf(Integer.class)));
        assertThat((Integer) json.opt(VoiceSettings.PRESET_VOLUME), is(synth.Volume.getDefaultValue()));
        assertThat(json.opt(VoiceSettings.PRESET_PUNCTUATION_LEVEL), is(instanceOf(String.class)));
        assertThat((String) json.opt(VoiceSettings.PRESET_PUNCTUATION_LEVEL), is("none"));
        assertThat(json.opt(VoiceSettings.PRESET_PUNCTUATION_CHARACTERS), is(nullValue()));
    } catch (JSONException e) {
        assertThat(e.toString(), is(nullValue())); // This will be false; used to report exception.
    }
}

From source file:com.reecedunn.espeak.test.VoiceSettingsTest.java

public void testEspeakVariant() {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
    SharedPreferences.Editor editor = prefs.edit();
    editor.clear();//from w  w w  .  j  a va  2 s .co m
    editor.putString("espeak_variant", "klatt2-old");
    editor.commit();

    SpeechSynthesis synth = new SpeechSynthesis(getContext(), mCallback);
    VoiceSettings settings = new VoiceSettings(prefs, synth);
    assertThat(settings.getVoiceVariant().toString(), is("klatt2-old"));
    assertThat(settings.getRate(), is(synth.Rate.getDefaultValue()));
    assertThat(settings.getPitch(), is(synth.Pitch.getDefaultValue()));
    assertThat(settings.getPitchRange(), is(synth.PitchRange.getDefaultValue()));
    assertThat(settings.getVolume(), is(synth.Volume.getDefaultValue()));
    assertThat(settings.getPunctuationLevel(), is(SpeechSynthesis.PUNCT_NONE));
    assertThat(settings.getPunctuationCharacters(), is(nullValue()));

    try {
        JSONObject json = settings.toJSON();
        assertThat(json.opt(VoiceSettings.PRESET_VARIANT), is(instanceOf(String.class)));
        assertThat((String) json.opt(VoiceSettings.PRESET_VARIANT), is("klatt2-old"));
        assertThat(json.opt(VoiceSettings.PRESET_RATE), is(instanceOf(Integer.class)));
        assertThat((Integer) json.opt(VoiceSettings.PRESET_RATE), is(synth.Rate.getDefaultValue()));
        assertThat(json.opt(VoiceSettings.PRESET_PITCH), is(instanceOf(Integer.class)));
        assertThat((Integer) json.opt(VoiceSettings.PRESET_PITCH), is(synth.Pitch.getDefaultValue()));
        assertThat(json.opt(VoiceSettings.PRESET_PITCH_RANGE), is(instanceOf(Integer.class)));
        assertThat((Integer) json.opt(VoiceSettings.PRESET_PITCH_RANGE),
                is(synth.PitchRange.getDefaultValue()));
        assertThat(json.opt(VoiceSettings.PRESET_VOLUME), is(instanceOf(Integer.class)));
        assertThat((Integer) json.opt(VoiceSettings.PRESET_VOLUME), is(synth.Volume.getDefaultValue()));
        assertThat(json.opt(VoiceSettings.PRESET_PUNCTUATION_LEVEL), is(instanceOf(String.class)));
        assertThat((String) json.opt(VoiceSettings.PRESET_PUNCTUATION_LEVEL), is("none"));
        assertThat(json.opt(VoiceSettings.PRESET_PUNCTUATION_CHARACTERS), is(nullValue()));
    } catch (JSONException e) {
        assertThat(e.toString(), is(nullValue())); // This will be false; used to report exception.
    }
}

From source file:com.reecedunn.espeak.test.VoiceSettingsTest.java

public void espeakRateTest(int prefValue, int settingValue, SpeechSynthesis synth) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
    SharedPreferences.Editor editor = prefs.edit();
    editor.clear();//from   w  w w.j a v a2  s. c om
    editor.putString("espeak_rate", Integer.toString(prefValue));
    editor.commit();

    VoiceSettings settings = new VoiceSettings(prefs, synth);
    assertThat(settings.getVoiceVariant().toString(), is("male"));
    assertThat(settings.getRate(), is(settingValue));
    assertThat(settings.getPitch(), is(synth.Pitch.getDefaultValue()));
    assertThat(settings.getPitchRange(), is(synth.PitchRange.getDefaultValue()));
    assertThat(settings.getVolume(), is(synth.Volume.getDefaultValue()));
    assertThat(settings.getPunctuationLevel(), is(SpeechSynthesis.PUNCT_NONE));
    assertThat(settings.getPunctuationCharacters(), is(nullValue()));

    try {
        JSONObject json = settings.toJSON();
        assertThat(json.opt(VoiceSettings.PRESET_VARIANT), is(instanceOf(String.class)));
        assertThat((String) json.opt(VoiceSettings.PRESET_VARIANT), is("male"));
        assertThat(json.opt(VoiceSettings.PRESET_RATE), is(instanceOf(Integer.class)));
        assertThat((Integer) json.opt(VoiceSettings.PRESET_RATE), is(settingValue));
        assertThat(json.opt(VoiceSettings.PRESET_PITCH), is(instanceOf(Integer.class)));
        assertThat((Integer) json.opt(VoiceSettings.PRESET_PITCH), is(synth.Pitch.getDefaultValue()));
        assertThat(json.opt(VoiceSettings.PRESET_PITCH_RANGE), is(instanceOf(Integer.class)));
        assertThat((Integer) json.opt(VoiceSettings.PRESET_PITCH_RANGE),
                is(synth.PitchRange.getDefaultValue()));
        assertThat(json.opt(VoiceSettings.PRESET_VOLUME), is(instanceOf(Integer.class)));
        assertThat((Integer) json.opt(VoiceSettings.PRESET_VOLUME), is(synth.Volume.getDefaultValue()));
        assertThat(json.opt(VoiceSettings.PRESET_PUNCTUATION_LEVEL), is(instanceOf(String.class)));
        assertThat((String) json.opt(VoiceSettings.PRESET_PUNCTUATION_LEVEL), is("none"));
        assertThat(json.opt(VoiceSettings.PRESET_PUNCTUATION_CHARACTERS), is(nullValue()));
    } catch (JSONException e) {
        assertThat(e.toString(), is(nullValue())); // This will be false; used to report exception.
    }
}

From source file:com.reecedunn.espeak.test.VoiceSettingsTest.java

public void espeakPitchTest(int prefValue, int settingValue, SpeechSynthesis synth) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
    SharedPreferences.Editor editor = prefs.edit();
    editor.clear();//from   ww  w . j a  v  a2s .c  o m
    editor.putString("espeak_pitch", Integer.toString(prefValue));
    editor.commit();

    VoiceSettings settings = new VoiceSettings(prefs, synth);
    assertThat(settings.getVoiceVariant().toString(), is("male"));
    assertThat(settings.getRate(), is(synth.Rate.getDefaultValue()));
    assertThat(settings.getPitch(), is(settingValue));
    assertThat(settings.getPitchRange(), is(synth.PitchRange.getDefaultValue()));
    assertThat(settings.getVolume(), is(synth.Volume.getDefaultValue()));
    assertThat(settings.getPunctuationLevel(), is(SpeechSynthesis.PUNCT_NONE));
    assertThat(settings.getPunctuationCharacters(), is(nullValue()));

    try {
        JSONObject json = settings.toJSON();
        assertThat(json.opt(VoiceSettings.PRESET_VARIANT), is(instanceOf(String.class)));
        assertThat((String) json.opt(VoiceSettings.PRESET_VARIANT), is("male"));
        assertThat(json.opt(VoiceSettings.PRESET_RATE), is(instanceOf(Integer.class)));
        assertThat((Integer) json.opt(VoiceSettings.PRESET_RATE), is(synth.Rate.getDefaultValue()));
        assertThat(json.opt(VoiceSettings.PRESET_PITCH), is(instanceOf(Integer.class)));
        assertThat((Integer) json.opt(VoiceSettings.PRESET_PITCH), is(settingValue));
        assertThat(json.opt(VoiceSettings.PRESET_PITCH_RANGE), is(instanceOf(Integer.class)));
        assertThat((Integer) json.opt(VoiceSettings.PRESET_PITCH_RANGE),
                is(synth.PitchRange.getDefaultValue()));
        assertThat(json.opt(VoiceSettings.PRESET_VOLUME), is(instanceOf(Integer.class)));
        assertThat((Integer) json.opt(VoiceSettings.PRESET_VOLUME), is(synth.Volume.getDefaultValue()));
        assertThat(json.opt(VoiceSettings.PRESET_PUNCTUATION_LEVEL), is(instanceOf(String.class)));
        assertThat((String) json.opt(VoiceSettings.PRESET_PUNCTUATION_LEVEL), is("none"));
        assertThat(json.opt(VoiceSettings.PRESET_PUNCTUATION_CHARACTERS), is(nullValue()));
    } catch (JSONException e) {
        assertThat(e.toString(), is(nullValue())); // This will be false; used to report exception.
    }
}

From source file:com.reecedunn.espeak.test.VoiceSettingsTest.java

public void espeakPitchRangeTest(int prefValue, int settingValue, SpeechSynthesis synth) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
    SharedPreferences.Editor editor = prefs.edit();
    editor.clear();//from  w  w w  . j  a  v  a  2s  .c om
    editor.putString("espeak_pitch_range", Integer.toString(prefValue));
    editor.commit();

    VoiceSettings settings = new VoiceSettings(prefs, synth);
    assertThat(settings.getVoiceVariant().toString(), is("male"));
    assertThat(settings.getRate(), is(synth.Rate.getDefaultValue()));
    assertThat(settings.getPitch(), is(synth.Pitch.getDefaultValue()));
    assertThat(settings.getPitchRange(), is(settingValue));
    assertThat(settings.getVolume(), is(synth.Volume.getDefaultValue()));
    assertThat(settings.getPunctuationLevel(), is(SpeechSynthesis.PUNCT_NONE));
    assertThat(settings.getPunctuationCharacters(), is(nullValue()));

    try {
        JSONObject json = settings.toJSON();
        assertThat(json.opt(VoiceSettings.PRESET_VARIANT), is(instanceOf(String.class)));
        assertThat((String) json.opt(VoiceSettings.PRESET_VARIANT), is("male"));
        assertThat(json.opt(VoiceSettings.PRESET_RATE), is(instanceOf(Integer.class)));
        assertThat((Integer) json.opt(VoiceSettings.PRESET_RATE), is(synth.Rate.getDefaultValue()));
        assertThat(json.opt(VoiceSettings.PRESET_PITCH), is(instanceOf(Integer.class)));
        assertThat((Integer) json.opt(VoiceSettings.PRESET_PITCH), is(synth.Pitch.getDefaultValue()));
        assertThat(json.opt(VoiceSettings.PRESET_PITCH_RANGE), is(instanceOf(Integer.class)));
        assertThat((Integer) json.opt(VoiceSettings.PRESET_PITCH_RANGE), is(settingValue));
        assertThat(json.opt(VoiceSettings.PRESET_VOLUME), is(instanceOf(Integer.class)));
        assertThat((Integer) json.opt(VoiceSettings.PRESET_VOLUME), is(synth.Volume.getDefaultValue()));
        assertThat(json.opt(VoiceSettings.PRESET_PUNCTUATION_LEVEL), is(instanceOf(String.class)));
        assertThat((String) json.opt(VoiceSettings.PRESET_PUNCTUATION_LEVEL), is("none"));
        assertThat(json.opt(VoiceSettings.PRESET_PUNCTUATION_CHARACTERS), is(nullValue()));
    } catch (JSONException e) {
        assertThat(e.toString(), is(nullValue())); // This will be false; used to report exception.
    }
}