package org.valid4j.impl;

import org.valid4j.UnreachablePolicy;
import org.valid4j.exceptions.ContractViolation;
import org.valid4j.exceptions.NeverGetHereViolation;

import java.util.Queue;

import static org.valid4j.Message.withFormattedMessage;

/**
 * Policy for handling unreachable code by throwing an unrecoverable exception.
 */
public class NeverGetHerePolicy implements UnreachablePolicy {

  private final Queue<ContractViolation> violations;

  public NeverGetHerePolicy(Queue<ContractViolation> violations) {
    this.violations = violations;
  }

  @Override
  public void neverGetHere(Throwable cause, String msg, Object... values) {
    throw tracked(new NeverGetHereViolation(cause, withFormattedMessage(msg, values)));
  }

  private NeverGetHereViolation tracked(NeverGetHereViolation neverGetHereViolation) {
    violations.offer(neverGetHereViolation);
    return neverGetHereViolation;
  }
}

@@ -367,92 +367,70 @@
 icy 
-implements UnreachablePolicy %7B%0A%0A  private final Queue%3CContractViolation%3E violations;
+extends TrackingViolationPolicy implements UnreachablePolicy %7B
 %0A%0A  
@@ -502,13 +502,14 @@
     
-this.
+super(
 viol
@@ -518,21 +518,9 @@
 ions
- = violations
+)
 ;%0A  
@@ -606,24 +606,24 @@
 . values) %7B%0A
+
     throw tr
@@ -705,178 +705,7 @@
 %0A  %7D
-%0A%0A  private NeverGetHereViolation tracked(NeverGetHereViolation neverGetHereViolation) %7B%0A    violations.offer(neverGetHereViolation);%0A    return neverGetHereViolation;%0A  %7D
 %0A%7D%0A

Use the tracking policy to track thrown never-get-here errors