@Test public void throwJSONExceptionWhenGetMinidumpSubfolderWithDeviceInfo() throws java.lang.Exception { Device mockDevice = mock(Device.class); mockStatic(DeviceInfoHelper.class); when(DeviceInfoHelper.getDeviceInfo(any(Context.class))).thenReturn(mockDevice); Context mockContext = mock(Context.class); File mockFile = mock(File.class); whenNew(File.class).withAnyArguments().thenReturn(mockFile); doThrow(new JSONException("crash", new java.lang.Exception())).when(mockDevice).write(any(JSONStringer.class)); ErrorLogHelper.getNewMinidumpSubfolderWithContextData(mockContext); verify(mockFile).delete(); }
@NonNull public static synchronized File getNewMinidumpSubfolderWithContextData(Context context) { File directorySubfolder = getNewMinidumpSubfolder(); File deviceInfoFile = new File(directorySubfolder, ErrorLogHelper.DEVICE_INFO_FILE); try { Device deviceInfo = DeviceInfoHelper.getDeviceInfo(context); deviceInfo.setWrapperSdkName(WRAPPER_SDK_NAME_NDK); JSONStringer writer = new JSONStringer(); writer.object(); deviceInfo.write(writer); writer.endObject(); String deviceInfoString = writer.toString(); FileManager.write(deviceInfoFile, deviceInfoString); } catch (DeviceInfoHelper.DeviceInfoException | IOException | JSONException e) { AppCenterLog.error(Crashes.LOG_TAG, "Failed to store device info in a minidump folder.", e); deviceInfoFile.delete(); } return directorySubfolder; }
ErrorLogHelper { @NonNull public static synchronized File getNewMinidumpSubfolderWithContextData(Context context) { File directorySubfolder = getNewMinidumpSubfolder(); File deviceInfoFile = new File(directorySubfolder, ErrorLogHelper.DEVICE_INFO_FILE); try { Device deviceInfo = DeviceInfoHelper.getDeviceInfo(context); deviceInfo.setWrapperSdkName(WRAPPER_SDK_NAME_NDK); JSONStringer writer = new JSONStringer(); writer.object(); deviceInfo.write(writer); writer.endObject(); String deviceInfoString = writer.toString(); FileManager.write(deviceInfoFile, deviceInfoString); } catch (DeviceInfoHelper.DeviceInfoException | IOException | JSONException e) { AppCenterLog.error(Crashes.LOG_TAG, "Failed to store device info in a minidump folder.", e); deviceInfoFile.delete(); } return directorySubfolder; } }
ErrorLogHelper { @NonNull public static synchronized File getNewMinidumpSubfolderWithContextData(Context context) { File directorySubfolder = getNewMinidumpSubfolder(); File deviceInfoFile = new File(directorySubfolder, ErrorLogHelper.DEVICE_INFO_FILE); try { Device deviceInfo = DeviceInfoHelper.getDeviceInfo(context); deviceInfo.setWrapperSdkName(WRAPPER_SDK_NAME_NDK); JSONStringer writer = new JSONStringer(); writer.object(); deviceInfo.write(writer); writer.endObject(); String deviceInfoString = writer.toString(); FileManager.write(deviceInfoFile, deviceInfoString); } catch (DeviceInfoHelper.DeviceInfoException | IOException | JSONException e) { AppCenterLog.error(Crashes.LOG_TAG, "Failed to store device info in a minidump folder.", e); deviceInfoFile.delete(); } return directorySubfolder; }  }
ErrorLogHelper { @NonNull public static synchronized File getNewMinidumpSubfolderWithContextData(Context context) { File directorySubfolder = getNewMinidumpSubfolder(); File deviceInfoFile = new File(directorySubfolder, ErrorLogHelper.DEVICE_INFO_FILE); try { Device deviceInfo = DeviceInfoHelper.getDeviceInfo(context); deviceInfo.setWrapperSdkName(WRAPPER_SDK_NAME_NDK); JSONStringer writer = new JSONStringer(); writer.object(); deviceInfo.write(writer); writer.endObject(); String deviceInfoString = writer.toString(); FileManager.write(deviceInfoFile, deviceInfoString); } catch (DeviceInfoHelper.DeviceInfoException | IOException | JSONException e) { AppCenterLog.error(Crashes.LOG_TAG, "Failed to store device info in a minidump folder.", e); deviceInfoFile.delete(); } return directorySubfolder; }  @NonNull static ManagedErrorLog createErrorLog(@NonNull Context context, @NonNull final java.lang.Thread thread, @NonNull final Throwable throwable, @NonNull final Map<java.lang.Thread, StackTraceElement[]> allStackTraces, final long initializeTimestamp); @NonNull static ManagedErrorLog createErrorLog(@NonNull Context context, @NonNull final java.lang.Thread thread, @NonNull final Exception exception, @NonNull final Map<java.lang.Thread, StackTraceElement[]> allStackTraces, final long initializeTimestamp, boolean fatal); @NonNull static synchronized File getErrorStorageDirectory(); @NonNull static synchronized File getNewMinidumpDirectory(); @NonNull static synchronized File getNewMinidumpSubfolder(); @NonNull static synchronized File getNewMinidumpSubfolderWithContextData(Context context); @NonNull static synchronized File getPendingMinidumpDirectory(); @NonNull static File[] getStoredErrorLogFiles(); @NonNull static File[] getNewMinidumpFiles(); @Nullable static Device getStoredDeviceInfo(File logFolder); static void removeStaleMinidumpSubfolders(); static void removeMinidumpFolder(); @Nullable static File getLastErrorLogFile(); @Nullable static File getStoredThrowableFile(@NonNull UUID id); static void removeStoredThrowableFile(@NonNull UUID id); static void removeStoredErrorLogFile(@NonNull UUID id); @NonNull static ErrorReport getErrorReportFromErrorLog(@NonNull ManagedErrorLog log, String stackTrace); @NonNull static Exception getModelExceptionFromThrowable(@NonNull Throwable t); static Map<String, String> validateProperties(Map<String, String> properties, String logType); static void cleanPendingMinidumps(); @NonNull static UUID parseLogFolderUuid(File logFolder); @VisibleForTesting static void clearStaticState(); }
ErrorLogHelper { @NonNull public static synchronized File getNewMinidumpSubfolderWithContextData(Context context) { File directorySubfolder = getNewMinidumpSubfolder(); File deviceInfoFile = new File(directorySubfolder, ErrorLogHelper.DEVICE_INFO_FILE); try { Device deviceInfo = DeviceInfoHelper.getDeviceInfo(context); deviceInfo.setWrapperSdkName(WRAPPER_SDK_NAME_NDK); JSONStringer writer = new JSONStringer(); writer.object(); deviceInfo.write(writer); writer.endObject(); String deviceInfoString = writer.toString(); FileManager.write(deviceInfoFile, deviceInfoString); } catch (DeviceInfoHelper.DeviceInfoException | IOException | JSONException e) { AppCenterLog.error(Crashes.LOG_TAG, "Failed to store device info in a minidump folder.", e); deviceInfoFile.delete(); } return directorySubfolder; }  @NonNull static ManagedErrorLog createErrorLog(@NonNull Context context, @NonNull final java.lang.Thread thread, @NonNull final Throwable throwable, @NonNull final Map<java.lang.Thread, StackTraceElement[]> allStackTraces, final long initializeTimestamp); @NonNull static ManagedErrorLog createErrorLog(@NonNull Context context, @NonNull final java.lang.Thread thread, @NonNull final Exception exception, @NonNull final Map<java.lang.Thread, StackTraceElement[]> allStackTraces, final long initializeTimestamp, boolean fatal); @NonNull static synchronized File getErrorStorageDirectory(); @NonNull static synchronized File getNewMinidumpDirectory(); @NonNull static synchronized File getNewMinidumpSubfolder(); @NonNull static synchronized File getNewMinidumpSubfolderWithContextData(Context context); @NonNull static synchronized File getPendingMinidumpDirectory(); @NonNull static File[] getStoredErrorLogFiles(); @NonNull static File[] getNewMinidumpFiles(); @Nullable static Device getStoredDeviceInfo(File logFolder); static void removeStaleMinidumpSubfolders(); static void removeMinidumpFolder(); @Nullable static File getLastErrorLogFile(); @Nullable static File getStoredThrowableFile(@NonNull UUID id); static void removeStoredThrowableFile(@NonNull UUID id); static void removeStoredErrorLogFile(@NonNull UUID id); @NonNull static ErrorReport getErrorReportFromErrorLog(@NonNull ManagedErrorLog log, String stackTrace); @NonNull static Exception getModelExceptionFromThrowable(@NonNull Throwable t); static Map<String, String> validateProperties(Map<String, String> properties, String logType); static void cleanPendingMinidumps(); @NonNull static UUID parseLogFolderUuid(File logFolder); @VisibleForTesting static void clearStaticState(); static final String DEVICE_INFO_FILE; static final String ERROR_LOG_FILE_EXTENSION; static final String THROWABLE_FILE_EXTENSION; @VisibleForTesting
    static final int FRAME_LIMIT; static final int MAX_PROPERTY_ITEM_LENGTH; static final String MINIDUMP_FILE_EXTENSION; }