/impl/src/main/java/org/jboss/arquillian/persistence/test/AssertionErrorCollector.java

https://github.com/aslakknutsen/arquillian-extension-persistence · Java · 59 lines · 25 code · 7 blank · 27 comment · 2 complexity · f264d401ef8796959aaa3013bbf148b2 MD5 · raw file

  1. /*
  2. * JBoss, Home of Professional Open Source
  3. * Copyright 2011 Red Hat Inc. and/or its affiliates and other contributors
  4. * as indicated by the @authors tag. All rights reserved.
  5. * See the copyright.txt in the distribution for a
  6. * full listing of individual contributors.
  7. *
  8. * Licensed under the Apache License, Version 2.0 (the "License");
  9. * you may not use this file except in compliance with the License.
  10. * You may obtain a copy of the License at
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. package org.jboss.arquillian.persistence.test;
  19. import java.util.ArrayList;
  20. import java.util.List;
  21. /**
  22. * Collects all assertion errors which occurred during test execution
  23. * to report them back at the end of test lifecycle. This approach
  24. * allows to run through entire test execution and executed all
  25. * required phases (like cleaning up database at the end of each
  26. * persistence test) - so called soft assertion.
  27. *
  28. * @author <a href="mailto:bartosz.majsak@gmail.com">Bartosz Majsak</a>
  29. *
  30. */
  31. public class AssertionErrorCollector
  32. {
  33. private final List<String> assertionErrors = new ArrayList<String>();
  34. public void collect(AssertionError error)
  35. {
  36. assertionErrors.add(error.getMessage());
  37. }
  38. public void report()
  39. {
  40. if (assertionErrors.isEmpty())
  41. {
  42. return;
  43. }
  44. final StringBuilder builder = new StringBuilder();
  45. builder.append("Test failed in " + assertionErrors.size() + " cases. \n");
  46. for (String errorMessage : assertionErrors)
  47. {
  48. builder.append(errorMessage).append('\n');
  49. }
  50. throw new AssertionError(builder.toString());
  51. }
  52. }