Skip to content

Commit 9e1813b

Browse files
author
Julien Kronegg
committed
fix: added cache eviction tests for #2971
1 parent 39169a0 commit 9e1813b

File tree

1 file changed

+89
-0
lines changed

1 file changed

+89
-0
lines changed

cucumber-core/src/test/java/io/cucumber/core/runner/CachingGlueTest.java

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import io.cucumber.core.gherkin.Feature;
1717
import io.cucumber.core.gherkin.Step;
1818
import io.cucumber.core.runtime.TimeServiceEventBus;
19+
import io.cucumber.core.stepexpression.StepTypeRegistry;
1920
import io.cucumber.cucumberexpressions.ParameterByTypeTransformer;
2021
import io.cucumber.cucumberexpressions.ParameterType;
2122
import io.cucumber.datatable.DataTable;
@@ -528,6 +529,94 @@ void parameterTypeDefinition_with_source_reference_emits_parameterType_with_non_
528529
assertNotNull(sourceReference.getJavaStackTraceElement());
529530
}
530531

532+
@Test
533+
void prepareGlue_cache_evicted_when_language_changes() {
534+
// Given
535+
glue.prepareGlue(LANGUAGE);
536+
StepTypeRegistry stepTypeRegistry1 = glue.getStepTypeRegistry();
537+
538+
// When
539+
glue.prepareGlue(Locale.FRENCH);
540+
StepTypeRegistry stepTypeRegistry2 = glue.getStepTypeRegistry();
541+
542+
// Then
543+
assertThat(stepTypeRegistry1!=stepTypeRegistry2, is(true));
544+
}
545+
546+
@Test
547+
void prepareGlue_cache_not_evicted_when_language_remains() {
548+
// Given
549+
glue.prepareGlue(LANGUAGE);
550+
StepTypeRegistry stepTypeRegistry1 = glue.getStepTypeRegistry();
551+
552+
// When
553+
glue.prepareGlue(LANGUAGE);
554+
StepTypeRegistry stepTypeRegistry2 = glue.getStepTypeRegistry();
555+
556+
// Then
557+
assertThat(stepTypeRegistry1==stepTypeRegistry2, is(true));
558+
}
559+
560+
@Test
561+
void prepareGlue_cache_evicted_when_stepDefinition_added() {
562+
// Given
563+
glue.prepareGlue(LANGUAGE);
564+
StepTypeRegistry stepTypeRegistry1 = glue.getStepTypeRegistry();
565+
566+
// When
567+
glue.addStepDefinition(new MockedStepDefinition("mock"));
568+
glue.prepareGlue(LANGUAGE);
569+
StepTypeRegistry stepTypeRegistry2 = glue.getStepTypeRegistry();
570+
571+
// Then
572+
assertThat(stepTypeRegistry1!=stepTypeRegistry2, is(true));
573+
}
574+
575+
@Test
576+
void prepareGlue_cache_evicted_when_parameterType_added() {
577+
// Given
578+
glue.prepareGlue(LANGUAGE);
579+
StepTypeRegistry stepTypeRegistry1 = glue.getStepTypeRegistry();
580+
581+
// When
582+
glue.addParameterType(new MockedParameterTypeDefinition());
583+
glue.prepareGlue(LANGUAGE);
584+
StepTypeRegistry stepTypeRegistry2 = glue.getStepTypeRegistry();
585+
586+
// Then
587+
assertThat(stepTypeRegistry1!=stepTypeRegistry2, is(true));
588+
}
589+
590+
@Test
591+
void prepareGlue_cache_evicted_when_dataTableType_added() {
592+
// Given
593+
glue.prepareGlue(LANGUAGE);
594+
StepTypeRegistry stepTypeRegistry1 = glue.getStepTypeRegistry();
595+
596+
// When
597+
glue.addDataTableType(new MockedDataTableTypeDefinition());
598+
glue.prepareGlue(LANGUAGE);
599+
StepTypeRegistry stepTypeRegistry2 = glue.getStepTypeRegistry();
600+
601+
// Then
602+
assertThat(stepTypeRegistry1!=stepTypeRegistry2, is(true));
603+
}
604+
605+
@Test
606+
void prepareGlue_cache_evicted_when_docString_added() {
607+
// Given
608+
glue.prepareGlue(LANGUAGE);
609+
StepTypeRegistry stepTypeRegistry1 = glue.getStepTypeRegistry();
610+
611+
// When
612+
glue.addDocStringType(new MockedDocStringTypeDefinition());
613+
glue.prepareGlue(LANGUAGE);
614+
StepTypeRegistry stepTypeRegistry2 = glue.getStepTypeRegistry();
615+
616+
// Then
617+
assertThat(stepTypeRegistry1!=stepTypeRegistry2, is(true));
618+
}
619+
531620
private static class MockedScenarioScopedStepDefinition extends StubStepDefinition implements ScenarioScoped {
532621

533622
MockedScenarioScopedStepDefinition(String pattern, Type... types) {

0 commit comments

Comments
 (0)