Java Test Automation / Quiz

Exceptions Without False Greens

Distinguish checked and unchecked failures, close resources reliably, and assert expected exceptions without swallowing real defects.

Difficulty
Medium
Format
Quiz
Points
150
Estimate
8 min

// MISSION BRIEF

Your Mission

Test utilities cross files, APIs, and assertions, so failure handling is part of their contract. Inspect Java fragments and keep expected error behavior distinct from infrastructure faults and accidentally swallowed failures.

// FIRST CONTACT

Battle teaser

This helper does not compile: String load(Path path) { return Files.readString(path); } Why, and what are the normal choices?

  1. AFiles.readString only works inside a static initializer
  2. BPath is unchecked, so it must be converted to an int
  3. CFiles.readString can throw checked IOException, so load must catch it meaningfully or declare it with throws IOException
  4. DEvery method that returns String must catch RuntimeException
Answers, scoring, hints, and the full battle stay sealed.

// SKILL TAGS

java-exceptionstry-with-resourcesassertthrowsjava-testing