Skip to content

Commit

Permalink
remove "expected" exception from unit tests
Browse files Browse the repository at this point in the history
It pollutes the console and makes debugging the build harder.
Asserting can also make the failure mode testing more precise.

Signed-off-by: Matthew Khouzam <[email protected]>
  • Loading branch information
MatthewKhouzam committed Mar 15, 2024
1 parent 3c9d7f2 commit 27a590e
Showing 1 changed file with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.util.logging.ErrorManager;
import java.util.logging.Filter;
import java.util.logging.Formatter;
Expand All @@ -43,7 +44,7 @@
import org.junit.Test;

/**
* Test aynchronous file hnandler
* Test aynchronous file handler
*/
public class AsyncFileHandlerTest {

Expand Down Expand Up @@ -91,19 +92,26 @@ public void testGoodConfigure() {
* @throws SecurityException
* won't happen
*/
@Test(expected = IOException.class)
@Test
public void testBadConfigure() throws SecurityException, IOException {
try (InputStream fis = new FileInputStream(
new File("./src/test/java/org/eclipse/tracecompass/trace_event_logger/res/badlogging.properties"))) { //$NON-NLS-1$
LogManager manager = LogManager.getLogManager();
try {
LogManager manager = LogManager.getLogManager();
manager.readConfiguration(fis);
String prop = manager.getProperty("org.eclipse.tracecompass.trace_event_logger.SnapshotHandler.maxEvents"); //$NON-NLS-1$
assertNotNull(prop);
} catch (IOException e) {
fail(e.getMessage());
}
new AsyncFileHandler();
try {
new AsyncFileHandler();
} catch (UnsupportedEncodingException e) {
assertNotNull(e);
assertEquals("uTF-6", e.getMessage()); //$NON-NLS-1$
manager.reset();
return;
}
fail("should have failed above"); //$NON-NLS-1$
} catch (FileNotFoundException e) {
fail(e.getMessage());
Expand Down

0 comments on commit 27a590e

Please sign in to comment.