Bug 547

Summary: There is an issue arised when writing the test code of ClimbingMode class. When initializing the ClimbingTrailRepoManager as the new ClimbingTrailRepoManagerStub, the current program code is unable to take the ClimbingTrailRepoManagerStub as input.
Product: Trash Reporter: xuntanye2-c
Component: testAssignee: ruiruyang2-c
Status: CONFIRMED ---    
Severity: enhancement    
Priority: Normal    
Version: unspecified   
Hardware: PC   
OS: Windows   

Description xuntanye2-c 2021-11-07 13:57:41 HKT
Step to Reproduce:
When running the below segment of code as junit test, the code didn't cover for the listTrails and findTrailsByDifficulty functions.
	private ClimbingMode cm = ClimbingMode.getInstance();
	@Test
	public void testTrailListing() {
		ClimbingTrailRepoManager ctrm = new ClimbingTrailRepoManagerStub();
		String actualString = ctrm.list();
		String expectedString = "Test trail";
		assertEquals(expectedString, actualString);

	}

	@Test
	public void testFilterDifficulty() {
		ClimbingTrailRepoManager ctrm = new ClimbingTrailRepoManagerStub();
		String actualString = ctrm.filterByDifficulty(8);
		String expectedString = "Test trail";
		assertEquals(expectedString, actualString);

	}

Actual Result: 
The listTrails and findTrailsByDifficulty functions are not covered.


Expected Result: 
The test code coverage should increase, the code in the ClimbingMode class, listTrails and findTrailsByDifficulty, should be covered.
Comment 1 xuntanye2-c 2021-11-07 14:01:34 HKT
Solution:
Adding a new constructor with input parameter in the ClimbingMode class in addition to the constructor without input parameter so that the test case can input a ClimbingTrailRepoManagerStub Object to initialize the ClimbingMode object.
The singleton design pattern should also not be applied for this class because multiple constructors are required and needed to be accessed by other classes.