Checking parameters of all method calls

  Kiến thức lập trình

I work on a Java app which uses a ResourceBundle with a static helper class.

Simplified it works like this:

class Bundle()
{
  static String get(key)
  {
    resourceBundle.get(key)
  } 
}

uiClass()
{
  new Label(Bundle.get("key.to.ressource"))
}

Now if you insert a wrong Key (e.g. wrongly capitalized “Key.To.Resource”) the app only throws an Exception at runtime and don’t fail while compiling or testing.

So I wanted to write an (Arch-)UnitTest which simply checks all method calls to Bundle.get() in the project with all used parameters and check for exceptions. Does ArchUnit even support such tests? If not, how could I achieve the same result: Ensure that all keys are valid while compiling or testing?

I tried using ArchUnit (via Maven: com.tngtech.archunit:archunit:1.2.1) but I’m not sure, if these more dynamic values are supported.

LEAVE A COMMENT