Package com.google.gwt.dev.util

Examples of com.google.gwt.dev.util.UnitTestTreeLogger$Builder


    loggerBuilder.expectError("bad5 cannot be resolved to a type", null);
    loggerBuilder.expectError("Errors in '/mock/bad5.java'", null);
    loggerBuilder.expectError("bad3 cannot be resolved to a type", null);
    loggerBuilder.expectError("Errors in '/mock/bad3.java'", null);
    loggerBuilder.expectError("bad1 cannot be resolved to a type", null);
    UnitTestTreeLogger testLogger = loggerBuilder.createLogger();
    CompilationProblemReporter.logErrorTrace(testLogger, TreeLogger.ERROR, compilerContext, "bad6",
        false);
    testLogger.assertCorrectLogEntries();

    // Check that validClasses is not mutated
    assertEquals(knownValidClasses, validClasses);

    // Check that units is mutated
View Full Code Here


    builder.setLowestLogLevel(TreeLogger.ERROR);
    for (String expectedMsg : expected) {
      builder.expectError(expectedMsg, null);
    }
    builder.expectError(RequestFactoryModel.poisonedMessage(), null);
    UnitTestTreeLogger testLogger = builder.createLogger();
    try {
      new RequestFactoryModel(testLogger, state.getTypeOracle().findType(
          "t.TestRequestFactory"));
      fail("Should have complained");
    } catch (UnableToCompleteException e) {
    }
    testLogger.assertCorrectLogEntries();
  }
View Full Code Here

* Tests output functions.
*/
public class CssOutputTestCase extends TestCase {

  public void testOutputCssMapArtifact() throws UnableToCompleteException {
    UnitTestTreeLogger testLogger = new UnitTestTreeLogger.Builder().createLogger();
    ResourceContext mockResourceContext = mock(ResourceContext.class);
    Map<JMethod, String> testMap = new HashMap<JMethod, String>();
    OutputStream mockOutputStream = mock(OutputStream.class);
    GeneratorContext mockGeneratorContext = mock(GeneratorContext.class);
    GeneratedResource mockGeneratedResource = mock(GeneratedResource.class);

    when(mockResourceContext.getGeneratorContext()).thenReturn(mockGeneratorContext);
    when(mockGeneratorContext.tryCreateResource(
        testLogger, "cssResource/com.test.Bundle.cssMethod.cssmap")).thenReturn(mockOutputStream);
    when(mockGeneratorContext.commitResource(testLogger, mockOutputStream)).thenReturn(
        mockGeneratedResource);

    JMethod method = mock(JMethod.class);
    JClassType bundleType = mock(JClassType.class);
    when(method.getEnclosingType()).thenReturn(bundleType);
    when(bundleType.getQualifiedSourceName()).thenReturn("com.test.Bundle");
    when(method.getName()).thenReturn("cssMethod");

    CssResourceGenerator crg = new CssResourceGenerator();
    // Test the method
    crg.outputCssMapArtifact(testLogger, mockResourceContext, method, testMap);

    testLogger.assertCorrectLogEntries();

    verify(mockGeneratorContext).tryCreateResource(testLogger, "cssResource/com.test.Bundle.cssMethod.cssmap");
    verify(mockGeneratorContext).commitResource(testLogger, mockOutputStream);
    verifyNoMoreInteractions(mockGeneratorContext);
  }
View Full Code Here

  public void testOutputCssMapArtifactThrowOnTryCreateResource() throws UnableToCompleteException {
    UnitTestTreeLogger.Builder builder = new UnitTestTreeLogger.Builder();
    builder.expectWarn(
        "Could not create resource: cssResource/com.test.Bundle.cssMethod.cssmap", null);
    UnitTestTreeLogger testLogger =  builder.createLogger();
    ResourceContext mockResourceContext = mock(ResourceContext.class);
    Map<JMethod, String> testMap = new HashMap<JMethod, String>();
    GeneratorContext mockGeneratorContext = mock(GeneratorContext.class);

    when(mockResourceContext.getGeneratorContext()).thenReturn(mockGeneratorContext);
    when(mockGeneratorContext.tryCreateResource(testLogger,
        "cssResource/com.test.Bundle.cssMethod.cssmap")).thenThrow(new UnableToCompleteException());

    JMethod method = mock(JMethod.class);
    JClassType bundleType = mock(JClassType.class);
    when(method.getEnclosingType()).thenReturn(bundleType);
    when(bundleType.getQualifiedSourceName()).thenReturn("com.test.Bundle");
    when(method.getName()).thenReturn("cssMethod");

    CssResourceGenerator crg = new CssResourceGenerator();
    crg.outputCssMapArtifact(testLogger, mockResourceContext, method, testMap);

    testLogger.assertCorrectLogEntries();

    verify(mockGeneratorContext).tryCreateResource(testLogger, "cssResource/com.test.Bundle.cssMethod.cssmap");
    verifyNoMoreInteractions(mockGeneratorContext);
  }
View Full Code Here

    verify(mockGeneratorContext).tryCreateResource(testLogger, "cssResource/com.test.Bundle.cssMethod.cssmap");
    verifyNoMoreInteractions(mockGeneratorContext);
  }

  public void testOutputCssMapArtifactReturnNullOutputString() throws UnableToCompleteException {
    UnitTestTreeLogger testLogger = new UnitTestTreeLogger.Builder().createLogger();
    ResourceContext mockResourceContext = mock(ResourceContext.class);
    Map<JMethod, String> testMap = new HashMap<JMethod, String>();
    GeneratorContext mockGeneratorContext = mock(GeneratorContext.class);

    when(mockResourceContext.getGeneratorContext()).thenReturn(mockGeneratorContext);
    when(mockGeneratorContext.tryCreateResource(
        testLogger, "cssResource/com.test.Bundle.cssMethod.cssmap")).thenReturn(null);

    JMethod method = mock(JMethod.class);
    JClassType bundleType = mock(JClassType.class);
    when(method.getEnclosingType()).thenReturn(bundleType);
    when(bundleType.getQualifiedSourceName()).thenReturn("com.test.Bundle");
    when(method.getName()).thenReturn("cssMethod");

    CssResourceGenerator crg = new CssResourceGenerator();
    crg.outputCssMapArtifact(testLogger, mockResourceContext, method, testMap);

    testLogger.assertCorrectLogEntries();

    verify(mockGeneratorContext).tryCreateResource(testLogger,
        "cssResource/com.test.Bundle.cssMethod.cssmap");
    verifyNoMoreInteractions(mockGeneratorContext);
  }
View Full Code Here

  public void testOutputCssMapArtifactThrowOnCommitResource() throws UnableToCompleteException {
    UnitTestTreeLogger.Builder builder = new UnitTestTreeLogger.Builder();
    builder.expectWarn(
        "Error trying to commit artifact: cssResource/com.test.Bundle.cssMethod.cssmap", null);
    UnitTestTreeLogger testLogger =  builder.createLogger();
    ResourceContext mockResourceContext = mock(ResourceContext.class);
    Map<JMethod, String> testMap = new HashMap<JMethod, String>();
    OutputStream mockOutputStream = mock(OutputStream.class);
    GeneratorContext mockGeneratorContext = mock(GeneratorContext.class);

    when(mockResourceContext.getGeneratorContext()).thenReturn(mockGeneratorContext);
    when(mockGeneratorContext.tryCreateResource(
        testLogger, "cssResource/com.test.Bundle.cssMethod.cssmap")).thenReturn(mockOutputStream);
    when(mockGeneratorContext.commitResource(testLogger, mockOutputStream)).thenThrow(
        new UnableToCompleteException());

    JMethod method = mock(JMethod.class);
    JClassType bundleType = mock(JClassType.class);
    when(method.getEnclosingType()).thenReturn(bundleType);
    when(bundleType.getQualifiedSourceName()).thenReturn("com.test.Bundle");
    when(method.getName()).thenReturn("cssMethod");

    CssResourceGenerator crg = new CssResourceGenerator();
    crg.outputCssMapArtifact(testLogger, mockResourceContext, method, testMap);

    testLogger.assertCorrectLogEntries();

    verify(mockGeneratorContext).tryCreateResource(testLogger, "cssResource/com.test.Bundle.cssMethod.cssmap");
    verify(mockGeneratorContext).commitResource(testLogger, mockOutputStream);
  }
View Full Code Here

    verify(mockGeneratorContext).tryCreateResource(testLogger, "cssResource/com.test.Bundle.cssMethod.cssmap");
    verify(mockGeneratorContext).commitResource(testLogger, mockOutputStream);
  }

  public void testOutputCssMapArtifactWithTestData() throws UnableToCompleteException {
    UnitTestTreeLogger testLogger = new UnitTestTreeLogger.Builder().createLogger();
    ResourceContext mockResourceContext = mock(ResourceContext.class);
    JMethod mockJMethod1 = mock(JMethod.class);
    JMethod mockJMethod2 = mock(JMethod.class);
    JMethod mockJMethod3 = mock(JMethod.class);
    JClassType mockJClassType1 = mock(JClassType.class);
    JClassType mockJClassType2 = mock(JClassType.class);
    JClassType mockJClassType3 = mock(JClassType.class);
    Map<JMethod, String> testMap = new LinkedHashMap<JMethod, String>();
    testMap.put(mockJMethod1, "TESTCSSNAME1");
    testMap.put(mockJMethod2, "TESTCSSNAME2");
    testMap.put(mockJMethod3, "TESTCSSNAME3");
    ByteArrayOutputStream testOutputStream = new ByteArrayOutputStream();
    GeneratorContext mockGeneratorContext = mock(GeneratorContext.class);
    GeneratedResource mockGeneratedResource = mock(GeneratedResource.class);

    when(mockResourceContext.getGeneratorContext()).thenReturn(mockGeneratorContext);
    when(mockGeneratorContext.tryCreateResource(
        testLogger, "cssResource/com.test.Bundle.cssMethod.cssmap")).thenReturn(testOutputStream);
    when(mockJMethod1.getEnclosingType()).thenReturn(mockJClassType1);
    when(mockJClassType1.getQualifiedSourceName()).thenReturn("test.class.type.1");
    when(mockJMethod1.getName()).thenReturn("basename1");
    when(mockJMethod2.getEnclosingType()).thenReturn(mockJClassType2);
    when(mockJClassType2.getQualifiedSourceName()).thenReturn("test.class.type.2");
    when(mockJMethod2.getName()).thenReturn("basename2");
    when(mockJMethod3.getEnclosingType()).thenReturn(mockJClassType3);
    when(mockJClassType3.getQualifiedSourceName()).thenReturn("test.class.type.3");
    when(mockJMethod3.getName()).thenReturn("basename3");
    when(mockGeneratorContext.commitResource(testLogger, testOutputStream)).thenReturn(
        mockGeneratedResource);

    JMethod method = mock(JMethod.class);
    JClassType bundleType = mock(JClassType.class);
    when(method.getEnclosingType()).thenReturn(bundleType);
    when(bundleType.getQualifiedSourceName()).thenReturn("com.test.Bundle");
    when(method.getName()).thenReturn("cssMethod");

    CssResourceGenerator crg = new CssResourceGenerator();
    crg.outputCssMapArtifact(testLogger, mockResourceContext, method, testMap);
    String expectedOutput = "test-class-type-1-basename1,TESTCSSNAME1\n" +
        "test-class-type-2-basename2,TESTCSSNAME2\n" +
        "test-class-type-3-basename3,TESTCSSNAME3\n";
    assertEquals(expectedOutput, testOutputStream.toString());

    testLogger.assertCorrectLogEntries();

    verify(mockGeneratorContext).tryCreateResource(testLogger, "cssResource/com.test.Bundle.cssMethod.cssmap");
    verify(mockGeneratorContext).commitResource(testLogger, testOutputStream);
  }
View Full Code Here

  public void testResourceNotFoundGivenAnnotation() {
    UnitTestTreeLogger.Builder b = new UnitTestTreeLogger.Builder();
    b.expectError(
        ImageBundleGenerator.msgCannotFindImageFromMetaData("from/metadata/notfound.png"),
        null);
    UnitTestTreeLogger logger = b.createLogger();

    try {
      getImageName(logger, new String[0], "nonexistentImg", "from.metadata",
          getResourceAnnotation("testResourceNotFoundGivenAnnotation"));
      fail("Should have thrown");
    } catch (UnableToCompleteException e) {
    }
    logger.assertCorrectLogEntries();
  }
View Full Code Here

    UnitTestTreeLogger.Builder b = new UnitTestTreeLogger.Builder();
    b.expectError(ImageBundleGenerator.MSG_NO_FILE_BASED_ON_METHOD_NAME, null);
    b.expectError("test/nonexistentImg.png", null);
    b.expectError("test/nonexistentImg.gif", null);
    b.expectError("test/nonexistentImg.jpg", null);
    UnitTestTreeLogger logger = b.createLogger();

    try {
      getImageName(logger, new String[0], "nonexistentImg", "test", null);
      fail("Should have thrown");
    } catch (UnableToCompleteException e) {
    }
    logger.assertCorrectLogEntries();
  }
View Full Code Here

   * residing in the default package.
   */
  public void testResourcesFoundFromImageBundleInDefaultPackage()
      throws UnableToCompleteException {
    UnitTestTreeLogger.Builder b = new UnitTestTreeLogger.Builder();
    UnitTestTreeLogger logger = b.createLogger();

    {
      // [1] Find an image in the default package using the method name.
      String imgName = getImageName(logger, new String[] {
          "cabbage.jpg", "lettuce.jpg",}, "cabbage", "", null);
      assertEquals("cabbage.jpg", imgName);
    }

    {
      // [2] Find an image in the default package using an annotation.
      String imgName = getImageName(logger, new String[] {
          "car.png", "dunebuggy.gif",}, "vehicleImage", "",
          getResourceAnnotation("duneBuggyInDefaultPackage"));
      assertEquals("dunebuggy.gif", imgName);
    }
    {
      // [3] Find an image in a non-default package using an annotation.
      String imgName = getImageName(logger, new String[] {
          "car.png", "dunebuggy.gif", "a/b/c/dunebuggy.gif",}, "vehicleImage",
          "", getResourceAnnotation("duneBuggyInNonDefaultPackage"));
      assertEquals("a/b/c/dunebuggy.gif", imgName);
    }

    logger.assertCorrectLogEntries();
  }
View Full Code Here

TOP

Related Classes of com.google.gwt.dev.util.UnitTestTreeLogger$Builder

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.