Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactored dashboard ExportSearchResultsPage #2611

Merged
merged 3 commits into from
Dec 19, 2024
Merged

Conversation

lbownik
Copy link
Contributor

@lbownik lbownik commented Dec 13, 2024

refactored dashboard ExportSearchResultsPage

@lbownik lbownik requested a review from diasf December 13, 2024 12:53
@lbownik lbownik force-pushed the dashboard_refactoring branch from 1be03d6 to add4bee Compare December 16, 2024 09:39
@@ -15,6 +15,8 @@

import static java.util.Optional.ofNullable;

import java.util.Collection;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused import.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@@ -94,6 +94,10 @@ public String getLocaleTitle() {
public int getFilesPerPage() {
return filesPerPage;
}

public boolean canEditDashboard() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be moved to the LOGIC section below.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@Mock
private DataverseSession session;
@Mock
private SystemConfig systemConfig;
@Mock
private DatasetFieldTypeRepository datasetFiledTypeRepo;
@Mock
private PermissionsWrapper permissionsWrapper;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You still need a NavigationWrapper mock.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont need it since I don't test DashboardExportSearchResultsPage.verifyAccess() method, and I don't intend to for now.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But you're purposefully breaking the constructor interface by providing null and you're still creating a SystemConfig mock even though it doesn't seem necessary. I mean, it's not very consistent. Tests are in a way much like production code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

.thenReturn(asList(this.type1, this.type2));
when(this.datasetFiledTypeRepo.findAll()).thenReturn(types);

this.page = new DashboardExportSearchResultsPage(this.session, null,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you remove @InjectMocks?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the constructor of DashboardExportSearchResultsPage invokes datasetFiledTypeRepo.findAll().

i need to call when(this.datasetFiledTypeRepo.findAll()).thenReturn(types); BEFORE instantiating DashboardExportSearchResultsPage
otherwise datasetFiledTypeRepo.findAll() returns empty list

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess the problem stems from using logic inside the constructor, which isn't always the best choice (specifically in a dependency injection context). For instance, you could have extracted the logic to a @PostCostruct annotated method and call that method here to make the intend (logic usage) more obvious.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@diasf diasf assigned lbownik and unassigned diasf Dec 18, 2024
@lbownik lbownik requested a review from diasf December 18, 2024 11:20
@lbownik lbownik merged commit ea5306a into develop Dec 19, 2024
1 check passed
@lbownik lbownik deleted the dashboard_refactoring branch December 19, 2024 09:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants