Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
6430201
Added members of the team
aleksandraprohorova Oct 12, 2021
badea31
fix test failure with LineSeparator method
fyaraliyeva Oct 13, 2021
f70b7fb
Added logging of chars
aleksandraprohorova Oct 14, 2021
81b2732
add log method for String
fyaraliyeva Oct 14, 2021
0db7f8e
Uncommented test for logging chars
aleksandraprohorova Oct 14, 2021
f45ae8c
add log method for boolean
fyaraliyeva Oct 14, 2021
a949a1f
Added logging for references
aleksandraprohorova Oct 14, 2021
6028616
Moved printing to console to separate method
aleksandraprohorova Oct 14, 2021
23a8cb5
Separated printStream to make it changeable
aleksandraprohorova Oct 14, 2021
97b7256
Added handling null object
aleksandraprohorova Oct 14, 2021
d7d4995
Added state machine to manage summed values and string repetitions
aleksandraprohorova Oct 15, 2021
cb57575
Remove redundant code
aleksandraprohorova Oct 15, 2021
af1bab6
Added TODOs from remarks
aleksandraprohorova Oct 15, 2021
cf18b96
Improved design to reduce code duplication for iterations 1-2
aleksandraprohorova Oct 18, 2021
2f37ed3
add interation03 tests refactoring
fyaraliyeva Oct 18, 2021
67ed4a0
Added methods to log arrays of ints and strings
aleksandraprohorova Oct 18, 2021
732e0db
proceed TODO's
fyaraliyeva Oct 19, 2021
b5b2414
Refactored to objects
aleksandraprohorova Oct 20, 2021
bef68c1
Refactored to objects
aleksandraprohorova Oct 20, 2021
65db7c3
Removed redundant code
aleksandraprohorova Oct 21, 2021
06128e7
Created common methods accumulate and isSameType for all messages
aleksandraprohorova Oct 21, 2021
42beaba
Added object message
aleksandraprohorova Oct 21, 2021
1bf9863
Added message of int array
aleksandraprohorova Oct 21, 2021
cea3459
Removed method clear
aleksandraprohorova Oct 21, 2021
c009f97
Added two dimesional arrays
aleksandraprohorova Oct 21, 2021
e7b07bf
refactor log for char and boolean
fyaraliyeva Oct 21, 2021
c0af9e5
Merge remote-tracking branch 'origin/master'
fyaraliyeva Oct 21, 2021
b096b18
Removed redundant methods
aleksandraprohorova Oct 21, 2021
c8a8c08
Removed redundant imports
aleksandraprohorova Oct 21, 2021
bd9c7e0
Removed redundant file
aleksandraprohorova Oct 21, 2021
6406294
remove unused methods
fyaraliyeva Oct 21, 2021
4bcca5f
Merge remote-tracking branch 'origin/master'
fyaraliyeva Oct 21, 2021
479f1be
Removed redundant file
aleksandraprohorova Oct 21, 2021
0086e98
remove comments
fyaraliyeva Oct 21, 2021
70835fe
Merge branch 'master' of github.com:aleksandraprohorova/java-junior
aleksandraprohorova Oct 21, 2021
5b13a45
Introduced abstract class NumberMessage to reduce duplication of over…
aleksandraprohorova Oct 22, 2021
179f98b
Removed redundant class
aleksandraprohorova Oct 22, 2021
a0a9d2b
Added tests for loggerController
aleksandraprohorova Oct 25, 2021
9fd5451
Added tests for loggerController
aleksandraprohorova Oct 25, 2021
9631e57
Fix Surefire version to run JUnit5 tests.
Oct 25, 2021
a306b52
Add test coverage report.
Oct 25, 2021
730e929
Add mutation testing report.
Oct 25, 2021
bb52be1
Fixed cherry-picking
aleksandraprohorova Oct 26, 2021
d4b6c58
Fixed results of changing maven
aleksandraprohorova Oct 26, 2021
f590fd4
Moved test to another package
aleksandraprohorova Oct 26, 2021
56b56ce
Enabled tests from previous iterations
aleksandraprohorova Oct 26, 2021
1e0c929
Refactored accumulate method to become not coupled with printer
aleksandraprohorova Oct 26, 2021
edaad6e
fix logger tests
fyaraliyeva Oct 26, 2021
195cbe9
Added tests for StringMessage
aleksandraprohorova Oct 26, 2021
f83dc19
Added test for stringMessage
aleksandraprohorova Oct 26, 2021
a55739b
Fixed tests
aleksandraprohorova Oct 27, 2021
f331875
Altered accumulator logic to get along without clone()
aleksandraprohorova Oct 27, 2021
463b251
Added concrete arguments to test asserts
aleksandraprohorova Oct 27, 2021
01f9ccd
Fixed codestyle
aleksandraprohorova Oct 27, 2021
a47e4fc
Made accumulator return the same message object that it received
aleksandraprohorova Oct 27, 2021
3c871d6
move duplications in tests to BeforeEach
fyaraliyeva Oct 27, 2021
efa2e66
Improved test coverage for StringMessage
aleksandraprohorova Oct 27, 2021
714e662
add test for null message to controller
fyaraliyeva Oct 28, 2021
96642c3
Added net functionality
aleksandraprohorova Oct 28, 2021
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
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Team members
- Aleksandra Prokhorova
- Fatima Yaraliyeva

# Java Junior Developer Training Course.
88 hours training + 32 hours work project = 120 hr.

Expand Down
93 changes: 88 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,101 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.7</version>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>verify</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.pitest</groupId>
<artifactId>pitest-maven</artifactId>
<version>1.7.2</version>
<dependencies>
<dependency>
<groupId>org.pitest</groupId>
<artifactId>pitest-junit5-plugin</artifactId>
<version>0.15</version>
</dependency>
</dependencies>
<configuration>
<targetClasses>
<param>com.acme.edu.*</param>
</targetClasses>
<targetTests>
<param>com.acme.edu.*</param>
</targetTests>
<verbose>true</verbose>
</configuration>
<executions>
<execution>
<id>mutation-coverage</id>
<goals>
<goal>mutationCoverage</goal>
</goals>
</execution>
<execution>
<id>mutation-report</id>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.21.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
<version>2.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>4.0.0</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/com/acme/edu/ConsolePrinter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.acme.edu;

import com.acme.edu.common.Message;
import com.acme.edu.common.Printer;

public class ConsolePrinter implements Printer {
@Override
public void print(Message message) {
System.out.println(message.getDecoratedString());
}
}
45 changes: 43 additions & 2 deletions src/main/java/com/acme/edu/Logger.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,52 @@
package com.acme.edu;

import com.acme.edu.messages.*;

import java.io.PrintStream;

public class Logger {
private static PrintStream out = System.out;

private static LoggerController controller = new LoggerController(new ConsolePrinter());


public static void flush() {
controller.flush();
}

public static void log(int message) {
System.out.println("primitive: " + message);
controller.log(new IntMessage(message));
}

public static void log(byte message) {
System.out.println("primitive: " + message);
controller.log(new ByteMessage(message));
}

public static void log(char message) {
controller.log(new CharMessage(message));
}

public static void log(String message) {
controller.log(new StringMessage(message));
}

public static void log(boolean message) {
controller.log(new BooleanMessage(message));
}

public static void log(Object message) {
controller.log(new ObjectMessage(message));
}

public static void log(int... array) {
controller.log(new IntArrayMessage(array));
}
public static void log(int[]... array) {
controller.log(new IntTwoDimensionalArrayMessage(array));
}
public static void log(String... array) {
for (String value: array) {
controller.log(new StringMessage(value));
}
}
}
41 changes: 41 additions & 0 deletions src/main/java/com/acme/edu/LoggerController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.acme.edu;

import com.acme.edu.common.Message;
import com.acme.edu.common.Printer;

public class LoggerController {
private Printer printer;
private Message oldMessage;

public LoggerController(Printer printer) {
this.printer = printer;
}

public void log(Message message){
if(message == null)
throw new IllegalArgumentException("Given message is null");

if (oldMessage == null) {
oldMessage = message;
return;
}
if (oldMessage.isSameType(message)) {
Message newMessage = oldMessage.accumulate(message);
if (newMessage != null) {
flush(newMessage);
}
} else {
flush(message);
}
}
public void flush() {
flush(null);
}

private void flush(Message newMessage) {
if (oldMessage != null) {
printer.print(oldMessage);
}
oldMessage = newMessage;
}
}
7 changes: 7 additions & 0 deletions src/main/java/com/acme/edu/common/Message.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.acme.edu.common;

public interface Message {
String getDecoratedString();
boolean isSameType(Message message);
Message accumulate(Message message);
}
5 changes: 5 additions & 0 deletions src/main/java/com/acme/edu/common/Printer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.acme.edu.common;

public interface Printer {
void print(Message message);
}
29 changes: 29 additions & 0 deletions src/main/java/com/acme/edu/messages/BooleanMessage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.acme.edu.messages;

import com.acme.edu.common.Message;

public class BooleanMessage implements Message {
private boolean value;

public BooleanMessage(boolean value) {
this.value = value;
}

@Override
public String getDecoratedString() {
return "boolean: " + value;
}

@Override
public boolean isSameType(Message message) {
return (message instanceof BooleanMessage);
}

@Override
public Message accumulate(Message message) {
if (!isSameType(message)) {
throw new IllegalArgumentException("Can not accumulate message which is not type of Boolean");
}
return this;
}
}
41 changes: 41 additions & 0 deletions src/main/java/com/acme/edu/messages/ByteMessage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.acme.edu.messages;

import com.acme.edu.common.Message;

public class ByteMessage extends NumberMessage {
private byte value;

public ByteMessage(byte message) {
value = message;
}

@Override
public String getDecoratedString() {
return "primitive: " + value;
}

@Override
public boolean isSameType(Message message) {
return (message instanceof ByteMessage);
}

@Override
protected long getValue() {
return value;
}

@Override
protected void setValue(long value) {
this.value = (byte) value;
}

@Override
protected long getMaxValue() {
return Byte.MAX_VALUE;
}

@Override
protected NumberMessage createNumberMessage(long value) {
return new ByteMessage((byte) value);
}
}
29 changes: 29 additions & 0 deletions src/main/java/com/acme/edu/messages/CharMessage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.acme.edu.messages;

import com.acme.edu.common.Message;

public class CharMessage implements Message {
private char value;

public CharMessage(char value) {
this.value = value;
}

@Override
public String getDecoratedString() {
return "char: " + value;
}

@Override
public boolean isSameType(Message message) {
return (message instanceof CharMessage);
}

@Override
public Message accumulate(Message message) {
if (!isSameType(message)) {
throw new IllegalArgumentException("Can not accumulate message which is not type of CharMessage");
}
return this;
}
}
37 changes: 37 additions & 0 deletions src/main/java/com/acme/edu/messages/IntArrayMessage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.acme.edu.messages;

import com.acme.edu.common.Message;

public class IntArrayMessage implements Message {
private int[] array;

public IntArrayMessage(int[] array) {
this.array = array;
}

@Override
public String getDecoratedString() {
return "arrays's sum: " + getSumOfArray(array);
}

@Override
public boolean isSameType(Message message) {
return message instanceof IntArrayMessage;
}

@Override
public Message accumulate(Message message) {
if (!isSameType(message)) {
throw new IllegalArgumentException("Can not accumulate message which is not type of IntArrayMessage");
}
return this;
}

protected int getSumOfArray(int... array) {
int sum = 0;
for (int value: array) {
sum += value;
}
return sum;
}
}
Loading