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

chore(StorageManager): typos and minor code cleanups #5009

Merged
merged 5 commits into from
May 14, 2022

Conversation

keturn
Copy link
Member

@keturn keturn commented May 8, 2022

Responding to code inspections and suggestions.

Some cleanup to reduce distractions while working on StorageManager for #4800.

Might have some conflicts with that branch, but both these branches are pretty small, shouldn't be too much trouble to resolve.

@keturn keturn added Size: S Small effort likely only affecting a single area and requiring little to no research Type: Chore Request for or implementation of maintenance changes labels May 8, 2022
@@ -147,7 +145,7 @@ public void setup(@TempDir Path tempHome) throws Exception {

context.put(ChunkProvider.class, mock(ChunkProvider.class));
WorldProvider worldProvider = mock(WorldProvider.class);
when(worldProvider.getWorldInfo()).thenReturn(new WorldInfo());
// when(worldProvider.getWorldInfo()).thenReturn(new WorldInfo());
Copy link
Member

Choose a reason for hiding this comment

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

is this still required or can it be removed entirely?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is the thing that spooks me about mocks.

Mockito told me that not all the mocks were used for all the tests. For instance, some of the tests don't use the NetworkManager mocks. A couple of these lines weren't used by any of the tests—those are the ones I've commented out.

But I have a hunch that they were needed at some point or they wouldn't have been written. What if the next test needs them? Or what if something somewhere in the depths of one of these systems shifts which methods it calls when, and now this gets called again?

So I left it a little messy. With the intent that we'll come back to this after #5010 is merged and take another look at what kind of HeadlessEnvironment these tests need.

Copy link
Member

Choose a reason for hiding this comment

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

in that case, please add a TODO there so that it's clear, why this is commented-out but not removed a.k.a what's unclear about it and what's necessary before it can be clarified and either re-introduced or removed.

when(chunkProvider.getAllChunks()).thenReturn(Arrays.asList(chunk));
when(chunkProvider.getChunk(ArgumentMatchers.any(Vector3ic.class))).thenReturn(chunk);
when(chunkProvider.getAllChunks()).thenReturn(List.of(chunk));
// when(chunkProvider.getChunk(ArgumentMatchers.any(Vector3ic.class))).thenReturn(chunk);
Copy link
Member

Choose a reason for hiding this comment

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

same question

Copy link
Member

Choose a reason for hiding this comment

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

see above

savePath = PathManager.getInstance().getSavePath("testSave");

assert !Files.isRegularFile(tempHome.resolve("global.dat"));
Copy link
Member

Choose a reason for hiding this comment

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

why is this assertion no longer relevant?

Copy link
Member

@pollend pollend May 11, 2022

Choose a reason for hiding this comment

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

this should use the junit test function not assert. assertFalse()

Copy link
Member Author

Choose a reason for hiding this comment

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

I think the intention of that assert was to make sure that we aren't re-using a directory that already has stuff in it. I took it out because it was already guaranteed unique by @TempDir, and because I removed this TempDir stuff because there's already TempDir stuff setting up the PathManager in TerasologyTestingEnvironment.

But your comment did prompt me to take another look, and I found that I had broken things here, I just hadn't gotten caught yet. (global.dat would be under savePath, not tempHome) This is a BeforeEach, but TTE was only doing the path setup BeforeAll.

I've fixed it now so every test gets its own save name, regardless of whether the PathManager has been reset between methods or not.

Responding to code inspections and suggestions.
@keturn keturn force-pushed the chore/storage-manager-tidy branch from e6a099a to 71045e8 Compare May 13, 2022 20:15
@keturn
Copy link
Member Author

keturn commented May 13, 2022

jdrueckert
jdrueckert previously approved these changes May 14, 2022
Copy link
Member

@jdrueckert jdrueckert left a comment

Choose a reason for hiding this comment

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

I'll add my approval already now but please add TODO comments for the two commented-out lines before merging :)

@@ -147,7 +145,7 @@ public void setup(@TempDir Path tempHome) throws Exception {

context.put(ChunkProvider.class, mock(ChunkProvider.class));
WorldProvider worldProvider = mock(WorldProvider.class);
when(worldProvider.getWorldInfo()).thenReturn(new WorldInfo());
// when(worldProvider.getWorldInfo()).thenReturn(new WorldInfo());
Copy link
Member

Choose a reason for hiding this comment

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

in that case, please add a TODO there so that it's clear, why this is commented-out but not removed a.k.a what's unclear about it and what's necessary before it can be clarified and either re-introduced or removed.

when(chunkProvider.getAllChunks()).thenReturn(Arrays.asList(chunk));
when(chunkProvider.getChunk(ArgumentMatchers.any(Vector3ic.class))).thenReturn(chunk);
when(chunkProvider.getAllChunks()).thenReturn(List.of(chunk));
// when(chunkProvider.getChunk(ArgumentMatchers.any(Vector3ic.class))).thenReturn(chunk);
Copy link
Member

Choose a reason for hiding this comment

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

see above

@keturn
Copy link
Member Author

keturn commented May 14, 2022

Comments on comments, hmm?

Alright, how about this: I've un-commented those lines—the test's mockito strictness is already lowered to lenient, so that won't break anything—and I've added a TODO comment with an explanation for the lenient setting.

Thank you for the review! I'll merge once Jenkins approves this latest change.

@keturn keturn merged commit 60b819b into develop May 14, 2022
@keturn keturn deleted the chore/storage-manager-tidy branch May 14, 2022 18:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Size: S Small effort likely only affecting a single area and requiring little to no research Type: Chore Request for or implementation of maintenance changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants