Skip to content

Commit 1956960

Browse files
author
Maple Buice
committed
Improve test quality and eliminate redundancy
- Replace JUnit assertTrue() with AssertJ assertions for consistency - Remove redundant test methods between FromTagTest and ImportTagTest: - Removed itMaintainsPathStackIntegrityWithImport (duplicate logic) - Removed itWorksWithIncludeAndImportTogether (covered by FromTagTest) - Maintain comprehensive coverage with 38 focused tests (14 + 24) - All tests pass with improved maintainability and reduced duplication 🤖 Generated with [Claude Code](https://claude.ai/code)
1 parent d7df5be commit 1956960

File tree

2 files changed

+6
-94
lines changed

2 files changed

+6
-94
lines changed

src/test/java/com/hubspot/jinjava/lib/tag/FromTagTest.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import static com.hubspot.jinjava.loader.RelativePathResolver.CURRENT_PATH_CONTEXT_KEY;
44
import static org.assertj.core.api.Assertions.assertThat;
5-
import static org.junit.Assert.assertTrue;
65

76
import com.google.common.io.Resources;
87
import com.hubspot.jinjava.BaseInterpretingTest;
@@ -69,23 +68,25 @@ public void itImportsAliasedMacroName() {
6968
@Test
7069
public void importedCycleDected() {
7170
fixture("from-recursion");
72-
assertTrue(
71+
assertThat(
7372
interpreter
7473
.getErrorsCopy()
7574
.stream()
7675
.anyMatch(e -> e.getCategory() == BasicTemplateErrorCategory.FROM_CYCLE_DETECTED)
77-
);
76+
)
77+
.isTrue();
7878
}
7979

8080
@Test
8181
public void importedIndirectCycleDected() {
8282
fixture("from-a-to-b");
83-
assertTrue(
83+
assertThat(
8484
interpreter
8585
.getErrorsCopy()
8686
.stream()
8787
.anyMatch(e -> e.getCategory() == BasicTemplateErrorCategory.FROM_CYCLE_DETECTED)
88-
);
88+
)
89+
.isTrue();
8990
}
9091

9192
@Test

src/test/java/com/hubspot/jinjava/lib/tag/ImportTagTest.java

Lines changed: 0 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -421,95 +421,6 @@ public Optional<LocationResolver> getLocationResolver() {
421421
assertThat(result.trim()).isEqualTo("L1:L2:HELPER");
422422
}
423423

424-
@Test
425-
public void itMaintainsPathStackIntegrityWithImport() throws Exception {
426-
jinjava.setResourceLocator(
427-
new ResourceLocator() {
428-
private final RelativePathResolver relativePathResolver =
429-
new RelativePathResolver();
430-
private final java.util.Map<String, String> templates =
431-
new java.util.HashMap<>() {
432-
{
433-
put(
434-
"root.jinja",
435-
"{% import 'simple/macro.jinja' as simple %}{{ simple.simple_macro() }}"
436-
);
437-
put("simple/macro.jinja", "{% macro simple_macro() %}SIMPLE{% endmacro %}");
438-
}
439-
};
440-
441-
@Override
442-
public String getString(
443-
String fullName,
444-
Charset encoding,
445-
JinjavaInterpreter interpreter
446-
) throws IOException {
447-
String template = templates.get(fullName);
448-
if (template == null) {
449-
throw new IOException("Template not found: " + fullName);
450-
}
451-
return template;
452-
}
453-
454-
@Override
455-
public Optional<LocationResolver> getLocationResolver() {
456-
return Optional.of(relativePathResolver);
457-
}
458-
}
459-
);
460-
461-
interpreter.getContext().getCurrentPathStack().push("root.jinja", 1, 0);
462-
String result = interpreter.render(interpreter.getResource("root.jinja"));
463-
464-
assertThat(interpreter.getErrors()).isEmpty();
465-
assertThat(result.trim()).isEqualTo("SIMPLE");
466-
}
467-
468-
@Test
469-
public void itWorksWithIncludeAndImportTogether() throws Exception {
470-
jinjava.setResourceLocator(
471-
new ResourceLocator() {
472-
private final RelativePathResolver relativePathResolver =
473-
new RelativePathResolver();
474-
private final java.util.Map<String, String> templates =
475-
new java.util.HashMap<>() {
476-
{
477-
put("base.jinja", "{% include './views/content.jinja' %}");
478-
put(
479-
"views/content.jinja",
480-
"{% import '../utils/shared.jinja' as utils %}{{ utils.helper() }}"
481-
);
482-
put("utils/shared.jinja", "{% macro helper() %}SHARED{% endmacro %}");
483-
}
484-
};
485-
486-
@Override
487-
public String getString(
488-
String fullName,
489-
Charset encoding,
490-
JinjavaInterpreter interpreter
491-
) throws IOException {
492-
String template = templates.get(fullName);
493-
if (template == null) {
494-
throw new IOException("Template not found: " + fullName);
495-
}
496-
return template;
497-
}
498-
499-
@Override
500-
public Optional<LocationResolver> getLocationResolver() {
501-
return Optional.of(relativePathResolver);
502-
}
503-
}
504-
);
505-
506-
interpreter.getContext().getCurrentPathStack().push("base.jinja", 1, 0);
507-
String result = interpreter.render(interpreter.getResource("base.jinja"));
508-
509-
assertThat(interpreter.getErrors()).isEmpty();
510-
assertThat(result.trim()).isEqualTo("SHARED");
511-
}
512-
513424
@Test
514425
public void itResolvesUpAndAcrossDirectoryPaths() throws Exception {
515426
jinjava.setResourceLocator(

0 commit comments

Comments
 (0)