Increase unit test code coverage

pull/876/head
chen.ma 2 years ago
parent 233ebeef28
commit a193869619

@ -19,7 +19,7 @@ coverage:
status: status:
patch: patch:
default: default:
threshold: 0.1% threshold: 0.01%
ignore: ignore:
- "hippo4j-example/.*" - "hippo4j-example/.*"
- "docs/.*" - "docs/.*"

@ -34,7 +34,7 @@ public class RewriteUserInfoApiFilter implements Filter {
@Override @Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
boolean enableAuthentication = AuthUtil.enableAuthentication; boolean enableAuthentication = AuthUtil.ENABLE_AUTHENTICATION;
HttpServletRequest httpRequest = (HttpServletRequest) servletRequest; HttpServletRequest httpRequest = (HttpServletRequest) servletRequest;
String path = httpRequest.getRequestURI(); String path = httpRequest.getRequestURI();
if (!enableAuthentication && path.contains("users/info")) { if (!enableAuthentication && path.contains("users/info")) {

@ -20,13 +20,19 @@ package cn.hippo4j.auth.toolkit;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
/**
* Auth util.
*/
@Component @Component
public class AuthUtil { public class AuthUtil {
public static boolean enableAuthentication; /**
* Enable authentication
*/
public static boolean ENABLE_AUTHENTICATION;
@Value("${hippo4j.core.auth.enabled:true}") @Value("${hippo4j.core.auth.enabled:true}")
public void setEnableAuthentication(boolean enabled) { public void setEnableAuthentication(boolean enabled) {
AuthUtil.enableAuthentication = enabled; AuthUtil.ENABLE_AUTHENTICATION = enabled;
} }
} }

@ -0,0 +1,38 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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 cn.hippo4j.auth.toolkit;
import cn.hippo4j.common.toolkit.Assert;
import org.junit.Before;
import org.junit.Test;
public final class AuthUtilTest {
private AuthUtil authUtil;
@Before
public void beforeInit() {
authUtil = new AuthUtil();
authUtil.setEnableAuthentication(true);
}
@Test
public void assertGetEnableAuthentication() {
Assert.isTrue(AuthUtil.ENABLE_AUTHENTICATION);
}
}

@ -0,0 +1,49 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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 cn.hippo4j.auth.toolkit;
import cn.hippo4j.common.toolkit.Assert;
import org.junit.Before;
import org.junit.Test;
import java.util.Objects;
public final class ReturnTTest {
private ReturnT returnT;
@Before
public void beforeInit() {
returnT = new ReturnT("success");
}
@Test
public void assertGetCode() {
Assert.isTrue(Objects.equals(returnT.getCode(), 200));
}
@Test
public void assertGetMessage() {
Assert.isNull(returnT.getMsg());
}
@Test
public void assertGetContent() {
Assert.isTrue(Objects.equals(returnT.getContent(), "success"));
}
}
Loading…
Cancel
Save