Skip to content

Commit

Permalink
Add loaded and unloaded unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Cypress Borg authored and cy-by committed Oct 11, 2023
1 parent 8619f57 commit 79d75fd
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,26 @@

import static org.assertj.core.api.Assertions.assertThat;

import java.util.Objects;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
import org.springframework.boot.autoconfigure.thymeleaf.ThymeleafAutoConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
import org.thymeleaf.TemplateEngine;
import org.junit.jupiter.api.Test;
import org.thymeleaf.templateresolver.ClassLoaderTemplateResolver;

@SpringBootTest(classes = {ThymeleafConfiguration.class}, properties = {"form-flow.design-system.name=cfa-uswds"})
@ImportAutoConfiguration(ThymeleafAutoConfiguration.class)
class ThymeleafConfigurationTest {

@Autowired
private ThymeleafConfiguration thymeleafConfiguration;
@SpringBootTest(classes = {ThymeleafConfiguration.class}, properties = {"form-flow.design-system.name=cfa-uswds"})
public class ThymeleafConfigurationLoadedTest {

@Autowired
private TemplateEngine templateEngine;

@Test
void checkThatUSWDSTemplateResolverIsLoaded() {
System.out.println(templateEngine.getTemplateResolvers());
assertThat(templateEngine.getTemplateResolvers().size()).isEqualTo(2);

assertThat(thymeleafConfiguration).isEqualTo("test");
var uswdsResolver = templateEngine.getTemplateResolvers().stream()
.filter(x -> Objects.equals(x.getName(), "org.thymeleaf.templateresolver.ClassLoaderTemplateResolver")).findFirst();
assertThat(uswdsResolver).isPresent();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package formflow.library.config;

import static org.assertj.core.api.Assertions.assertThat;

import java.util.Objects;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
import org.springframework.boot.autoconfigure.thymeleaf.ThymeleafAutoConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
import org.thymeleaf.TemplateEngine;

@ImportAutoConfiguration(ThymeleafAutoConfiguration.class)
@SpringBootTest(classes = {ThymeleafConfiguration.class}, properties = {"form-flow.design-system.name=honeycrisp"})
public class ThymeleafConfigurationUnloadedTest {

@Autowired
private TemplateEngine templateEngine;

@Test
void checkThatUSWDSTemplateResolverIsLoaded() {
assertThat(templateEngine.getTemplateResolvers().size()).isEqualTo(1);
var uswdsResolver = templateEngine.getTemplateResolvers().stream()
.filter(x -> Objects.equals(x.getName(), "org.thymeleaf.templateresolver.ClassLoaderTemplateResolver")).findFirst();
assertThat(uswdsResolver).isNotPresent();
}
}

0 comments on commit 79d75fd

Please sign in to comment.