Micronaut-core: getNaturalName() returns incorrect name

Created on 16 Apr 2019  路  9Comments  路  Source: micronaut-projects/micronaut-core

Task List

  • [x] Steps to reproduce provided
  • [ ] Stacktrace (if present) provided
  • [x] Example that reproduces the problem uploaded to Github
  • [x] Full description of the issue provided (see below)

Steps to Reproduce

  1. Call getNaturalName(String name) with the input DomainRCAdaptor.
  2. The function is returning output Domain RCA daptor where as the correct output should be Domain RC Adaptor.
  3. The code is hard to debug and not well maintained. Requesting to give the opportunity to rewrite the code while correcting the above use-case.

Expected Behaviour

Given the input DomainRCAdaptor, the output should be Domain RC Adaptor

Actual Behaviour

Given the input DomainRCAdaptor, the output is Domain RCA daptor

Environment Information

  • Operating System: All
  • Micronaut Version: 1.1.0
  • JDK Version: 1.8
good first issue cli bug

All 9 comments

@vinrar If you'd like feel free to submit a PR. If you can also create a test case that ensures the following passes:

NameUtils.getNaturalName("firstName") == "First Name"
NameUtils.getNaturalName("URL") == "URL"
NameUtils.getNaturalName("localURL") == "Local URL"
NameUtils.getNaturalName("URLlocal") == "URL local"
NameUtils.getNaturalName("aURLlocal") == "A URL local"
NameUtils.getNaturalName("MyDomainClass") == "My Domain Class"
NameUtils.getNaturalName("com.myco.myapp.MyDomainClass") == "My Domain Class"
NameUtils.getNaturalName("aName") == "A Name"

@vinrar Are you working on this issue? If not I can take it.

Thanks @koziolk, I would like to attempt it by myself. Will have it ready by Tue/Wed.

@jameskleeh If this is a valid case, What should be the output of NameUtils.getNaturalName("uRLlocal")? And in Java, the alphabet after the acronym is usually a capital letter. So shouldn't NameUtils.getNaturalName("URLlocal") == "URL local" ideally be NameUtils.getNaturalName("URLLocal") == "URL Local"?

I would expect under the current rules:
NameUtils.getNaturalName("uRLlocal") == "U RL Local"

I don't think you can have it both ways. It's impossible to know whether the last capital is supposed to be with the previous segment or the next segment

NameUtils.getNaturalName("URLLocal") == "URL Local" makes sense, but so does NameUtils.getNaturalName("URLlocal") == "URL local".

After thinking about this more I think the current behavior is allowing for a new word to not start with a capital, which is incorrect. NameUtils.getNaturalName("URLlocal") == "UR Llocal" seems to be correct to me.

@jameskleeh Can you please review the PR: https://github.com/micronaut-projects/micronaut-core/pull/1583

Was this page helpful?
0 / 5 - 0 ratings