### Question:
ReadOnlySwaggerDecoration extends AbstractSwaggerExtension { @Override public void decorateOperation(Operation operation, Method method, Iterator<SwaggerExtension> chain) { if(method.isAnnotationPresent(GET.class)) { operation.setVendorExtension(SWAGGER_EXTENSION_READ_ONLY, Boolean.TRUE); if (chain.hasNext()) { chain.next().decorateOperation(operation, method, chain); } return; } KieServerEndpoint api = method.getAnnotation(KieServerEndpoint.class); if(api == null) { api = method.getDeclaringClass().getAnnotation(KieServerEndpoint.class); } if (api != null) { List<EndpointType> current = new ArrayList<>(asList(api.categories())); current.retainAll(valid); if(!current.isEmpty()) { operation.setVendorExtension(SWAGGER_EXTENSION_READ_ONLY, Boolean.TRUE); } } if (chain.hasNext()) { chain.next().decorateOperation(operation, method, chain); } }  @Override void decorateOperation(Operation operation, Method method, Iterator<SwaggerExtension> chain); static final String SWAGGER_EXTENSION_READ_ONLY; }### Answer:
@Test public void testGetAlwaysPass() throws Exception { ReadOnlySwaggerDecoration decoration = new ReadOnlySwaggerDecoration(); Operation operation = new Operation(); decoration.decorateOperation(operation, TestSimpleOperations.class.getMethod("test1"), emptyListIterator()); Assert.assertThat(operation.getVendorExtensions().keySet(), hasItems(SWAGGER_EXTENSION_READ_ONLY)); }
@Test public void testOtherOperationNoPass() throws Exception { ReadOnlySwaggerDecoration decoration = new ReadOnlySwaggerDecoration(); Operation operation = new Operation(); decoration.decorateOperation(operation, TestSimpleOperations.class.getMethod("test2"), emptyListIterator()); Assert.assertThat(operation.getVendorExtensions().keySet(), not(hasItems(SWAGGER_EXTENSION_READ_ONLY))); }
@Test public void testOtherNoPassAnnotationPass() throws Exception { ReadOnlySwaggerDecoration decoration = new ReadOnlySwaggerDecoration(); Operation operation = new Operation(); decoration.decorateOperation(operation, TestAnnotationOperations.class.getMethod("test1"), emptyListIterator()); Assert.assertThat(operation.getVendorExtensions().keySet(), not(hasItems(SWAGGER_EXTENSION_READ_ONLY))); }
@Test public void testOtherAlwaysPassAnnotationPass() throws Exception { ReadOnlySwaggerDecoration decoration = new ReadOnlySwaggerDecoration(); Operation operation = new Operation(); decoration.decorateOperation(operation, TestAnnotationOperations.class.getMethod("test2"), emptyListIterator()); Assert.assertThat(operation.getVendorExtensions().keySet(), hasItems(SWAGGER_EXTENSION_READ_ONLY)); }
@Test public void testOtherOverrideBadPassAnnotationPass() throws Exception { ReadOnlySwaggerDecoration decoration = new ReadOnlySwaggerDecoration(); Operation operation = new Operation(); decoration.decorateOperation(operation, TestTypeAnnotationOperations.class.getMethod("test1"), emptyListIterator()); Assert.assertThat(operation.getVendorExtensions().keySet(), not(hasItems(SWAGGER_EXTENSION_READ_ONLY))); }
@Test public void testOtherTypePassAnnotationPass() throws Exception { ReadOnlySwaggerDecoration decoration = new ReadOnlySwaggerDecoration(); Operation operation = new Operation(); decoration.decorateOperation(operation, TestTypeAnnotationOperations.class.getMethod("test2"), emptyListIterator()); Assert.assertThat(operation.getVendorExtensions().keySet(), hasItems(SWAGGER_EXTENSION_READ_ONLY)); }