@Test void testMultipleDecorators() { DoSomething before1 = mock(DoSomething.class); DoSomething after1 = mock(DoSomething.class); DoSomething before2 = mock(DoSomething.class); DoSomething after2 = mock(DoSomething.class); Runnable runnable = mock(Runnable.class); InOrder inOrder = Mockito.inOrder(before1, after1, before2, after2, runnable); CompositeTaskDecorator underTest = new CompositeTaskDecorator(List.of( TestDecorator.around(before1, after1), TestDecorator.around(before2, after2))); Runnable decoratedRunnable = underTest.decorate(runnable); decoratedRunnable.run(); inOrder.verify(before2).doSomething(); inOrder.verify(before1).doSomething(); inOrder.verify(runnable).run(); inOrder.verify(after1).doSomething(); inOrder.verify(after2).doSomething(); }
@Override public Runnable decorate(Runnable runnable) { Runnable decoratedRunnable = requireNonNull(runnable, "runnable is null"); for (TaskDecorator decorator : decorators) { decoratedRunnable = decorator.decorate(decoratedRunnable); } return decoratedRunnable; }
CompositeTaskDecorator implements TaskDecorator { @Override public Runnable decorate(Runnable runnable) { Runnable decoratedRunnable = requireNonNull(runnable, "runnable is null"); for (TaskDecorator decorator : decorators) { decoratedRunnable = decorator.decorate(decoratedRunnable); } return decoratedRunnable; } }
CompositeTaskDecorator implements TaskDecorator { @Override public Runnable decorate(Runnable runnable) { Runnable decoratedRunnable = requireNonNull(runnable, "runnable is null"); for (TaskDecorator decorator : decorators) { decoratedRunnable = decorator.decorate(decoratedRunnable); } return decoratedRunnable; } CompositeTaskDecorator(List<TaskDecorator> decorators); }
CompositeTaskDecorator implements TaskDecorator { @Override public Runnable decorate(Runnable runnable) { Runnable decoratedRunnable = requireNonNull(runnable, "runnable is null"); for (TaskDecorator decorator : decorators) { decoratedRunnable = decorator.decorate(decoratedRunnable); } return decoratedRunnable; } CompositeTaskDecorator(List<TaskDecorator> decorators); @Override Runnable decorate(Runnable runnable); }
CompositeTaskDecorator implements TaskDecorator { @Override public Runnable decorate(Runnable runnable) { Runnable decoratedRunnable = requireNonNull(runnable, "runnable is null"); for (TaskDecorator decorator : decorators) { decoratedRunnable = decorator.decorate(decoratedRunnable); } return decoratedRunnable; } CompositeTaskDecorator(List<TaskDecorator> decorators); @Override Runnable decorate(Runnable runnable);  }