Bug 632 - ClimbingMode constructor not flexible for testing
Summary: ClimbingMode constructor not flexible for testing
Status: RESOLVED FIXED
Alias: None
Product: New-Territories-Cycle-Track-Navigation-System
Classification: Unclassified
Component: ClimbingMode (show other bugs)
Version: 1.0
Hardware: PC Windows
: --- enhancement
Assignee: xuntanye2-c
URL:
Depends on:
Blocks:
 
Reported: 2021-12-01 10:27 HKT by xuntanye2-c
Modified: 2021-12-01 10:29 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-12-01 10:27:49 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-12-01 10:29:17 HKT
Solution:
A new constructor  public ClimbingMode(ClimbingTrailRepoManager ctrm, Scanner scan, BookmarkManager bmManager,CyclingMode cm) is used so that the input parameters can accept stubs for testing.