Skip to content

Commit 7c6e23b

Browse files
JayBazuzitrillium4dsherwoodisidore
committed
! F add ReportByOpeningFiles and deprecate FileLauncherReporter
Co-Authored-By: Trillium Smith <[email protected]> Co-Authored-By: 4dsherwood <[email protected]> Co-Authored-By: Llewellyn Falco <[email protected]>
1 parent 3b351d4 commit 7c6e23b

File tree

3 files changed

+56
-24
lines changed

3 files changed

+56
-24
lines changed
Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,9 @@
11
package org.approvaltests.reporters;
22

3-
import com.spun.util.io.FileUtils;
4-
import com.spun.util.logger.SimpleLogger;
5-
import com.spun.util.tests.TestUtils;
6-
import org.approvaltests.core.ApprovalFailureReporter;
7-
8-
public class FileLauncherReporter implements ApprovalFailureReporter
3+
/**
4+
* @deprecated use ReportByOpeningFiles
5+
*/
6+
@Deprecated
7+
public class FileLauncherReporter extends ReportByOpeningFiles
98
{
10-
@Override
11-
public boolean report(String received, String approved)
12-
{
13-
try
14-
{
15-
if (FileUtils.isNonEmptyFile(approved))
16-
{
17-
TestUtils.displayFile(approved);
18-
}
19-
TestUtils.displayFile(received);
20-
return true;
21-
}
22-
catch (Exception e)
23-
{
24-
SimpleLogger.warning("Error launching file.", e);
25-
return false;
26-
}
27-
}
289
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package org.approvaltests.reporters;
2+
3+
import com.spun.util.io.FileUtils;
4+
import com.spun.util.logger.SimpleLogger;
5+
import com.spun.util.tests.TestUtils;
6+
import org.approvaltests.core.ApprovalFailureReporter;
7+
8+
public class ReportByOpeningFiles implements ApprovalFailureReporter
9+
{
10+
@Override
11+
public boolean report(String received, String approved)
12+
{
13+
try
14+
{
15+
if (FileUtils.isNonEmptyFile(approved))
16+
{
17+
TestUtils.displayFile(approved);
18+
}
19+
TestUtils.displayFile(received);
20+
return true;
21+
}
22+
catch (Exception e)
23+
{
24+
SimpleLogger.warning("Error launching file.", e);
25+
return false;
26+
}
27+
}
28+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# `ReportByOpeningFiles` reporter
2+
3+
The `ReportByOpeningFiles` class provides a simple mechanism to open approved and received files using the system's default application for their file type.
4+
5+
## Purpose
6+
Allows users to visually inspect the received and approved files by automatically launching them on failure. This is useful when the file type corresponds to a tool that provides a good viewing or diffing experience, or as a fallback reporter.
7+
8+
## Features
9+
- **Automatic File Launching**: Opens files using the default system application associated with the file extension.
10+
- **Conditional Approved File Launch**: Only attempts to open the approved file if it exists and is non-empty.
11+
- **Robust Error Handling**: Catches exceptions during launch and logs a warning instead of failing the test execution flow.
12+
13+
## Behavior
14+
1. **report(received, approved)**: The main entry point for the reporter.
15+
2. **Checks Approved File**: Verifies if the `approved` file is a non-empty file.
16+
3. **Launches Approved File**: If the approved file exists and has content, it is opened using `TestUtils.displayFile(approved)`.
17+
4. **Launches Received File**: The `received` file is always opened using `TestUtils.displayFile(received)`.
18+
5. **Error Handling**: If any exception occurs during the process (e.g., file not found, no associated application), it is caught, logged as a warning, and the method returns `false`.
19+
6. **Success**: Returns `true` if the operation completes without exception.
20+
21+
22+
## Integration
23+
- Implements the `ApprovalFailureReporter` interface.

0 commit comments

Comments
 (0)