Bug 547 - 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.
Summary: There is an issue arised when writing the test code of ClimbingMode class. Wh...
Status: CONFIRMED
Alias: None
Product: Trash
Classification: Unclassified
Component: test (show other bugs)
Version: unspecified
Hardware: PC Windows
: Normal enhancement
Assignee: ruiruyang2-c
URL:
Depends on:
Blocks:
 
Reported: 2021-11-07 13:57 HKT by xuntanye2-c
Modified: 2021-12-01 10:30 HKT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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.