Skip to content

feat: initialize with maven #6

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

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions common/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>bms-prototype</artifactId>
<groupId>org.ridelab.bms</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<packaging>jar</packaging>
<artifactId>common</artifactId>

<dependencies>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.3</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.7</version>
</dependency>
</dependencies>

</project>
42 changes: 42 additions & 0 deletions common/src/main/java/org/ridelab/bms/common/five/Five.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package org.ridelab.bms.common.five;

import lombok.AccessLevel;
import lombok.experimental.FieldDefaults;
import lombok.experimental.UtilityClass;

/**
* @see <a href="https://github.com/jackdclark/five">Five</a>
*/
@UtilityClass
@FieldDefaults(level = AccessLevel.PUBLIC)
public class Five {

int five() {
return 5;
}

boolean isFive(int n) {
return five() == n;
}

String esperanto() {
return "kvin";
}

String greek() {
return "πέντε";
}

String pinyin() {
return "wǔ";
}

String morseCode() {
return ".....";
}

String oclock() {
return "\uD83D\uDD54";
}

}
35 changes: 35 additions & 0 deletions common/src/test/java/org/ridelab/bms/common/five/FiveTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package org.ridelab.bms.common.five;

import org.apache.commons.lang3.StringUtils;
import org.junit.Test;
import org.ridelab.bms.common.five.Five;

import static junit.framework.TestCase.assertTrue;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;

public class FiveTest {

@Test
public void five() {
assertEquals(5, Five.five());
}

@Test
public void isFive() {
assertTrue(Five.isFive(5));
assertFalse(Five.isFive(6));
}

@Test
public void multilingual() {
assertTrue(StringUtils.isNoneBlank(
Five.esperanto(),
Five.greek(),
Five.pinyin(),
Five.morseCode(),
Five.oclock()
));
}

}
23 changes: 23 additions & 0 deletions data-schema/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>bms-prototype</artifactId>
<groupId>org.ridelab.bms</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<packaging>jar</packaging>
<artifactId>data-schema</artifactId>

<dependencies>
<dependency>
<groupId>org.ridelab.bms</groupId>
<artifactId>common</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>

</project>
13 changes: 13 additions & 0 deletions data-schema/src/main/java/org/ridelab/bms/entity/Item.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.ridelab.bms.entity;

import lombok.Value;

@Value(staticConstructor = "of")
public class Item {

String name;

long id;

}

60 changes: 60 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.ridelab.bms</groupId>
<artifactId>bms-prototype</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>

<modules>
<module>common</module>
<module>data-schema</module>
<module>service</module>
</modules>

<properties>
<project.build.sourceEncoding>utf-8</project.build.sourceEncoding>
</properties>

<dependencies>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.18</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>15.0</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>utf-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.9.1</version>
</plugin>
</plugins>
</build>

</project>
2 changes: 2 additions & 0 deletions scripts/ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@

scripts/lint-docs.sh

mvn clean test

echo -e "\033[0;32mFinished\033[m"
28 changes: 28 additions & 0 deletions service/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>bms-prototype</artifactId>
<groupId>org.ridelab.bms</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<packaging>jar</packaging>
<artifactId>service</artifactId>

<dependencies>
<dependency>
<groupId>org.ridelab.bms</groupId>
<artifactId>common</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.ridelab.bms</groupId>
<artifactId>data-schema</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>

</project>
25 changes: 25 additions & 0 deletions service/src/main/java/org/ridelab/bms/service/ItemService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.ridelab.bms.service;

import org.ridelab.bms.entity.Item;

import java.util.Optional;

public interface ItemService {

/**
* Find one by id
*
* @param id id
* @return found item
*/
Optional<Item> findOneById(long id);

/**
* Find all by name
*
* @param name name
* @return found items
*/
Iterable<Item> findAllByName(String name);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package org.ridelab.bms.service.impl;

import lombok.extern.slf4j.Slf4j;
import lombok.val;
import org.apache.commons.lang3.RandomUtils;
import org.ridelab.bms.entity.Item;
import org.ridelab.bms.service.ItemService;

import java.util.Comparator;
import java.util.Optional;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

@Slf4j
public class ItemServiceImpl implements ItemService {

@Override
public Optional<Item> findOneById(long id) {

if (id < 0) {

logger.debug("Can't find item with negative id {}", id);

return Optional.empty();

} else {

val item = Item.of("nothing", id);

logger.debug("Found item {}", item);

return Optional.of(item);
}
}

@Override
public Iterable<Item> findAllByName(String name) {

val items = IntStream.range(1, RandomUtils.nextInt(5, 10)).
mapToObj(i -> Item.of(name, RandomUtils.nextInt())).
sorted(Comparator.comparingLong(Item::getId)).
collect(Collectors.toList());

logger.debug("Found items <size = {}> {}", items.size(), items);

return items;
}

}

33 changes: 33 additions & 0 deletions service/src/test/java/org/ridelab/bms/service/ItemServiceTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package org.ridelab.bms.service;

import lombok.val;
import org.junit.Test;
import org.ridelab.bms.service.impl.ItemServiceImpl;

import static org.junit.Assert.*;

public class ItemServiceTest {

private final ItemService itemService = new ItemServiceImpl();

@Test
public void getOneById() {
val result = itemService.findOneById(1L);
assertTrue(result.isPresent());
assertEquals(1L, result.get().getId());
}

@Test
public void getOneByIdNonexistent() {
val result = itemService.findOneById(-1L);
assertFalse(result.isPresent());
}

@Test
public void findAllByName() {
val result = itemService.findAllByName("nothing");
assertTrue(result.iterator().hasNext());
assertEquals("nothing", result.iterator().next().getName());
}

}