You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CompilationAndWeavingContextTest.java 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /* *******************************************************************
  2. * Copyright (c) 2005 Contributors.
  3. * All rights reserved.
  4. * This program and the accompanying materials are made available
  5. * under the terms of the Eclipse Public License v1.0
  6. * which accompanies this distribution and is available at
  7. * http://eclipse.org/legal/epl-v10.html
  8. *
  9. * Contributors:
  10. * Adrian Colyer Initial implementation
  11. * ******************************************************************/
  12. package org.aspectj.bridge.context;
  13. import junit.framework.TestCase;
  14. /**
  15. * @author colyer
  16. *
  17. */
  18. public class CompilationAndWeavingContextTest extends TestCase {
  19. public void testEnteringPhase() {
  20. CompilationAndWeavingContext.enteringPhase(1,"XYZ");
  21. assertEquals("when fiddling XYZ\n",CompilationAndWeavingContext.getCurrentContext());
  22. }
  23. public void testDoubleEntry() {
  24. CompilationAndWeavingContext.enteringPhase(1,"XYZ");
  25. CompilationAndWeavingContext.enteringPhase(2, "ABC");
  26. assertEquals("when fiddling XYZ\nwhen mucking about with ABC\n",CompilationAndWeavingContext.getCurrentContext());
  27. }
  28. public void testEntryEntryExit() {
  29. CompilationAndWeavingContext.enteringPhase(1,"XYZ");
  30. ContextToken ct = CompilationAndWeavingContext.enteringPhase(2, "ABC");
  31. CompilationAndWeavingContext.leavingPhase(ct);
  32. assertEquals("when fiddling XYZ\n",CompilationAndWeavingContext.getCurrentContext());
  33. }
  34. public void testEntryExitTop() {
  35. ContextToken ct = CompilationAndWeavingContext.enteringPhase(1,"XYZ");
  36. CompilationAndWeavingContext.enteringPhase(2, "ABC");
  37. CompilationAndWeavingContext.leavingPhase(ct);
  38. assertEquals("",CompilationAndWeavingContext.getCurrentContext());
  39. }
  40. protected void setUp() throws Exception {
  41. CompilationAndWeavingContext.reset();
  42. CompilationAndWeavingContext.registerFormatter(1, new MyContextFormatter("fiddling "));
  43. CompilationAndWeavingContext.registerFormatter(2, new MyContextFormatter("mucking about with "));
  44. }
  45. private static class MyContextFormatter implements ContextFormatter {
  46. private String prefix;
  47. public MyContextFormatter(String prefix) {
  48. this.prefix = prefix;
  49. }
  50. public String formatEntry(int phaseId, Object data) {
  51. return prefix + data.toString();
  52. }
  53. }
  54. }