void (AnnotationHolder holder, Function<? super AnnotationBuilder, ? extends AnnotationBuilder> method) { try { AnnotationBuilder builder = holder.newAnnotation(HighlightSeverity.ERROR, "xxx"); method.apply(builder); method.apply(builder); builder.create(); fail("Must have failed"); } catch (IllegalStateException ignored) { } // once is OK AnnotationBuilder builder = holder.newAnnotation(HighlightSeverity.ERROR, "xxx"); AnnotationBuilder newBuilder = method.apply(builder); assertSame(newBuilder, builder); builder.create(); }