How to use format method of com.tngtech.jgiven.junit.test.GivenTestStep class

Best JGiven code snippet using com.tngtech.jgiven.junit.test.GivenTestStep.format

Source:PlainTextReporterTest.java Github

copy

Full Screen

...16import com.tngtech.jgiven.WhenTestStep;17import com.tngtech.jgiven.annotation.*;18import com.tngtech.jgiven.annotation.POJOFormat.BracketsEnum;19import com.tngtech.jgiven.exception.JGivenWrongUsageException;20import com.tngtech.jgiven.format.BooleanFormatter;21import com.tngtech.jgiven.format.PrintfFormatter;22import com.tngtech.jgiven.report.model.StepModel;23/**24 * Please note that we do explicitly <strong>not</strong> use the ScenarioTest class for JUnit,25 * as this would require a dependency to jgiven-junit, which we have to avoid26 * here.27 */28@RunWith(DataProviderRunner.class)29public class PlainTextReporterTest extends ScenarioTestBaseForTesting<GivenTestStep, WhenTestStep, ThenTestStep> {30 @Rule31 public final ExpectedException expected = ExpectedException.none();32 @DataProvider33 public static Object[][] testData() {34 return new Object[][] {35 {5, 6, 30},36 {2, 2, 4},37 {-5, 1, -5},38 };39 }40 @Test41 @UseDataProvider("testData")42 public void parameters_are_reported_correctly(int a, int b, int expectedResult) throws Exception {43 getScenario().startScenario("values can be multiplied");44 given().$d_and_$d(a, b);45 when().both_values_are_multiplied_with_each_other();46 then().the_result_is(expectedResult);47 String string = PlainTextReporter.toString(getScenario().getScenarioModel());48 assertThat(string)49 .contains("Given " + a + " and " + b)50 .contains("When both values are multiplied with each other")51 .contains("Then the result is " + expectedResult);52 }53 @Test54 public void plain_text_report_works_as_expected() throws UnsupportedEncodingException {55 getScenario().startScenario("test");56 given().something()57 .and().something_else();58 when().something_happens();59 then().something_has_happen()60 .but().something_else_not();61 String string = PlainTextReporter.toString(getScenario().getScenarioModel());62 assertThat(string.replaceAll(System.getProperty("line.separator"), "\n"))63 .contains(""64 + " Test\n"65 + "\n"66 + " Given something\n"67 + " And something else\n"68 + " When something happens\n"69 + " Then something has happen\n"70 + " But something else not");71 }72 @Test73 public void sections_are_shown_correctly_in_the_plain_text_report() throws UnsupportedEncodingException {74 getScenario().startScenario("test");75 section("A first section");76 given().something()77 .and().something_else();78 when().something_happens();79 section("Another section");80 then().something_has_happen()81 .but().something_else_not();82 String string = PlainTextReporter.toString(getScenario().getScenarioModel());83 assertThat(string.replaceAll(System.getProperty("line.separator"), "\n"))84 .contains(""85 + " Test\n"86 + "\n"87 + " A first section\n"88 + "\n"89 + " Given something\n"90 + " And something else\n"91 + " When something happens\n"92 + "\n"93 + " Another section\n"94 + "\n"95 + " Then something has happen\n"96 + " But something else not");97 }98 @Test99 public void missing_intro_words_are_filled_with_spaces() throws UnsupportedEncodingException {100 getScenario().startScenario("test");101 given().something()102 .something_else();103 when().something_happens();104 then().something_has_happen()105 .something_else_not();106 String string = PlainTextReporter.toString(getScenario().getScenarioModel());107 assertThat(string.replaceAll(System.getProperty("line.separator"), "\n"))108 .contains(""109 + " Test\n"110 + "\n"111 + " Given something\n"112 + " something else\n"113 + " When something happens\n"114 + " Then something has happen\n"115 + " something else not");116 }117 @Test118 public void nested_steps_are_displayed_in_the_report() throws Throwable {119 getScenario().startScenario("test");120 given().something_with_nested_steps();121 when().something_happens();122 then().something_has_happen()123 .something_else_not();124 String string = PlainTextReporter.toString(getScenario().getScenarioModel());125 assertThat(string.replaceAll(System.getProperty("line.separator"), "\n"))126 .contains(""127 + " Test\n"128 + "\n"129 + " Given something with nested steps\n"130 + " Given something\n"131 + " And something else\n"132 + " When something happens\n"133 + " Then something has happen\n"134 + " something else not");135 StepModel parentStep = getScenario().getScenarioModel().getScenarioCases().get(0).getStep(0);136 long nestedDurations = parentStep.getNestedSteps().get(0).getDurationInNanos()137 + parentStep.getNestedSteps().get(1).getDurationInNanos();138 assertThat(parentStep.getDurationInNanos()).isGreaterThanOrEqualTo(nestedDurations);139 }140 @Test141 public void multilevel_nested_steps_are_displayed_in_the_report() throws UnsupportedEncodingException {142 getScenario().startScenario("test");143 given().something_with_multilevel_nested_steps();144 when().something_happens();145 then().something_has_happen()146 .something_else_not();147 String string = PlainTextReporter.toString(getScenario().getScenarioModel());148 assertThat(string.replaceAll(System.getProperty("line.separator"), "\n"))149 .contains(""150 + " Test\n"151 + "\n"152 + " Given something with multilevel nested steps\n"153 + " Given something with nested steps\n"154 + " Given something\n"155 + " And something else\n"156 + " And something further\n"157 + " When something happens\n"158 + " Then something has happen\n"159 + " something else not");160 }161 @Test162 public void nested_step_failures_appear_in_the_top_level_enclosing_step() throws Throwable {163 getScenario().startScenario("test");164 given().something_with_nested_steps_that_fails();165 when().something_happens();166 then().something_has_happen()167 .something_else_not();168 String string = PlainTextReporter.toString(getScenario().getScenarioModel());169 assertThat(string.replaceAll(System.getProperty("line.separator"), "\n"))170 .contains(""171 + " Test\n"172 + "\n"173 + " Given something with nested steps that fails (failed)\n"174 + " Given something (passed)\n"175 + " And something else that fails (failed)\n"176 + " And something else (skipped)\n"177 + " When something happens (skipped)\n"178 + " Then something has happen (skipped)\n"179 + " something else not (skipped)");180 }181 @Test182 public void parameters_are_correctly_replaced_if_there_is_an_intro_word() throws UnsupportedEncodingException {183 getScenario().startScenario("test");184 GivenTestStep stage = getScenario().addStage(GivenTestStep.class);185 stage.given().a_step_with_a_$_parameter("test");186 String string = PlainTextReporter.toString(getScenario().getScenarioModel());187 assertThat(string).contains("Given a step with a test parameter");188 }189 @Test190 public void parameters_are_correctly_replaced_if_there_is_no_intro_word() throws UnsupportedEncodingException {191 getScenario().startScenario("test");192 GivenTestStep stage = getScenario().addStage(GivenTestStep.class);193 stage.a_step_with_a_$_parameter("test");194 String string = PlainTextReporter.toString(getScenario().getScenarioModel());195 assertThat(string).contains("a step with a test parameter");196 }197 @Test198 public void formatter_are_applied_to_arguments() throws UnsupportedEncodingException {199 getScenario().startScenario("test");200 GivenTestStep stage = getScenario().addStage(GivenTestStep.class);201 stage.a_step_with_a_boolean_$_parameter(true);202 String string = PlainTextReporter.toString(getScenario().getScenarioModel());203 assertThat(string).contains("a step with a boolean yes parameter");204 }205 @Format(value = BooleanFormatter.class, args = {"yes", "no"})206 @Retention(RetentionPolicy.RUNTIME)207 @interface YesNo {208 }209 static class TestCustomer {210 String name;211 /**212 * Field level format annotation chain213 */214 @Formatf(value = "(quoted at POJO field level) %s")215 @Quoted216 String email;217 public TestCustomer(String name, String email) {218 this.name = name;219 this.email = email;220 }221 }222 @Formatf(value = "(quoted by custom format annotation) %s")223 @Quoted224 static @interface CustomFormatAnnotationChain {225 }226 static class FormattedSteps {227 public void yesno_$_formatted(@YesNo boolean b) {228 }229 public void quoted_$_test(@Quoted String s) {230 }231 public void argument_$_multiple_formatters(@Formatf("(%s)") @Quoted @YesNo boolean b) {232 }233 public void argument_$_multiple_wrong_formatters(@YesNo @Formatf("(%s)") @Quoted boolean b) {234 }235 public void pojo_formatter_with_default_field_level_formats_$_test(236 @POJOFormat(fieldSeparator = "|", includeNullColumns = true, prefixWithFieldName = false,237 brackets = BracketsEnum.NONE) TestCustomer c) {238 }239 public void pojo_formatter_with_specific_field_formats_$_test(240 @POJOFormat(fieldSeparator = ", ", includeNullColumns = false, prefixWithFieldName = true, fieldFormats = {241 @NamedFormat(name = "name", format = @Format(value = PrintfFormatter.class, args = "***%s***")),242 @NamedFormat(name = "email", formatAnnotation = CustomFormatAnnotationChain.class)243 }) TestCustomer c) {244 }245 }246 @Test247 public void formatter_annotations_are_applied_to_arguments() throws UnsupportedEncodingException {248 getScenario().startScenario("test");249 FormattedSteps stage = getScenario().addStage(FormattedSteps.class);250 stage.yesno_$_formatted(true);251 String string = PlainTextReporter.toString(getScenario().getScenarioModel());252 assertThat(string).contains("yesno yes formatted");253 }254 @Test255 public void quoted_is_working() throws UnsupportedEncodingException {256 getScenario().startScenario("test");257 FormattedSteps stage = getScenario().addStage(FormattedSteps.class);258 stage.quoted_$_test("foo");259 String string = PlainTextReporter.toString(getScenario().getScenarioModel());260 assertThat(string).contains("quoted \"foo\" test");261 }262 @Test263 public void multiple_formatter_annotations_can_be_specified() throws UnsupportedEncodingException {264 getScenario().startScenario("test");265 FormattedSteps stage = getScenario().addStage(FormattedSteps.class);266 stage.argument_$_multiple_formatters(true);267 String string = PlainTextReporter.toString(getScenario().getScenarioModel());268 assertThat(string).contains("argument (\"yes\") multiple formatters");269 }270 @Test271 public void chained_formatter_annotations_must_apply_to_strings() throws UnsupportedEncodingException {272 getScenario().startScenario("test");273 FormattedSteps stage = getScenario().addStage(FormattedSteps.class);274 expected.expect(JGivenWrongUsageException.class);275 stage.argument_$_multiple_wrong_formatters(true);276 }277 @Test278 public void substeps_access_are_not_printed_in_report() throws UnsupportedEncodingException {279 getScenario().startScenario("substeps");280 given().an_integer_value_set_in_a_substep(4);281 when().something_happens();282 then().the_substep_value_is(4)283 .and().the_substep_value_referred_in_the_step_is(4);284 String string = PlainTextReporter.toString(getScenario().getScenarioModel());285 assertThat(string.replaceAll(System.getProperty("line.separator"), "\n"))286 .contains(287 " Given an integer value set in a substep 4\n"288 + " When something happens\n"289 + " Then the substep value is 4\n"290 + " And the substep value referred in the step is 4");291 }292 @Test293 public void step_comments_are_printed() throws UnsupportedEncodingException {294 getScenario().startScenario("comments");295 given().something().comment("This is a comment.");296 String string = PlainTextReporter.toString(getScenario().getScenarioModel());297 assertThat(string).contains("something [This is a comment.]");298 }299 @Test300 public void varargs_formatting() throws UnsupportedEncodingException {301 getScenario().startScenario("varargs");302 given().varargs_as_parameters_$("a", "b", "c");303 String string = PlainTextReporter.toString(getScenario().getScenarioModel());304 assertThat(string).contains("Given varargs as parameters a, b, c");305 }306 @Test307 public void array_formatting() throws UnsupportedEncodingException {308 getScenario().startScenario("varargs");309 given().arrays_as_parameters(new String[] {"a", "b", "c"});310 String string = PlainTextReporter.toString(getScenario().getScenarioModel());311 assertThat(string).contains("Given arrays as parameters a, b, c");312 assertThat(string).doesNotContain("+");313 assertThat(string).doesNotContain("|");314 }315 @Test316 public void empty_lists() throws UnsupportedEncodingException {317 getScenario().startScenario("empty");318 given().table_as_parameter(new String[] {});319 String string = PlainTextReporter.toString(getScenario().getScenarioModel());320 assertThat(string).contains("Given table as parameter");321 }322 @Test323 public void pojo_format_is_working() throws Throwable {324 getScenario().startScenario("test");325 FormattedSteps stage = getScenario().addStage(FormattedSteps.class);326 String string;327 stage.pojo_formatter_with_default_field_level_formats_$_test(new TestCustomer("John Doe", "john@doe.com"));328 string = PlainTextReporter.toString(getScenario().getScenarioModel());329 assertThat(string)330 .contains(331 "pojo formatter with default field level formats John Doe|(quoted at POJO field level) \"john@doe.com\" test");332 stage.pojo_formatter_with_default_field_level_formats_$_test(new TestCustomer("John Doe", null));333 string = PlainTextReporter.toString(getScenario().getScenarioModel());334 assertThat(string).contains("pojo formatter with default field level formats John Doe|null test");335 stage.pojo_formatter_with_specific_field_formats_$_test(new TestCustomer("John Doe", "john@doe.com"));336 string = PlainTextReporter.toString(getScenario().getScenarioModel());337 assertThat(string)338 .contains(339 "pojo formatter with specific field formats [name=***John Doe***, email=(quoted by custom format annotation) \"john@doe.com\"] test");340 stage.pojo_formatter_with_specific_field_formats_$_test(new TestCustomer("John Doe", null));341 string = PlainTextReporter.toString(getScenario().getScenarioModel());342 assertThat(string).contains("pojo formatter with specific field formats [name=***John Doe***] test");343 }344}...

Full Screen

Full Screen

Source:DataProviderTest.java Github

copy

Full Screen

...4import com.tngtech.java.junit.dataprovider.UseDataProvider;5import com.tngtech.jgiven.annotation.Format;6import com.tngtech.jgiven.annotation.CaseAs;7import com.tngtech.jgiven.annotation.Quoted;8import com.tngtech.jgiven.format.BooleanFormatter;9import com.tngtech.jgiven.junit.test.GivenTestStep;10import com.tngtech.jgiven.junit.test.ThenTestStep;11import com.tngtech.jgiven.junit.test.WhenTestStep;12import com.tngtech.jgiven.report.analysis.CaseArgumentAnalyser;13import com.tngtech.jgiven.report.model.ScenarioCaseModel;14import com.tngtech.jgiven.report.model.ScenarioModel;15import com.tngtech.jgiven.report.model.Word;16import org.junit.Test;17import org.junit.runner.RunWith;18import java.util.List;19import static org.assertj.core.api.Assertions.assertThat;20@RunWith( DataProviderRunner.class )21public class DataProviderTest extends ScenarioTest<GivenTestStep, WhenTestStep, ThenTestStep> {22 @DataProvider23 public static Object[][] dataProvider() {24 return new Object[][] {25 { -2, false, 0 },26 { 22, true, 1 } };27 }28 @Test29 @UseDataProvider( "dataProvider" )30 public void DataProviderRunner_can_be_used( int intArg, boolean booleanArg, int caseNr ) {31 given().some_integer_value( intArg )32 .and().some_boolean_value( booleanArg );33 when().multiply_with_two();34 then().the_value_is_$not_greater_than_zero( booleanArg );35 ScenarioCaseModel scenarioModel = getScenario().getScenarioCaseModel();36 List<String> arguments = scenarioModel.getExplicitArguments();37 assertThat( arguments ).containsExactly( "" + intArg, "" + booleanArg, "" + caseNr );38 }39 @Test40 @DataProvider( { "0", "1" } )41 public void underlines_in_parameters_are_replaced_with_spaces( int int_arg ) {42 given().some_integer_value( int_arg );43 List<String> explicitParameters = getScenario().getScenarioModel().getExplicitParameters();44 assertThat( explicitParameters ).containsExactly( "int arg" );45 }46 @DataProvider47 public static Object[][] trickyData() {48 return new Object[][] {49 { 0, 0, 0 },50 { 0, 1, 0 },51 { 0, 0, 1 },52 };53 }54 @Test55 @UseDataProvider( "trickyData" )56 public void DataProviderRunner_with_tricky_data( int firstArg, int secondArg, int thirdArg ) {57 given().some_integer_value( firstArg )58 .and().another_integer_value( secondArg )59 .and().a_third_integer_value( thirdArg );60 when().multiply_with_two();61 ScenarioModel scenarioModel = getScenario().getScenarioModel();62 if( scenarioModel.getScenarioCases().size() == 3 ) {63 CaseArgumentAnalyser analyser = new CaseArgumentAnalyser();64 analyser.analyze( scenarioModel );65 Word word = scenarioModel.getCase( 0 ).getStep( 0 ).getWord( 2 );66 assertThat( word.isArg() ).isTrue();67 assertThat( word.getArgumentInfo().isParameter() ).isFalse();68 assertParameter( scenarioModel.getCase( 0 ), 1, scenarioModel.getExplicitParameters().get( 1 ) );69 assertParameter( scenarioModel.getCase( 0 ), 2, scenarioModel.getExplicitParameters().get( 2 ) );70 }71 }72 private void assertParameter( ScenarioCaseModel case0, int step, String parameter ) {73 Word word = case0.getStep( step ).getWords().get( 2 );74 assertThat( word.getArgumentInfo().getParameterName() ).isEqualTo( parameter );75 }76 @Test77 @DataProvider( { "1", "2", "3" } )78 public void derived_parameters_work( Integer arg ) {79 given().some_integer_value( arg )80 .and().another_integer_value( arg * 10 );81 when().multiply_with_two();82 ScenarioModel scenarioModel = getScenario().getScenarioModel();83 if( scenarioModel.getScenarioCases().size() == 3 ) {84 CaseArgumentAnalyser analyser = new CaseArgumentAnalyser();85 analyser.analyze( scenarioModel );86 ScenarioCaseModel case0 = scenarioModel.getCase( 0 );87 assertParameter( case0, 0, scenarioModel.getExplicitParameters().get( 0 ) );88 assertParameter( case0, 1, "secondArg" );89 }90 }91 @Test92 @DataProvider( { "1", "2" } )93 public void arguments_with_the_same_name_but_different_values_are_handled_correctly( Integer arg ) throws Throwable {94 given().some_integer_value( arg + 1 )95 .and().some_integer_value( arg + 2 );96 getScenario().finished();97 ScenarioModel scenarioModel = getScenario().getModel().getLastScenarioModel();98 if( scenarioModel.getScenarioCases().size() == 2 ) {99 CaseArgumentAnalyser analyser = new CaseArgumentAnalyser();100 analyser.analyze( scenarioModel );101 ScenarioCaseModel case0 = scenarioModel.getCase( 0 );102 assertParameter( case0, 0, "someIntValue" );103 assertParameter( case0, 1, "someIntValue2" );104 }105 }106 @Test107 @DataProvider( { "1", "2" } )108 public void differences_in_nested_steps_should_be_detected( Integer methodParameter ) throws Throwable {109 given().a_nested_step( methodParameter + 1 );110 getScenario().finished();111 ScenarioModel scenarioModel = getScenario().getModel().getLastScenarioModel();112 if( scenarioModel.getScenarioCases().size() == 2 ) {113 CaseArgumentAnalyser analyser = new CaseArgumentAnalyser();114 analyser.analyze( scenarioModel );115 ScenarioCaseModel case0 = scenarioModel.getCase( 0 );116 assertParameter( case0, 0, "nestedStepArg" );117 Word word = case0.getStep( 0 ).getNestedSteps().get( 0 ).getWords().get( 1 );118 assertThat( word.getArgumentInfo().getParameterName() ).isEqualTo( "someIntValue" );119 }120 }121 @Test122 @DataProvider( { "1", "2" } )123 public void table_parameters_work_with_primitive_arrays( Integer arg ) {124 given().a_step_with_a_table_parameter_and_primitive_array( 1, 2, 3 );125 }126 @Test127 @DataProvider( { "true", "false" } )128 public void parameters_of_methods_can_be_formatted( @Format( value = BooleanFormatter.class, args = { "foo", "bar" } ) boolean b )129 throws Throwable {130 given().some_boolean_value( b );131 if( b ) {132 when().something();133 }134 getScenario().finished();135 List<ScenarioCaseModel> cases = getScenario().getModel().getLastScenarioModel().getScenarioCases();136 assertThat( cases.get( cases.size() - 1 ).getExplicitArguments() ).containsExactly( b ? "foo" : "bar" );137 }138 @Test139 @DataProvider( { "the first case, true", "the second case, false" } )140 @CaseAs( "$1" )141 public void parameters_can_be_treated_as_case_description( String description, boolean b ) throws Throwable {142 given().something();143 getScenario().finished();144 List<ScenarioCaseModel> cases = getScenario().getModel().getLastScenarioModel().getScenarioCases();145 assertThat( cases.get( cases.size() - 1 ).getDescription() ).isEqualTo( description );146 }147 @Test148 @DataProvider( { "0", "1" } )149 public void duration_of_multiple_cases_is_summed_up( int nr ) throws Throwable {150 given().something();151 getScenario().finished();152 if( nr == 0 ) {153 getScenario().getModel().getLastScenarioModel().setDurationInNanos( 0 );154 } else {155 assertThat( getScenario().getModel().getLastScenarioModel().getDurationInNanos() ).isNotEqualTo( 0 );156 }157 }158 @Test159 @DataProvider( {160 "foo",161 "bar"162 } )163 public void two_identically_formatted_arguments_should_be_unified_in_one_parameter( @Quoted String arg ) throws Throwable {164 given().some_quoted_string_value( arg )165 .and().another_quoted_string_value( arg );166 getScenario().finished();167 ScenarioModel scenarioModel = getScenario().getModel().getLastScenarioModel();168 if( scenarioModel.getScenarioCases().size() == 2 ) {169 CaseArgumentAnalyser analyser = new CaseArgumentAnalyser();170 analyser.analyze( scenarioModel );171 assertThat( scenarioModel.getDerivedParameters() ).hasSize( 1 );172 assertThat( scenarioModel.getDerivedParameters().get( 0 ) ).isEqualTo( "arg" );173 }174 }175 @Test176 @DataProvider( {177 "foo",178 "bar"179 } )180 public void two_differently_formatted_arguments_but_with_the_same_value_should_become_two_parameters( String param ) throws Throwable {181 given().some_quoted_string_value( param )182 .and().some_string_value( param );183 getScenario().finished();184 ScenarioModel scenarioModel = getScenario().getModel().getLastScenarioModel();185 if( scenarioModel.getScenarioCases().size() == 2 ) {186 CaseArgumentAnalyser analyser = new CaseArgumentAnalyser();187 analyser.analyze( scenarioModel );188 assertThat( scenarioModel.getDerivedParameters() ).containsExactly( "someQuotedStringValue", "someStringValue" );189 }190 }191 @Test192 @DataProvider( {193 "foo",194 "bar"...

Full Screen

Full Screen

Source:GivenTestStep.java Github

copy

Full Screen

...13import com.tngtech.jgiven.annotation.ProvidedScenarioState;14import com.tngtech.jgiven.annotation.Quoted;15import com.tngtech.jgiven.annotation.Table;16import com.tngtech.jgiven.config.FormatterConfiguration;17import com.tngtech.jgiven.format.BooleanFormatter;18import com.tngtech.jgiven.format.ObjectFormatter;19import com.tngtech.jgiven.format.table.TableFormatter;20import com.tngtech.jgiven.format.table.TableFormatterFactory;21import com.tngtech.jgiven.report.model.DataTable;22public class GivenTestStep extends Stage<GivenTestStep> {23 @ProvidedScenarioState24 int value1;25 @ProvidedScenarioState26 int value2;27 public GivenTestStep some_integer_value( int someIntValue ) {28 this.value1 = someIntValue;29 return self();30 }31 public void some_boolean_value( boolean someBooleanValue ) {32 }33 @NestedSteps34 public void a_nested_step(Integer nestedStepArg) {35 some_integer_value(nestedStepArg+1);36 }37 @IsTag38 @Retention( RetentionPolicy.RUNTIME )39 @interface StepMethodTag {}40 @StepMethodTag41 public void a_tagged_step_method() {}42 public void $d_and_$d( int value1, int value2 ) {43 this.value1 = value1;44 this.value2 = value2;45 }46 public GivenTestStep another_integer_value( int secondArg ) {47 value2 = secondArg;48 return self();49 }50 public void a_third_integer_value( int thirdArg ) {}51 public void something() {52 }53 public void a_step_with_a_table_parameter_and_primitive_array( @Table int... args ) {}54 @Table(columnTitles = { "custom" })55 @Retention( RetentionPolicy.RUNTIME )56 @interface CustomTable {}57 public void a_list_of_Strings_with_a_meta_table_annotation(@CustomTable int... values) {}58 public GivenTestStep some_quoted_string_value( @Quoted String someQuotedStringValue ) {59 return self();60 }61 public GivenTestStep some_string_value( String someStringValue ) {62 return self();63 }64 public void another_quoted_string_value( @Quoted String anotherQuotedStringValue ) { }65 public static class TableClass {66 public String value;67 }68 public void some_data_table( @Table TableClass... param ) { }69 public static class TestTableEntry {70 int some_field = 1;71 }72 public static class CoffeePrice {73 String name;74 double price_in_EUR;75 public CoffeePrice( String name, double priceInEur ) {76 this.name = name;77 this.price_in_EUR = priceInEur;78 }79 }80 public GivenTestStep the_following_data( @Table CoffeePrice... data ) {81 return this;82 }83 public GivenTestStep a_list_of_booleans( @Table @Format( value = BooleanFormatter.class, args = { "on", "off" } ) List<Boolean> booleans ) {84 return this;85 }86 public GivenTestStep a_list_of_booleans_without_header( @Table( header = Table.HeaderType.NONE ) @Format(87 value = BooleanFormatter.class, args = { "on", "off" } ) List<Boolean> booleans ) {88 return this;89 }90 public static class TestTableFormatter implements TableFormatter {91 @Override92 public DataTable format( Object tableArgument, Table tableAnnotation, String parameterName, Annotation... allAnnotations ) {93 List<List<String>> data = Lists.newArrayList();94 CoffeePrice[] castedTableArgument = (CoffeePrice[]) tableArgument;95 data.add( Lists.newArrayList( parameterName ) );96 for( CoffeePrice price : castedTableArgument ) {97 data.add( Lists.newArrayList( price.name + ": " + price.price_in_EUR ) );98 }99 return new DataTable( Table.HeaderType.HORIZONTAL, data );100 }101 public static class Factory implements TableFormatterFactory {102 @Override103 public TableFormatter create( FormatterConfiguration formatterConfiguration, ObjectFormatter<?> objectFormatter ) {104 return new TestTableFormatter();105 }106 }107 }108 public GivenTestStep a_list_of_PoJos_with_custom_table_formatter(109 @Table( formatter = TestTableFormatter.Factory.class ) CoffeePrice... coffeePrices ) {110 return this;111 }112}...

Full Screen

Full Screen

format

Using AI Code Generation

copy

Full Screen

1import com.tngtech.jgiven.junit.test.GivenTestStep;2import com.tngtech.jgiven.junit.test.ThenTestStep;3import com.tngtech.jgiven.junit.test.WhenTestStep;4import org.junit.Test;5public class TestStepTest {6 public void testStep() {7 GivenTestStep given = new GivenTestStep();8 WhenTestStep when = new WhenTestStep();9 ThenTestStep then = new ThenTestStep();10 given.a_test_step();11 when.a_test_step();12 then.a_test_step();13 }14}15import com.tngtech.jgiven.junit.test.GivenTestStep;16import com.tngtech.jgiven.junit.test.ThenTestStep;17import com.tngtech.jgiven.junit.test.WhenTestStep;18import org.junit.Test;19public class TestStepTest {20 public void testStep() {21 GivenTestStep given = new GivenTestStep();22 WhenTestStep when = new WhenTestStep();23 ThenTestStep then = new ThenTestStep();24 given.a_test_step();25 when.a_test_step();26 then.a_test_step();27 }28}29import com.tngtech.jgiven.junit.test.GivenTestStep;30import com.tngtech.jgiven.junit.test.ThenTestStep;31import com.tngtech.jgiven.junit.test.WhenTestStep;32import org.junit.Test;33public class TestStepTest {34 public void testStep() {35 GivenTestStep given = new GivenTestStep();36 WhenTestStep when = new WhenTestStep();37 ThenTestStep then = new ThenTestStep();38 given.a_test_step();39 when.a_test_step();40 then.a_test_step();41 }42}43import com.tngtech.jgiven.junit.test.GivenTestStep;44import com.tngtech.jgiven.junit.test.ThenTestStep;45import com.tngtech.jgiven.junit.test.WhenTestStep;46import org.junit.Test;47public class TestStepTest {48 public void testStep() {

Full Screen

Full Screen

format

Using AI Code Generation

copy

Full Screen

1package com.tngtech.jgiven.junit.test;2import org.junit.Test;3import com.tngtech.jgiven.junit.ScenarioTest;4public class GivenTestStepTest extends ScenarioTest<GivenTestStep, WhenTestStep, ThenTestStep> {5 public void test() {6 given().a_$_given_step( "given" );7 when().a_$_when_step( "when" );8 then().a_$_then_step( "then" );9 }10}11package com.tngtech.jgiven.junit.test;12import org.junit.Test;13import com.tngtech.jgiven.junit.ScenarioTest;14public class WhenTestStepTest extends ScenarioTest<GivenTestStep, WhenTestStep, ThenTestStep> {15 public void test() {16 given().a_$_given_step( "given" );17 when().a_$_when_step( "when" );18 then().a_$_then_step( "then" );19 }20}21package com.tngtech.jgiven.junit.test;22import org.junit.Test;23import com.tngtech.jgiven.junit.ScenarioTest;24public class ThenTestStepTest extends ScenarioTest<GivenTestStep, WhenTestStep, ThenTestStep> {25 public void test() {26 given().a_$_given_step( "given" );27 when().a_$_when_step( "when" );28 then().a_$_then_step( "then" );29 }30}31package com.tngtech.jgiven.junit.test;32import org.junit.Test;33import com.tngtech.jgiven.junit.ScenarioTest;34public class GivenTestStepTest extends ScenarioTest<GivenTestStep, WhenTestStep, ThenTestStep> {35 public void test() {36 given().a_$_given_step( "given" );37 when().a_$_when_step( "when" );38 then().a_$_then_step( "then" );39 }40}

Full Screen

Full Screen

format

Using AI Code Generation

copy

Full Screen

1package com.tngtech.jgiven.junit.test;2import com.tngtech.jgiven.junit.ScenarioTest;3import com.tngtech.jgiven.tags.FeatureFormat;4import org.junit.Test;5import org.junit.experimental.categories.Category;6@Category(FeatureFormat.class)7public class FormatTest extends ScenarioTest<GivenTestStep, WhenTestStep, ThenTestStep> {8 public void test_format_method() {9 given().a_$_with_$_and_$("test", 1, 2);10 when().format_method_is_called();11 then().the_result_is("a test with 1 and 2");12 }13}14package com.tngtech.jgiven.junit.test;15import com.tngtech.jgiven.Stage;16public class GivenTestStep extends Stage<GivenTestStep> {17 String value1;18 int value2;19 int value3;20 public GivenTestStep a_$_with_$_and_$ (String value1, int value2, int value3) {21 this.value1 = value1;22 this.value2 = value2;23 this.value3 = value3;24 return self();25 }26}27package com.tngtech.jgiven.junit.test;28import com.tngtech.jgiven.Stage;29public class WhenTestStep extends Stage<WhenTestStep> {30 String value1;31 int value2;32 int value3;33 public WhenTestStep format_method_is_called() {34 value1 = "a " + value1 + " with " + value2 + " and " + value3;35 return self();36 }37}38package com.tngtech.jgiven.junit.test;39import com.tngtech.jgiven.Stage;40public class ThenTestStep extends Stage<ThenTestStep> {41 String value1;42 int value2;43 int value3;44 public ThenTestStep the_result_is(String result) {45 assertEquals(result, value1);46 return self();47 }48}49package com.tngtech.jgiven.junit.test;50import com.tngtech.jgiven.annotation.ExpectedScenarioState;51import com.tngtech.jgiven.junit.ScenarioTest;52import org.junit.Test;53public class FormatTest extends ScenarioTest<GivenTestStep, WhenTestStep, ThenTestStep> {54 public void test_format_method() {

Full Screen

Full Screen

format

Using AI Code Generation

copy

Full Screen

1package com.tngtech.jgiven.junit.test;2import com.tngtech.jgiven.junit.SimpleScenarioTest;3import org.junit.Test;4public class GivenTestStepTest extends SimpleScenarioTest<GivenTestStepTest.GivenTestStep, GivenTestStepTest.WhenTestStep, GivenTestStepTest.ThenTestStep> {5 public void test() {6 given().a_test_step_with_$_format_parameter("test");7 when().a_test_step_with_$_format_parameter("test");8 then().a_test_step_with_$_format_parameter("test");9 }10 public static class GivenTestStep extends com.tngtech.jgiven.junit.test.GivenTestStep<GivenTestStepTest.GivenTestStep, GivenTestStepTest.WhenTestStep, GivenTestStepTest.ThenTestStep> {11 }12 public static class WhenTestStep extends com.tngtech.jgiven.junit.test.WhenTestStep<GivenTestStepTest.GivenTestStep, GivenTestStepTest.WhenTestStep, GivenTestStepTest.ThenTestStep> {13 }14 public static class ThenTestStep extends com.tngtech.jgiven.junit.test.ThenTestStep<GivenTestStepTest.GivenTestStep, GivenTestStepTest.WhenTestStep, GivenTestStepTest.ThenTestStep> {15 }16}17package com.tngtech.jgiven.junit.test;18import com.tngtech.jgiven.annotation.Format;19import com.tngtech.jgiven.annotation.FormatType;20import com.tngtech.jgiven.annotation.ScenarioState;21import com.tngtech.jgiven.format.ArgumentFormatter;22import com.tngtech.jgiven.format.StringFormatter;23import com.tngtech.jgiven.impl.util.AnnotationUtil;24import com.tngtech.jgiven.impl.util.ReflectionUtil;25import com.tngtech.jgiven.impl.util.WordUtil;26import com.tngtech.jgiven.report.model.*;27import com.tngtech.jgiven.report.model.ObjectFormatter;28import com.tngtech.jgiven.report.model.ValueFormatter;29import com.tngtech.jgiven.report.text.TextFormatter;30import com.tngtech.jgiven.report.text.TextFormatter.FormattingContext;31import com.tngtech.jgiven.report.text.TextFormatter.FormattingContext.FormattingContextBuilder;32import com.tngtech.jgiven.report.text.TextFormatter.FormattingContext.FormattingContextBuilder.FormattingContextBuilderState;33import com.tngtech.jgiven.report.text.TextFormatter.FormattingContext.FormattingContextBuilder.FormattingContextBuilderState.FormattingContextBuilderStateBuilder;34import com.tngtech

Full Screen

Full Screen

format

Using AI Code Generation

copy

Full Screen

1GivenTestStep givenTestStep = new GivenTestStep();2givenTestStep.format("Hello %s", "World");3WhenTestStep whenTestStep = new WhenTestStep();4whenTestStep.format("Hello %s", "World");5ThenTestStep thenTestStep = new ThenTestStep();6thenTestStep.format("Hello %s", "World");7AndTestStep andTestStep = new AndTestStep();8andTestStep.format("Hello %s", "World");9ButTestStep butTestStep = new ButTestStep();10butTestStep.format("Hello %s", "World");11ThenTestStep thenTestStep = new ThenTestStep();12thenTestStep.format("Hello %s", "World");

Full Screen

Full Screen

format

Using AI Code Generation

copy

Full Screen

1import com.tngtech.jgiven.junit.test.GivenTestStep;2import org.junit.Test;3public class TestStepTest {4 public void test() {5 GivenTestStep testStep = new GivenTestStep();6 testStep.a_$_b_$_c("a", "b", "c");7 }8}9import com.tngtech.jgiven.junit.test.GivenTestStep;10import org.junit.Test;11public class TestStepTest {12 public void test() {13 GivenTestStep testStep = new GivenTestStep();14 testStep.a_$_b_$_c("a", "b", "c");15 }16}17import com.tngtech.jgiven.junit.test.GivenTestStep;18import org.junit.Test;19public class TestStepTest {20 public void test() {21 GivenTestStep testStep = new GivenTestStep();22 testStep.a_$_b_$_c("a", "b", "c");23 }24}25import com.tngtech.jgiven.junit.test.GivenTestStep;26import org.junit.Test;27public class TestStepTest {28 public void test() {29 GivenTestStep testStep = new GivenTestStep();30 testStep.a_$_b_$_c("a", "b", "c");31 }32}33import com.tngtech.jgiven.junit.test.GivenTestStep;34import org.junit.Test;35public class TestStepTest {36 public void test() {37 GivenTestStep testStep = new GivenTestStep();38 testStep.a_$_b_$_c("a", "b", "c");39 }40}41import com.tngtech.jgiven.junit.test.GivenTestStep;42import org.junit.Test;

Full Screen

Full Screen

format

Using AI Code Generation

copy

Full Screen

1import com.tngtech.jgiven.junit.test.GivenTestStep;2import org.junit.Test;3public class JGivenTest {4 public void testFormat() {5 GivenTestStep testStep = new GivenTestStep();6 String formattedString = testStep.format("Hello %s", "World");7 System.out.println(formattedString);8 }9}

Full Screen

Full Screen

format

Using AI Code Generation

copy

Full Screen

1package com.tngtech.jgiven.junit.test;2import org.junit.Test;3public class Test1 {4public void test1() {5GivenTestStep given = new GivenTestStep();6given.a_test_step();7}8}9package com.tngtech.jgiven.junit.test;10import org.junit.Test;11public class Test2 {12public void test2() {13GivenTestStep given = new GivenTestStep();14given.a_test_step();15}16}17package com.tngtech.jgiven.junit.test;18import org.junit.Test;19public class Test3 {20public void test3() {21GivenTestStep given = new GivenTestStep();22given.a_test_step();23}24}25package com.tngtech.jgiven.junit.test;26import org.junit.Test;27public class Test4 {28public void test4() {29GivenTestStep given = new GivenTestStep();30given.a_test_step();31}32}33package com.tngtech.jgiven.junit.test;34import org.junit.Test;35public class Test5 {36public void test5() {37GivenTestStep given = new GivenTestStep();38given.a_test_step();39}40}41package com.tngtech.jgiven.junit.test;42import org.junit.Test;43public class Test6 {44public void test6() {45GivenTestStep given = new GivenTestStep();46given.a_test_step();47}48}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful