From 988527fae700a32d63f9d336377a3158e861fbd4 Mon Sep 17 00:00:00 2001 From: samr Date: Mon, 15 May 2023 22:54:46 +0000 Subject: [PATCH 1/6] impl.Main --- .../packagenamingpackage/impl/Main.java | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/Main.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/Main.java index 22409508..03fd77a7 100644 --- a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/Main.java +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/Main.java @@ -1,9 +1,19 @@ +// Main.java +// Main + +// import package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl; +// import package org.springframework.context.ApplicationContext +// import package org.springframework.context.ConfigurableApplicationContext +// import package org.springframework.context.support.ClassPathXmlApplicationContext import org.springframework.context.ApplicationContext; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; +// import package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.parameters.DefaultFizzBuzzUpperLimitParameter +// import package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.FizzBuzz +// import package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.parameters.FizzBuzzUpperLimitParameter import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.parameters.DefaultFizzBuzzUpperLimitParameter; import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.FizzBuzz; import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.parameters.FizzBuzzUpperLimitParameter; @@ -14,16 +24,20 @@ public final class Main { /** + * the main function to the class Main declared in com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl; the starting point to the application * @param args */ public static void main(final String[] args) { + // create an object off of ClassPathXmlApplicationContent imported from org.springframework.context.support.ClassPathXmlApplicationContent on line 12 called context of type ApplicationContext, passing in Constants.SPRING_XML final ApplicationContext context = new ClassPathXmlApplicationContext(Constants.SPRING_XML); + // create an object called myFizzBuzz of type FizzBuzz by calling method getBean from context declared on line 31 and passing in Contants.STANDARD_FIZZ_BUZZ final FizzBuzz myFizzBuzz = (FizzBuzz) context.getBean(Constants.STANDARD_FIZZ_BUZZ); + // create an object of type FizzBuzzUpperLimitParamater imported from com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.parameters.FizzBuzzUpperLimitParameter on line 19, using class DefaultFizzBuzzUpperLimit imported from com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.parameters.DefaultFizzBuzzUpperLimitParameter on line 17 final FizzBuzzUpperLimitParameter fizzBuzzUpperLimit = new DefaultFizzBuzzUpperLimitParameter(); + // call method fizzBuzz on constant myFizzBuzz declared on line 33 myFizzBuzz.fizzBuzz(fizzBuzzUpperLimit.obtainUpperLimitValue()); + // call method close on context declared on line 31 casted to ConfigurableApplicationContext imported from org.springframework.context.ConfigurableApplicationContect on line 11 ((ConfigurableApplicationContext) context).close(); - } - } From 435bb24c4aca35ea99e3828dc67c3e99a1a06462 Mon Sep 17 00:00:00 2001 From: samr Date: Mon, 15 May 2023 23:10:47 +0000 Subject: [PATCH 2/6] impl.StandardFizzBuzz + additions to impl.Main --- .../packagenamingpackage/impl/Main.java | 4 ++-- .../impl/StandardFizzBuzz.java | 18 ++++++++++++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/Main.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/Main.java index 03fd77a7..cd4d472f 100644 --- a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/Main.java +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/Main.java @@ -1,7 +1,7 @@ // Main.java // Main -// import package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl +// add this specific class (Main) to the package named com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl; // import package org.springframework.context.ApplicationContext @@ -25,7 +25,7 @@ public final class Main { /** * the main function to the class Main declared in com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl; the starting point to the application - * @param args + * @param args The command line arguments passed in from the command line, which are used to change the end effects of the program if used as a Command Line Interface, or CLI, tool. This is declared as `final`, which is a keyword used in Java to declare any variable as a constant, meaning that it cannot be changed after declaration. This specfic program does not use this argument, as this is just an Enterprise Quality(TM) FizzBuzz program which does not need any arguments passed in on execution, but other projects which are less Enterprise Quality(TM) have used it. */ public static void main(final String[] args) { // create an object off of ClassPathXmlApplicationContent imported from org.springframework.context.support.ClassPathXmlApplicationContent on line 12 called context of type ApplicationContext, passing in Constants.SPRING_XML diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/StandardFizzBuzz.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/StandardFizzBuzz.java index acc15f54..af636109 100644 --- a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/StandardFizzBuzz.java +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/StandardFizzBuzz.java @@ -1,10 +1,19 @@ +// StandardFizzBuzz.java +// Standard FizzBuzz + +// add this specific class (StandardFizzBuzz) to the package named com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl; +// import package org.springframework.beans.factory.annotation.Autowired import org.springframework.beans.factory.annotation.Autowired; +// import package org.springframework.stereotype.Service import org.springframework.stereotype.Service; +// import package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.FizzBuzz import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.FizzBuzz; +// import package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.factories.FizzBuzzSolutionStrategyFactory import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.factories.FizzBuzzSolutionStrategyFactory; +// import package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.strategies.FizzBuzzSolutionStrategy import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.strategies.FizzBuzzSolutionStrategy; /** @@ -12,25 +21,30 @@ */ @Service public class StandardFizzBuzz implements FizzBuzz { - + // create a private contstant called _fizzBuzzSolutionStrategyFactory of type FizzBuzzSolutionStrategyFactory imported from com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.factories.FizzBuzzSolutionStrategyFactory on line 15 private final FizzBuzzSolutionStrategyFactory _fizzBuzzSolutionStrategyFactory; /** + * the constructor for the class StandardFizzBuzz declared on line 23 * @param _fizzBuzzSolutionStrategyFactory */ @Autowired public StandardFizzBuzz(final FizzBuzzSolutionStrategyFactory _fizzBuzzSolutionStrategyFactory) { + // call the constructor of the class StandardFizzBuzz declared on line 13 super(); + // set the value of the constant _fizzBuzzSolutionStrategyFactory, a property on the current object declared on line 25, to the value of _fizzBuzzSolutionStrategyFactory, the parameter to the constructor of StandardFizzBuzz declared on line 23, declared on line 32 this._fizzBuzzSolutionStrategyFactory = _fizzBuzzSolutionStrategyFactory; } /** + * the method fizzBuzz on the class StandardFizzBuzz declared on line 23 * @param nFizzBuzzUpperLimit */ public void fizzBuzz(final int nFizzBuzzUpperLimit) { + // a constant called mySolutionStrategy of type FizzBuzzSolutionStrategy imported from com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.strategies.FizzBuzzSolutionStrategy on line 17, which is set to the return value of the method createFizzBuzzSolutionStrategy on the property _fizzBuzzSolutionStrategy of this object declared on line 25 final FizzBuzzSolutionStrategy mySolutionStrategy = this._fizzBuzzSolutionStrategyFactory.createFizzBuzzSolutionStrategy(); + // run the method runSolution on the object mySolutionStrategy declared on lines 45-46 of type FizzBuzzSolutionStrategy and pass in the parameter to this function called nFizzBuzzUpperLimit of type int mySolutionStrategy.runSolution(nFizzBuzzUpperLimit); } - } From 0d3d17893d5ab6e58472d03d345f4a1f96ce1f58 Mon Sep 17 00:00:00 2001 From: samr Date: Mon, 15 May 2023 23:17:21 +0000 Subject: [PATCH 3/6] impl.Constants --- .../packagenamingpackage/impl/Constants.java | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/Constants.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/Constants.java index f351e327..5b73f056 100644 --- a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/Constants.java +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/Constants.java @@ -1,23 +1,39 @@ +// Constants.java +// Constants + +// add this specific class (Constants) to the package named com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl; /** * Constants */ public class Constants { - + // a public, static constant property of the class Constants defined on line 10 of type string called AN_ATTEMPT_WAS_MADE_TO_DIVIDE_BY_ZERO which contains the text "An attempt was made to divide by zero." public static final String AN_ATTEMPT_WAS_MADE_TO_DIVIDE_BY_ZERO = "An attempt was made to divide by zero."; + // a public, static constant property of the class Constants defined on line 10 of type string called BUZZ which contains the text "Buzz" public static final String BUZZ = "Buzz"; + // a public, static constant property of the class Constants defined on line 10 of type string called COM_SERIOUSCOMPANY_BUSINESS_JAVA_FIZZBUZZ_PACKAGENAMINGPACKAGE_IMPL_PRINTERS_INTEGER_INTEGER_PRINTER_PRINT which contains the text "com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.printers.IntegerIntegerPrinter.print()" public static final String COM_SERIOUSCOMPANY_BUSINESS_JAVA_FIZZBUZZ_PACKAGENAMINGPACKAGE_IMPL_PRINTERS_INTEGER_INTEGER_PRINTER_PRINT = "com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.printers.IntegerIntegerPrinter.print()"; + // a public, static constant property of the class Constants defined on line 10 of type string called FIZZ which contains the text "Fizz" public static final String FIZZ = "Fizz"; + // a public, static constant property of the class Constants defined on line 10 of type string called LINE_SEPARATOR which contains the text "line.separator" public static final String LINE_SEPARATOR = "line.separator"; + // a public, static constant property of the class Constants defined on line 10 of type string called LOOP_COMPONENT_FACTORY which contains the text "loopComponentFactory" public static final String LOOP_COMPONENT_FACTORY = "loopComponentFactory"; + // a public, static constant property of the class Constants defined on line 10 of type string called SPRING_XML which contains the text "spring.xml" public static final String SPRING_XML = "spring.xml"; + // a public, static constant property of the class Constants defined on line 10 of type string called STANDARD_FIZZ_BUZZ which contains the text "standardFizzBuzz" public static final String STANDARD_FIZZ_BUZZ = "standardFizzBuzz"; + // a public, static constant property of the class Constants defined on line 10 of type string called THE_INTEGERS_COULD_NOT_BE_COMPARED which contains the text "The integers could not be compared." public static final String THE_INTEGERS_COULD_NOT_BE_COMPARED = "The integers could not be compared."; + // a public, static constant property of the class Constants defined on line 10 of type int called DEFAULT_FIZZ_BUZZ_UPPER_LIMIT_PARAMETER_VALUE which contains the number 100 public static final int DEFAULT_FIZZ_BUZZ_UPPER_LIMIT_PARAMETER_VALUE = 100; + // a public, static constant property of the class Constants defined on line 10 of type int called INTEGER_DIVIDE_ZERO_VALUE which contains the number 0 public static final int INTEGER_DIVIDE_ZERO_VALUE = 0; + // a public, static constant property of the class Constants defined on line 10 of type int called INTEGER_ORIGIN_ZERO_VALUE which contains the number 0 public static final int INTEGER_ORIGIN_ZERO_VALUE = 0; + // a public, static constant property of the class Constants defined on line 10 of type int called LOOP_INC_VALUE which contains the number 1 public static final int LOOP_INC_VALUE = 1; + // a public, static constant property of the class Constants defined on line 10 of type int called LOOP_INIT_VALUE which contains the number 1 public static final int LOOP_INIT_VALUE = 1; - } From 150eb6e3823e98a7621e6f31b275a0fd2ced9af8 Mon Sep 17 00:00:00 2001 From: samr Date: Mon, 15 May 2023 23:27:39 +0000 Subject: [PATCH 4/6] test.java.TestConstants --- src/test/java/TestConstants.java | 40 ++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/src/test/java/TestConstants.java b/src/test/java/TestConstants.java index 6b8c5883..ea628f97 100644 --- a/src/test/java/TestConstants.java +++ b/src/test/java/TestConstants.java @@ -1,45 +1,81 @@ +// Constants.java +// Costants for FizzBuzz tests + /** * Constants for FizzBuzz tests */ public class TestConstants { - + // create a private constructor for the class TestConstants defined on line 7 which calls itself private TestConstants() { super(); } + // a public, static constant property of type String called _1_2_FIZZ_4_BUZZ_FIZZ_7_8_FIZZ_BUZZ_11_FIZZ_13_14_FIZZ_BUZZ_16 which contains the text "1\n2\nFizz\n4\nBuzz\nFizz\n7\n8\nFizz\nBuzz\n11\nFizz\n13\n14\nFizzBuzz\n16\n" static final String _1_2_FIZZ_4_BUZZ_FIZZ_7_8_FIZZ_BUZZ_11_FIZZ_13_14_FIZZ_BUZZ_16 = "1\n2\nFizz\n4\nBuzz\nFizz\n7\n8\nFizz\nBuzz\n11\nFizz\n13\n14\nFizzBuzz\n16\n"; + // a public, static constant property of type String called _1_2_FIZZ_4_BUZZ_FIZZ_7_8_FIZZ_BUZZ_11_FIZZ_13_14_FIZZ_BUZZ which contains the text "1\n2\nFizz\n4\nBuzz\nFizz\n7\n8\nFizz\nBuzz\n11\nFizz\n13\n14\nFizzBuzz\n" static final String _1_2_FIZZ_4_BUZZ_FIZZ_7_8_FIZZ_BUZZ_11_FIZZ_13_14_FIZZ_BUZZ = "1\n2\nFizz\n4\nBuzz\nFizz\n7\n8\nFizz\nBuzz\n11\nFizz\n13\n14\nFizzBuzz\n"; + // a public, static constant property of type String called _1_2_FIZZ_4_BUZZ_FIZZ_7_8_FIZZ_BUZZ_11_FIZZ_13_14 which contains the text "1\n2\nFizz\n4\nBuzz\nFizz\n7\n8\nFizz\nBuzz\n11\nFizz\n13\n14\n" static final String _1_2_FIZZ_4_BUZZ_FIZZ_7_8_FIZZ_BUZZ_11_FIZZ_13_14 = "1\n2\nFizz\n4\nBuzz\nFizz\n7\n8\nFizz\nBuzz\n11\nFizz\n13\n14\n"; + // a public, static constant property of type String called _1_2_FIZZ_4_BUZZ_FIZZ_7_8_FIZZ_BUZZ_11_FIZZ_13 which contains the text "1\n2\nFizz\n4\nBuzz\nFizz\n7\n8\nFizz\nBuzz\n11\nFizz\n13\n" static final String _1_2_FIZZ_4_BUZZ_FIZZ_7_8_FIZZ_BUZZ_11_FIZZ_13 = "1\n2\nFizz\n4\nBuzz\nFizz\n7\n8\nFizz\nBuzz\n11\nFizz\n13\n"; + // a public, static constant property of type String called _1_2_FIZZ_4_BUZZ_FIZZ_7_8_FIZZ_BUZZ_11_FIZZ which contains the text "1\n2\nFizz\n4\nBuzz\nFizz\n7\n8\nFizz\nBuzz\n11\nFizz\n" static final String _1_2_FIZZ_4_BUZZ_FIZZ_7_8_FIZZ_BUZZ_11_FIZZ = "1\n2\nFizz\n4\nBuzz\nFizz\n7\n8\nFizz\nBuzz\n11\nFizz\n"; + // a public, static constant property of type String called _1_2_FIZZ_4_BUZZ_FIZZ_7_8_FIZZ_BUZZ_11 which contains the text "1\n2\nFizz\n4\nBuzz\nFizz\n7\n8\nFizz\nBuzz\n11\n" static final String _1_2_FIZZ_4_BUZZ_FIZZ_7_8_FIZZ_BUZZ_11 = "1\n2\nFizz\n4\nBuzz\nFizz\n7\n8\nFizz\nBuzz\n11\n"; + // a public, static constant property of type String called _1_2_FIZZ_4_BUZZ_FIZZ_7_8_FIZZ_BUZZ which contains the text "1\n2\nFizz\n4\nBuzz\nFizz\n7\n8\nFizz\nBuzz\n" static final String _1_2_FIZZ_4_BUZZ_FIZZ_7_8_FIZZ_BUZZ = "1\n2\nFizz\n4\nBuzz\nFizz\n7\n8\nFizz\nBuzz\n"; + // a public, static constant property of type String called _1_2_FIZZ_4_BUZZ_FIZZ_7_8_FIZZ which contains the text "1\n2\nFizz\n4\nBuzz\nFizz\n7\n8\nFizz\n" static final String _1_2_FIZZ_4_BUZZ_FIZZ_7_8_FIZZ = "1\n2\nFizz\n4\nBuzz\nFizz\n7\n8\nFizz\n"; + // a public, static constant property of type String called _1_2_FIZZ_4_BUZZ_FIZZ_7_8 which contains the text "1\n2\nFizz\n4\nBuzz\nFizz\n7\n8\n" static final String _1_2_FIZZ_4_BUZZ_FIZZ_7_8 = "1\n2\nFizz\n4\nBuzz\nFizz\n7\n8\n"; + // a public, static constant property of type String called _1_2_FIZZ_4_BUZZ_FIZZ_7 which contains the text "1\n2\nFizz\n4\nBuzz\nFizz\n7\n" static final String _1_2_FIZZ_4_BUZZ_FIZZ_7 = "1\n2\nFizz\n4\nBuzz\nFizz\n7\n"; + // a public, static constant property of type String called _1_2_FIZZ_4_BUZZ_FIZZ which contains the text "1\n2\nFizz\n4\nBuzz\nFizz\n" static final String _1_2_FIZZ_4_BUZZ_FIZZ = "1\n2\nFizz\n4\nBuzz\nFizz\n"; + // a public, static constant property of type String called _1_2_FIZZ_4_BUZZ which contains the text "1\n2\nFizz\n4\nBuzz\n" static final String _1_2_FIZZ_4_BUZZ = "1\n2\nFizz\n4\nBuzz\n"; + // a public, static constant property of type String called _1_2_FIZZ_4 which contains the text "1\n2\nFizz\n4\n" static final String _1_2_FIZZ_4 = "1\n2\nFizz\n4\n"; + // a public, static constant property of type String called _1_2_FIZZ which contains the text "1\n2\nFizz\n" static final String _1_2_FIZZ = "1\n2\nFizz\n"; + // a public, static constant property of type String called _1_2_ which contains the text "1\n2\n" static final String _1_2_ = "1\n2\n"; + // a public, static constant property of type String called _1_ which contains the text "1\n" static final String _1_ = "1\n"; + // a public, static constant property of type String called STANDARD_FIZZ_BUZZ which contains the text "standardFizzBuzz" static final String STANDARD_FIZZ_BUZZ = "standardFizzBuzz"; + // a public, static constant property of type String called SPRING_XML which contains the text "spring.xml" static final String SPRING_XML = "spring.xml"; + // a public, static constant property of type int called INT_1 which contains the number 1 static final int INT_1 = 1; + // a public, static constant property of type int called INT_2 which contains the number 2 static final int INT_2 = 2; + // a public, static constant property of type int called INT_3 which contains the number 3 static final int INT_3 = 3; + // a public, static constant property of type int called INT_4 which contains the number 4 static final int INT_4 = 4; + // a public, static constant property of type int called INT_5 which contains the number 5 static final int INT_5 = 5; + // a public, static constant property of type int called INT_6 which contains the number 6 static final int INT_6 = 6; + // a public, static constant property of type int called INT_7 which contains the number 7 static final int INT_7 = 7; + // a public, static constant property of type int called INT_8 which contains the number 8 static final int INT_8 = 8; + // a public, static constant property of type int called INT_9 which contains the number 9 static final int INT_9 = 9; + // a public, static constant property of type int called INT_10 which contains the number 10 static final int INT_10 = 10; + // a public, static constant property of type int called INT_11 which contains the number 11 static final int INT_11 = 11; + // a public, static constant property of type int called INT_12 which contains the number 12 static final int INT_12 = 12; + // a public, static constant property of type int called INT_13 which contains the number 13 static final int INT_13 = 13; + // a public, static constant property of type int called INT_14 which contains the number 14 static final int INT_14 = 14; + // a public, static constant property of type int called INT_15 which contains the number 15 static final int INT_15 = 15; + // a public, static constant property of type int called INT_16 which contains the number 16 static final int INT_16 = 16; - } From 098e753277887b86e2d3170570fcd4200aa55059 Mon Sep 17 00:00:00 2001 From: samr Date: Mon, 15 May 2023 23:56:17 +0000 Subject: [PATCH 5/6] test.java.FizzBuzzTest --- src/test/java/FizzBuzzTest.java | 50 ++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/src/test/java/FizzBuzzTest.java b/src/test/java/FizzBuzzTest.java index 73ab761c..418a12a0 100644 --- a/src/test/java/FizzBuzzTest.java +++ b/src/test/java/FizzBuzzTest.java @@ -1,85 +1,133 @@ +// FizzBuzzTest.java +// Tests for FizzBuzz + +// import method assertEquals from package org.junit.Assert import static org.junit.Assert.assertEquals; +// import package java.io.BufferedOutputStream import java.io.BufferedOutputStream; +// import package java.io.ByteArrayOutputStream import java.io.ByteArrayOutputStream; +// import package java.io.IOException import java.io.IOException; +// import package java.io.PrintStream import java.io.PrintStream; +// import package org.junit.After import org.junit.After; +// import package org.junit.Before import org.junit.Before; +// import package org.junit.Test import org.junit.Test; +// import package org.springframework.context.ApplicationContext import org.springframework.context.ApplicationContext; +// import package org.springframework.context.ConfigurableApplicationContext import org.springframework.context.ConfigurableApplicationContext; +// import package org.springframework.context.support.ClassPathXmlApplicationContext import org.springframework.context.support.ClassPathXmlApplicationContext; +// import package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.FizzBuzz import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.FizzBuzz; /** * Tests for FizzBuzz */ public class FizzBuzzTest { - + // create a private property on class FizzBuzzTest declared on line 35 called out of type PrintStream imported from import java.io.PrintStream on line 14 private PrintStream out; + // create a private property on class FizzBuzzTest declared on line 35 called fb of type FizzBuzz imported from import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.FizzBuzz on line 30 private FizzBuzz fb; /** + * setUp method on class FizzBuzzTest declared on line 35 sets up object for tests * @return void */ @Before public void setUp() { + // declare an object called context of type ApplicationContext imported from org.springframework.context.ApplicationContext on line 23, based on ClassPathXmlApplicationContext imported from org.springframework.context.support.ClassPathXmlApplicationContext on line 27 passing in test constant SPRING_XML final ApplicationContext context = new ClassPathXmlApplicationContext(TestConstants.SPRING_XML); + // set the value of the property fb of the current object declared on line 39 to the return value of the method getBean on the object context of type ApplicationContext declared on line 48 passing in the test constant STANDARD_FIZZ_BUZZ casted to the type FizzBuzz imported from import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.FizzBuzz on line 30 this.fb = (FizzBuzz) context.getBean(TestConstants.STANDARD_FIZZ_BUZZ); + // set the print stream for this class to System.out, by setting the value of the property out of the current object declared on line 37 this.out = System.out; + // call the method close on the object context declared on line 48 casted to type ConfigurableApplicationContext imported from org.springframework.context.ConfigurableApplicationContext on line 25 ((ConfigurableApplicationContext) context).close(); } /** + * tearDown method on class FizzBuzzTest declared on line 35 deconstructs object and sets everything back to defaults * @return void */ @After public void tearDown() { + // set the system output to the value of the property out on the current object, which should be set to System.out due to it being set on line 52 in method setUp of class FizzBuzzTest declared on line 35 System.setOut(this.out); } /** + * do the fizzbuzz; see method testFizzBuzz on class FizzBuzzTest declared on line 35 declared on line 98 * @param n int * @param s String * @throws IOException */ private void doFizzBuzz(final int n, final String s) throws IOException { + // create a constant of type ByteArrayOutputStream imported from java.io.ByteArrayOutputStream on line 10 called baos final ByteArrayOutputStream baos = new ByteArrayOutputStream(); + // create a constant of type BufferedOutputStream imported from java.io.BufferedOutputStream on line 8 called bos, and pass in baos declared on line 75 to the constructor final BufferedOutputStream bos = new BufferedOutputStream(baos); + // set the system output to the returned object of the constructor for PrintStream imported from java.io.PrintStream on line 14 passing in bos declared on line 77 System.setOut(new PrintStream(bos)); + // call the method fizzBuzz on the property fb of the current object, passing in the constant parameter n of type int this.fb.fizzBuzz(n); + // flush the system ouput by running the method flush on the property out on the class System System.out.flush(); + // create a string variable called platformDependentExpectedResult which replaces all of the newlines in the constant parameter s of type string with the system line seperator, fetched by passing "line.seperator" to the method getProperty on class System String platformDependentExpectedResult = s.replaceAll("\\n", System.getProperty("line.separator")); + // assert that the value of platformDependentExpectedResult declared on line 87 is equal to the string-casted value of baos declared on line 75 assertEquals(platformDependentExpectedResult, baos.toString()); } /** + * does the fizzbuzz; see method doFizzBuzz on class FizzBuzzTest declared on line 35 declared on line 73 * @throws IOException * @return void */ @Test public void testFizzBuzz() throws IOException { + // run the method doFizzBuzz of the current object, passing in the test constant INT_1 as n and the test constant _1_ as s this.doFizzBuzz(TestConstants.INT_1, TestConstants._1_); + // run the method doFizzBuzz of the current object, passing in the test constant INT_2 as n and the test constant _1_2 as s this.doFizzBuzz(TestConstants.INT_2, TestConstants._1_2_); + // run the method doFizzBuzz of the current object, passing in the test constant INT_3 as n and the test constant _1_2_FIZZ as s this.doFizzBuzz(TestConstants.INT_3, TestConstants._1_2_FIZZ); + // run the method doFizzBuzz of the current object, passing in the test constant INT_4 as n and the test constant _1_2_FIZZ_4 as s this.doFizzBuzz(TestConstants.INT_4, TestConstants._1_2_FIZZ_4); + // run the method doFizzBuzz of the current object, passing in the test constant INT_5 as n and the test constant _1_2_FIZZ_4_BUZZ as s this.doFizzBuzz(TestConstants.INT_5, TestConstants._1_2_FIZZ_4_BUZZ); + // run the method doFizzBuzz of the current object, passing in the test constant INT_6 as n and the test constant _1_2_FIZZ_4_BUZZ_FIZZ as s this.doFizzBuzz(TestConstants.INT_6, TestConstants._1_2_FIZZ_4_BUZZ_FIZZ); + // run the method doFizzBuzz of the current object, passing in the test constant INT_7 as n and the test constant _1_2_FIZZ_4_BUZZ_FIZZ_7 as s this.doFizzBuzz(TestConstants.INT_7, TestConstants._1_2_FIZZ_4_BUZZ_FIZZ_7); + // run the method doFizzBuzz of the current object, passing in the test constant INT_8 as n and the test constant _1_2_FIZZ_4_BUZZ_FIZZ_7_8 as s this.doFizzBuzz(TestConstants.INT_8, TestConstants._1_2_FIZZ_4_BUZZ_FIZZ_7_8); + // run the method doFizzBuzz of the current object, passing in the test constant INT_9 as n and the test constant _1_2_FIZZ_4_BUZZ_FIZZ_7_8_FIZZ as s this.doFizzBuzz(TestConstants.INT_9, TestConstants._1_2_FIZZ_4_BUZZ_FIZZ_7_8_FIZZ); + // run the method doFizzBuzz of the current object, passing in the test constant INT_10 as n and the test constant _1_2_FIZZ_4_BUZZ_FIZZ_7_8_FIZZ_BUZZ as s this.doFizzBuzz(TestConstants.INT_10, TestConstants._1_2_FIZZ_4_BUZZ_FIZZ_7_8_FIZZ_BUZZ); + // run the method doFizzBuzz of the current object, passing in the test constant INT_11 as n and the test constant _1_2_FIZZ_4_BUZZ_FIZZ_7_8_FIZZ_BUZZ_11 as s this.doFizzBuzz(TestConstants.INT_11, TestConstants._1_2_FIZZ_4_BUZZ_FIZZ_7_8_FIZZ_BUZZ_11); + // run the method doFizzBuzz of the current object, passing in the test constant INT_12 as n and the test constant _1_2_FIZZ_4_BUZZ_FIZZ_7_8_FIZZ_BUZZ_11_FIZZ as s this.doFizzBuzz(TestConstants.INT_12, TestConstants._1_2_FIZZ_4_BUZZ_FIZZ_7_8_FIZZ_BUZZ_11_FIZZ); + // run the method doFizzBuzz of the current object, passing in the test constant INT_13 as n and the test constant _1_2_FIZZ_4_BUZZ_FIZZ_7_8_FIZZ_BUZZ_11_FIZZ_13 as s this.doFizzBuzz(TestConstants.INT_13, TestConstants._1_2_FIZZ_4_BUZZ_FIZZ_7_8_FIZZ_BUZZ_11_FIZZ_13); + // run the method doFizzBuzz of the current object, passing in the test constant INT_14 as n and the test constant _1_2_FIZZ_4_BUZZ_FIZZ_7_8_FIZZ_BUZZ_11_FIZZ_13_14 as s this.doFizzBuzz(TestConstants.INT_14, TestConstants._1_2_FIZZ_4_BUZZ_FIZZ_7_8_FIZZ_BUZZ_11_FIZZ_13_14); + // run the method doFizzBuzz of the current object, passing in the test constant INT_15 as n and the test constant _1_2_FIZZ_4_BUZZ_FIZZ_7_8_FIZZ_BUZZ_11_FIZZ_13_14_FIZZ_BUZZ as s this.doFizzBuzz(TestConstants.INT_15, TestConstants._1_2_FIZZ_4_BUZZ_FIZZ_7_8_FIZZ_BUZZ_11_FIZZ_13_14_FIZZ_BUZZ); + // run the method doFizzBuzz of the current object, passing in the test constant INT_16 as n and the test constant _1_2_FIZZ_4_BUZZ_FIZZ_7_8_FIZZ_BUZZ_11_FIZZ_13_14_FIZZ_BUZZ_16 as s this.doFizzBuzz(TestConstants.INT_16, TestConstants._1_2_FIZZ_4_BUZZ_FIZZ_7_8_FIZZ_BUZZ_11_FIZZ_13_14_FIZZ_BUZZ_16); } From 82cf500f9eee1f6c0be09f869718198ebb44761b Mon Sep 17 00:00:00 2001 From: samr Date: Tue, 16 May 2023 00:07:16 +0000 Subject: [PATCH 6/6] interfaces.FizzBuzz --- .../fizzbuzz/packagenamingpackage/interfaces/FizzBuzz.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/FizzBuzz.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/FizzBuzz.java index d0147978..a4d84c2b 100644 --- a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/FizzBuzz.java +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/FizzBuzz.java @@ -1,13 +1,16 @@ +// FizzBuzz.java +// FizzBuzz + +// add this specific interface (FizzBuzz) to the package named com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces; /** * FizzBuzz */ public interface FizzBuzz { - /** + * the signature for the constructor for the class FizzBuzz declared on line 10 * @param nFizzBuzzUpperLimit */ void fizzBuzz(int nFizzBuzzUpperLimit); - }