Skip to content

Commit

Permalink
Improve code coverage.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ahoo-Wang committed Apr 18, 2022
1 parent 40c8a75 commit c302b01
Show file tree
Hide file tree
Showing 8 changed files with 298 additions and 2 deletions.
5 changes: 5 additions & 0 deletions simba-spring-boot-starter/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,9 @@ dependencies {
api("org.springframework.boot:spring-boot-starter")
annotationProcessor("org.springframework.boot:spring-boot-configuration-processor:${rootProject.ext.get("springBootVersion")}")
annotationProcessor("org.springframework.boot:spring-boot-autoconfigure-processor:${rootProject.ext.get("springBootVersion")}")

testImplementation("org.springframework.boot:spring-boot-starter-test")
testImplementation("mysql:mysql-connector-java")
testImplementation("org.springframework.boot:spring-boot-starter-jdbc")
testImplementation("org.apache.curator:curator-test")
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
public class JdbcProperties {
public static final String PREFIX = Simba.SIMBA_PREFIX + "jdbc";
private boolean enabled = true;

private Duration initialDelay = Duration.ofSeconds(0);
private Duration ttl = Duration.ofSeconds(10);
private Duration transition = Duration.ofSeconds(6);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ public SimbaZookeeperAutoConfiguration(ZookeeperProperties zookeeperProperties)
this.zookeeperProperties = zookeeperProperties;
}


@Bean
@ConditionalOnBean(CuratorFramework.class)
@ConditionalOnMissingBean
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
* Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].
* 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 me.ahoo.simba.spring.boot.starter.jdbc;

import static org.junit.jupiter.api.Assertions.*;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import java.time.Duration;

/**
* JdbcPropertiesTest .
*
* @author ahoo wang
*/
class JdbcPropertiesTest {

@Test
void isEnabled() {
JdbcProperties properties = new JdbcProperties();
Assertions.assertTrue(properties.isEnabled());
}

@Test
void setEnabled() {
JdbcProperties properties = new JdbcProperties();
properties.setEnabled(false);
Assertions.assertFalse(properties.isEnabled());
}

@Test
void getInitialDelay() {
JdbcProperties properties = new JdbcProperties();
Assertions.assertEquals(Duration.ofSeconds(0), properties.getInitialDelay());
}

@Test
void setInitialDelay() {
Duration initialDelay = Duration.ofSeconds(1);
JdbcProperties properties = new JdbcProperties();
properties.setInitialDelay(initialDelay);
Assertions.assertEquals(initialDelay, properties.getInitialDelay());
}

@Test
void getTtl() {
Duration ttl = Duration.ofSeconds(10);
JdbcProperties properties = new JdbcProperties();
Assertions.assertEquals(ttl, properties.getTtl());
}

@Test
void setTtl() {
Duration ttl = Duration.ofSeconds(10);
JdbcProperties properties = new JdbcProperties();
properties.setTtl(ttl);
Assertions.assertEquals(ttl, properties.getTtl());
}

@Test
void getTransition() {
JdbcProperties properties = new JdbcProperties();
Assertions.assertEquals(Duration.ofSeconds(6), properties.getTransition());
}

@Test
void setTransition() {
Duration transition = Duration.ofSeconds(8);
JdbcProperties properties = new JdbcProperties();
properties.setTransition(transition);
Assertions.assertEquals(transition, properties.getTransition());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].
* 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 me.ahoo.simba.spring.boot.starter.jdbc;

import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat;
import static org.junit.jupiter.api.Assertions.*;

import me.ahoo.simba.core.MutexContendServiceFactory;
import me.ahoo.simba.jdbc.MutexOwnerRepository;

import org.junit.jupiter.api.Test;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;

/**
* SimbaJdbcAutoConfigurationTest .
*
* @author ahoo wang
*/
class SimbaJdbcAutoConfigurationTest {
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner();

@Test
void contextLoads() {
this.contextRunner
.withPropertyValues("spring.datasource.url=jdbc:mysql://localhost:3306/simba_db")
.withUserConfiguration(DataSourceAutoConfiguration.class, SimbaJdbcAutoConfiguration.class)
.run(context -> {
assertThat(context)
.hasSingleBean(SimbaJdbcAutoConfiguration.class)
.hasSingleBean(JdbcProperties.class)
.hasSingleBean(MutexOwnerRepository.class)
.hasSingleBean(MutexContendServiceFactory.class)
;
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].
* 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 me.ahoo.simba.spring.boot.starter.redis;

import static org.junit.jupiter.api.Assertions.*;

import me.ahoo.simba.spring.boot.starter.jdbc.JdbcProperties;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import java.time.Duration;

/**
* RedisPropertiesTest .
*
* @author ahoo wang
*/
class RedisPropertiesTest {

@Test
void isEnabled() {
RedisProperties properties = new RedisProperties();
Assertions.assertTrue(properties.isEnabled());
}

@Test
void setEnabled() {
RedisProperties properties = new RedisProperties();
properties.setEnabled(false);
Assertions.assertFalse(properties.isEnabled());
}

@Test
void getTtl() {
Duration ttl = Duration.ofSeconds(10);
RedisProperties properties = new RedisProperties();
Assertions.assertEquals(ttl, properties.getTtl());
}

@Test
void setTtl() {
Duration ttl = Duration.ofSeconds(10);
RedisProperties properties = new RedisProperties();
properties.setTtl(ttl);
Assertions.assertEquals(ttl, properties.getTtl());
}

@Test
void getTransition() {
RedisProperties properties = new RedisProperties();
Assertions.assertEquals(Duration.ofSeconds(6), properties.getTransition());
}

@Test
void setTransition() {
Duration transition = Duration.ofSeconds(8);
RedisProperties properties = new RedisProperties();
properties.setTransition(transition);
Assertions.assertEquals(transition, properties.getTransition());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].
* 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 me.ahoo.simba.spring.boot.starter.redis;

import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat;
import static org.junit.jupiter.api.Assertions.*;

import me.ahoo.simba.core.MutexContendServiceFactory;

import org.junit.jupiter.api.Test;
import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.data.redis.listener.RedisMessageListenerContainer;

/**
* SimbaSpringRedisAutoConfigurationTest .
*
* @author ahoo wang
*/
class SimbaSpringRedisAutoConfigurationTest {
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner();

@Test
void contextLoads() {
this.contextRunner
.withUserConfiguration(RedisAutoConfiguration.class, SimbaSpringRedisAutoConfiguration.class)
.run(context -> {
assertThat(context)
.hasSingleBean(SimbaSpringRedisAutoConfiguration.class)
.hasSingleBean(RedisProperties.class)
.hasSingleBean(RedisMessageListenerContainer.class)
.hasSingleBean(MutexContendServiceFactory.class)
;
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].
* 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 me.ahoo.simba.spring.boot.starter.zookeeper;

import static org.junit.jupiter.api.Assertions.*;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

/**
* ZookeeperPropertiesTest .
*
* @author ahoo wang
*/
class ZookeeperPropertiesTest {

@Test
void isEnabled() {
ZookeeperProperties properties=new ZookeeperProperties();
Assertions.assertTrue(properties.isEnabled());
}

@Test
void setEnabled() {
ZookeeperProperties properties=new ZookeeperProperties();
properties.setEnabled(false);
Assertions.assertFalse(properties.isEnabled());
}
}

0 comments on commit c302b01

Please sign in to comment.