Polishing.

Replace static imports with qualified use. Add author tags. Add copyright header. Simplify code. Simplify JavaDoc documentation. Rename test class and methods to align with project style.

Original pull request: #64.
This commit is contained in:
Mark Paluch
2017-03-31 12:22:30 +02:00
parent ba135817fa
commit b6d0b04b18
3 changed files with 55 additions and 39 deletions

View File

@@ -17,9 +17,6 @@ package org.springframework.vault.core.lease.domain;
import org.springframework.util.Assert;
import static org.springframework.vault.core.lease.domain.RequestedSecret.Mode.RENEW;
import static org.springframework.vault.core.lease.domain.RequestedSecret.Mode.ROTATE;
/**
* Represents a requested secret from a specific Vault path associated with a lease
* {@link Mode}.
@@ -27,6 +24,7 @@ import static org.springframework.vault.core.lease.domain.RequestedSecret.Mode.R
* A {@link RequestedSecret} can be renewing or rotating.
*
* @author Mark Paluch
* @author Pierre-Jean Vardanega
* @see Mode
* @see Lease#isRenewable()
*/
@@ -53,7 +51,7 @@ public class RequestedSecret {
* @return the renewable {@link RequestedSecret}.
*/
public static RequestedSecret renewable(String path) {
return new RequestedSecret(path, RENEW);
return new RequestedSecret(path, Mode.RENEW);
}
/**
@@ -69,23 +67,19 @@ public class RequestedSecret {
}
/**
* Create a rotating or renewable {@link RequestedSecret} at {@code path}. A lease associated with
* this secret will be renewed if the lease is qualified for renewal. Once the lease
* expires, a new secret with a new lease is obtained if mode is ROTATE, otherwize the lease is no
* longer valid after expiry.
* Create a {@link RequestedSecret} given {@link Mode} at {@code path}.
*
* @param mode must not be {@literal null}
* @param mode must not be {@literal null}.
* @param path must not be {@literal null} or empty, must not start with a slash.
* @see #rotating(String)
* @see #renewable(String)
* @return the rotating {@link RequestedSecret}.
*/
public static RequestedSecret from(Mode mode, String path) {
Assert.notNull(mode, "Mode cannot be null");
if (mode == ROTATE) {
return rotating(path);
} else {
return renewable(path);
}
Assert.notNull(mode, "Mode must not be null");
return mode == Mode.ROTATE ? rotating(path) : renewable(path);
}
/**

View File

@@ -1,24 +0,0 @@
package org.springframework.vault.core.lease.domain;
import org.junit.Test;
import org.springframework.vault.core.lease.domain.RequestedSecret.Mode;
import static org.assertj.core.api.Assertions.assertThat;
public class RequestedSecretTest {
@Test
public void should_build_rotating_requested_secret() {
RequestedSecret requestedSecret = RequestedSecret.from(Mode.ROTATE, "my/path");
assertThat(requestedSecret.getMode()).isEqualTo(Mode.ROTATE);
}
@Test
public void should_build_renewal_requested_secret() {
RequestedSecret requestedSecret = RequestedSecret.from(Mode.RENEW, "my/path");
assertThat(requestedSecret.getMode()).isEqualTo(Mode.RENEW);
}
}

View File

@@ -0,0 +1,46 @@
/*
* Copyright 2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.vault.core.lease.domain;
import org.junit.Test;
import org.springframework.vault.core.lease.domain.RequestedSecret.Mode;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Unit tests for {@link RequestedSecret}.
*
* @author Pierre-Jean Vardanega
*/
public class RequestedSecretTests {
@Test
public void shouldBuildRotatingRequestedSecret() {
RequestedSecret requestedSecret = RequestedSecret.from(Mode.ROTATE, "my/path");
assertThat(requestedSecret.getMode()).isEqualTo(Mode.ROTATE);
}
@Test
public void shouldBuildRenewingRequestedSecret() {
RequestedSecret requestedSecret = RequestedSecret.from(Mode.RENEW, "my/path");
assertThat(requestedSecret.getMode()).isEqualTo(Mode.RENEW);
}
}