Skip to content

Additional tests for named container lookup#1

Merged
rhusar merged 2 commits intorhusar:named-container-lookupfrom
topicusonderwijs:issue-117-part1-a
Apr 30, 2026
Merged

Additional tests for named container lookup#1
rhusar merged 2 commits intorhusar:named-container-lookupfrom
topicusonderwijs:issue-117-part1-a

Conversation

@haster
Copy link
Copy Markdown

@haster haster commented Apr 30, 2026

What was left of the code I had locally after taking into account what you had already done on this branch. Do with it what you will, I offer them as suggestions so as not to let the code get lost. They are not necessary for our case.

Two commits:

  • test-only additions on the existing code
  • null-safe lookup-by-name + typed lookup overload (convenience API for downstream consumers) + supporting tests

The 2nd commit is a slight change in your production code. Feel free to pick only the first commit if you so wish.

haster and others added 2 commits April 30, 2026 16:59
Adds two test additions on top of the named-lookup implementation:

- NamedContainerTest: a third field reusing an existing name, asserting
  that two fields with the same @TestContainer(name) resolve to the same
  instance.
- TestcontainerRegistryTest: plain-JUnit unit tests exercising the
  registry's lookup semantics directly — same-name same-instance via
  lookupOrCreate, lookup of an unknown name, and lookup of the empty
  string against a registry holding only named containers.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
- TestcontainerRegistry.lookup(String): flip the equals direction so
  callers passing null get a null result instead of an NPE on a
  populated registry. The compared `containerDesc.name` is sourced from
  Testcontainer.name(), which by annotation rules cannot be null.
- TestcontainerRegistry.lookup(String, Class<T>): typed overload that
  casts the looked-up container to the requested type, throwing
  IllegalArgumentException if the registered container is not assignable
  to the requested type. Returns null if no container with the given
  name is registered.

Tests cover the null-name path on a populated registry, the typed-lookup
happy path including a missing-name null return, and the type-mismatch
throw path.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@rhusar
Copy link
Copy Markdown
Owner

rhusar commented Apr 30, 2026

@haster I am slightly confused by addition of org.arquillian.testcontainers.TestcontainerRegistry#lookup(java.lang.String, java.lang.Class) which is never used from prod code (only from test code)? The 'convenience API for downstream consumers' - i don't think the org.arquillian.testcontainers.TestcontainerRegistry is obtainable by users.

Rest look good.

@haster
Copy link
Copy Markdown
Author

haster commented Apr 30, 2026

One of our other changes would make the Registry (or the View, or both, if your PR arquillian#127 drops) injectable via @ArquillianResource
That would make this method accessible for manual access.

It's a convenience based on our current code but not necessary.

(I wonder if the extension could use it for injection 🤔 but I can't check that right now).

Copy link
Copy Markdown
Owner

@rhusar rhusar left a comment

Choose a reason for hiding this comment

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

LGTM – we will resolve the situation with the new lookup method in the subsequent PR.

@rhusar rhusar merged commit ffaedfb into rhusar:named-container-lookup Apr 30, 2026
3 checks passed
@rhusar
Copy link
Copy Markdown
Owner

rhusar commented Apr 30, 2026

Thanks @haster

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