コード例 #1
0
  @Test
  public void getContentWhenException() throws Exception {
    LESSSkinFileResourceReference lessSkinFileResourceReference =
        new LESSSkinFileResourceReference("file.less", templateManager, skinManager);

    // Mocks
    Template template = mock(Template.class);
    when(templateManager.getTemplate("less/file.less", skin)).thenReturn(template);
    Exception exception = new Exception("exception");
    when(template.getContent()).thenThrow(exception);

    // Test
    LESSCompilerException caughtException = null;
    try {
      lessSkinFileResourceReference.getContent("skin");
    } catch (LESSCompilerException e) {
      caughtException = e;
    }

    // Verify
    assertNotNull(caughtException);
    assertEquals(
        "Failed to get the content of the template [file.less].", caughtException.getMessage());
    assertEquals(exception, caughtException.getCause());
  }
コード例 #2
0
  @Test
  public void getContent() throws Exception {
    LESSSkinFileResourceReference lessSkinFileResourceReference =
        new LESSSkinFileResourceReference("style.less", templateManager, skinManager);

    // Mocks
    Template template = mock(Template.class);
    when(templateManager.getTemplate("less/style.less", skin)).thenReturn(template);
    TemplateContent templateContent = mock(TemplateContent.class);
    when(template.getContent()).thenReturn(templateContent);
    when(templateContent.getContent()).thenReturn("// My LESS file");

    // Test
    assertEquals("// My LESS file", lessSkinFileResourceReference.getContent("skin"));
  }