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

KeyStoreUtilTest: Remove deprecated ExpectedException.none() @Rule & use assertThrows instead #1040

Closed
rohanKanojia opened this issue Oct 19, 2021 · 5 comments · Fixed by #1041 or #1042
Assignees
Labels
first-timers-only Is this your first time contributing? This could be a good place to start! good first issue Good for newcomers Hacktoberfest Issues accountable for the Hacktoberfest

Comments

@rohanKanojia
Copy link
Member

Description

As pointed out in JUnit Javadocs, ExpectedException.none() rule is deprecated. We should use Assert.assertThrows instead

https://github.com/eclipse/jkube/blob/ee2390178dcad8a9cc3a9cb6d5e8c5d70a162a04/jkube-kit/build/service/docker/src/test/java/org/eclipse/jkube/kit/build/service/docker/access/KeyStoreUtilTest.java#L33-L34

We need to refactor loadInvalidPrivateKey test to use assertThrows instead. So what is currently this:
https://github.com/eclipse/jkube/blob/ee2390178dcad8a9cc3a9cb6d5e8c5d70a162a04/jkube-kit/build/service/docker/src/test/java/org/eclipse/jkube/kit/build/service/docker/access/KeyStoreUtilTest.java#L47-L51

Should be changed to:

  @Test
  public void loadInvalidPrivateKey() {
    GeneralSecurityException exception = assertThrows(GeneralSecurityException.class, () -> KeyStoreUtil.loadPrivateKey(getFile("keys/invalid.pem")));
    assertThat(exception).hasMessageContaining("Cannot generate private key");
  }

Before you start

Make sure you read the contributing guide first. Pay special attention to the ECA agreement section and the requirement to sign-off your commit.

How to manually test my changes

Kubernetes

If you don't have a real Kubernetes cluster available (most probably), you can use Minikube or Kind to test with a local cluster.

OpenShift

If you don't have a real OpenShift cluster available (most probably), you can use Red Hat's developer Sandbox for Red Hat OpenShift. The only requirement is to have a Red Hat account.

Once you have your Sandbox environment, you'll need to download the oc tool from the cluster console.
(Press the ? icon and from the context menu select Command line tools, you'll be redirected to https://$subdomain.openshiftapps.com/command-lines-tools where you'll be able to download the CLI for your platform)

@rohanKanojia rohanKanojia added first-timers-only Is this your first time contributing? This could be a good place to start! good first issue Good for newcomers Hacktoberfest Issues accountable for the Hacktoberfest labels Oct 19, 2021
@dolatapatryk
Copy link
Contributor

I would like to do that 😊 Hoping to push the PR today

@rohanKanojia
Copy link
Member Author

@dolatapatryk : Thanks a lot. I'm assigning it to you.

@hsteinmueller
Copy link
Contributor

Hi guys, I'm sorry I simply started working on this without asking first since it's a small task.
I made a PR #1041 but if it doesn't follow the guidelines it's completely fine if you want to use @dolatapatryk 's PR.
Sorry for the inconvenience.

@rohanKanojia
Copy link
Member Author

@hsteinmueller : ohk, no problem.

There are still other places where ExpectedException.none() @Rule needs to be replaced:

jkube : $ git grep -in "ExpectedException.none()"
jkube-kit/build/api/src/test/java/org/eclipse/jkube/kit/build/api/auth/handler/FromConfigRegistryAuthHandlerTest.java:43:    public ExpectedException expectedException = ExpectedException.none();
jkube-kit/build/api/src/test/java/org/eclipse/jkube/kit/build/api/auth/handler/OpenShiftRegistryAuthHandlerTest.java:53:    public ExpectedException expectedException = ExpectedException.none();
jkube-kit/build/api/src/test/java/org/eclipse/jkube/kit/build/api/auth/handler/SystemPropertyRegistryAuthHandlerTest.java:45:    public ExpectedException expectedException = ExpectedException.none();
jkube-kit/build/service/docker/src/test/java/org/eclipse/jkube/kit/build/service/docker/auth/ecr/DockerRegistryAuthHandlerTest.java:55:    public ExpectedException expectedException = ExpectedException.none();

@dolatapatryk : Whenever you pick this, Would it be possible for you to remove ExpectedException.none() from other classes?

@dolatapatryk
Copy link
Contributor

@rohanKanojia yes, of course. I have just submit PR so please don't look at it now. When I changed other places I will notify you :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
first-timers-only Is this your first time contributing? This could be a good place to start! good first issue Good for newcomers Hacktoberfest Issues accountable for the Hacktoberfest
Projects
None yet
3 participants