### Question:
Strings { public static String getFormattedFileName(){ return getFormattedFileName(Session.getInstance(), PreferenceHelper.getInstance()); }  static String getDescriptiveDurationString(int numberOfSeconds,
                                                      Context context); static String getBearingDescription(float bearingDegrees,
                                               Context context); static String cleanDescriptionForXml(String desc); static String cleanDescriptionForJson(String desc); static String getIsoDateTime(Date dateToFormat); static String getIsoDateTimeFormat(); static String getIsoCalendarDate(Date dateToFormat); static String getIsoCalendarDateFormat(); static String getReadableDateTime(Date dateToFormat); static boolean isNullOrEmpty(String text); static String htmlDecode(String text); static String getBuildSerial(); static String getFormattedFileName(); static String getFormattedFileName(Session session, PreferenceHelper ph); static String getFormattedCustomFileName(String baseName, Calendar calendar, PreferenceHelper ph); static int toInt(String number, int defaultVal); static String getSpeedDisplay(Context context, double metersPerSecond, boolean imperial); static String getDistanceDisplay(Context context, double meters, boolean imperial, boolean autoscale); static String getTimeDisplay(Context context, long milliseconds); static Map<String, String> getAvailableLocales(Context context); static String getSanitizedMarkdownForFaqView(String md); static String getDegreesMinutesSeconds(double decimaldegrees, boolean isLatitude); static String getDegreesDecimalMinutes(double decimaldegrees, boolean isLatitude); static String getDecimalDegrees(double decimaldegrees); static String getFormattedLatitude(double decimaldegrees); static String getFormattedLongitude(double decimaldegrees); static String getDetectedActivityName(DetectedActivity detectedActivity);  }### Answer:
@Test public void getFormattedFileName_BasicFileName_ReturnsAsIs(){ Session sess = mock(Session.class); when(sess.getCurrentFileName()).thenReturn("hello"); PreferenceHelper ph = mock(PreferenceHelper.class); String expected = "hello"; String actual = Strings.getFormattedFileName(sess, ph); assertThat("Basic file name unchanged", actual, is(expected)); when(sess.getCurrentFileName()).thenReturn(""); expected = ""; actual = Strings.getFormattedFileName(sess, ph); assertThat("Empty file name returns empty string", actual, is(expected)); }
@Test public void getFormattedFileName_CreateCustomFileName_ReturnsFormatted(){ Session sess = mock(Session.class); when(sess.getCurrentFileName()).thenReturn("basename_%ver"); PreferenceHelper ph = mock(PreferenceHelper.class); when(ph.shouldCreateCustomFile()).thenReturn(true); String expected = "basename_" + BuildConfig.VERSION_NAME; String actual = Strings.getFormattedFileName(sess, ph); assertThat("Custom file name should do substitutions", actual, is(expected)); }
@Test public void getFormattedFileName_shouldPrefixSerialToFileName(){ Session sess = mock(Session.class); when(sess.getCurrentFileName()).thenReturn("somefile"); PreferenceHelper ph = mock(PreferenceHelper.class); when(ph.shouldPrefixSerialToFileName()).thenReturn(true); String expected = Build.SERIAL + "_somefile"; String actual = Strings.getFormattedFileName(sess,ph); assertThat("Build serial is prefixed to file name", actual, is(expected)); }
@Test public void getFormattedFileName_shouldPrefixSerialToFileName_SerialOnlyIncludedOnce(){ Session sess = mock(Session.class); when(sess.getCurrentFileName()).thenReturn(Build.SERIAL + "___somefile"); PreferenceHelper ph = mock(PreferenceHelper.class); when(ph.shouldPrefixSerialToFileName()).thenReturn(true); String expected = Build.SERIAL + "___somefile"; String actual = Strings.getFormattedFileName(sess, ph); assertThat("Build serial only included once", actual, is(expected)); }