Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Moves private-class-data to Java 11
  • Loading branch information
anuragagarwal561994 committed Dec 29, 2019
commit ba49532850250d950d4f935c2f74ce281b375848
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ public class App {
*/
public static void main(String[] args) {
// stew is mutable
Stew stew = new Stew(1, 2, 3, 4);
var stew = new Stew(1, 2, 3, 4);
stew.mix();
stew.taste();
stew.mix();

// immutable stew protected with Private Class Data pattern
ImmutableStew immutableStew = new ImmutableStew(2, 4, 3, 6);
var immutableStew = new ImmutableStew(2, 4, 3, 6);
immutableStew.mix();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,12 @@
import org.junit.jupiter.api.Test;

/**
*
* Application test
*
*/
public class AppTest {

@Test
public void test() {
String[] args = {};
App.main(args);
App.main(new String[]{});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@

package com.iluwatar.privateclassdata;

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

import com.iluwatar.privateclassdata.utils.InMemoryAppender;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

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

/**
* Date: 12/27/15 - 10:46 PM
*
Expand All @@ -54,10 +54,10 @@ public void tearDown() {
*/
@Test
public void testMix() {
final Stew stew = new Stew(1, 2, 3, 4);
final String expectedMessage = "Mixing the stew we find: 1 potatoes, 2 carrots, 3 meat and 4 peppers";
var stew = new Stew(1, 2, 3, 4);
var expectedMessage = "Mixing the stew we find: 1 potatoes, 2 carrots, 3 meat and 4 peppers";

for (int i = 0; i < 20; i++) {
for (var i = 0; i < 20; i++) {
stew.mix();
assertEquals(expectedMessage, appender.getLastMessage());
}
Expand All @@ -70,15 +70,17 @@ public void testMix() {
*/
@Test
public void testDrink() {
final Stew stew = new Stew(1, 2, 3, 4);
final var stew = new Stew(1, 2, 3, 4);
stew.mix();

assertEquals("Mixing the stew we find: 1 potatoes, 2 carrots, 3 meat and 4 peppers", appender.getLastMessage());
assertEquals("Mixing the stew we find: 1 potatoes, 2 carrots, 3 meat and 4 peppers", appender
.getLastMessage());

stew.taste();
assertEquals("Tasting the stew", appender.getLastMessage());
assertEquals("Tasting the stew", appender.getLastMessage());

stew.mix();
assertEquals("Mixing the stew we find: 0 potatoes, 1 carrots, 2 meat and 3 peppers", appender.getLastMessage());
assertEquals("Mixing the stew we find: 0 potatoes, 1 carrots, 2 meat and 3 peppers", appender
.getLastMessage());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@

package com.iluwatar.privateclassdata;

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

import com.iluwatar.privateclassdata.utils.InMemoryAppender;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

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

/**
* Date: 12/27/15 - 10:46 PM
*
Expand All @@ -54,11 +54,11 @@ public void tearDown() {
*/
@Test
public void testMix() {
final ImmutableStew stew = new ImmutableStew(1, 2, 3, 4);
final String expectedMessage = "Mixing the immutable stew we find: 1 potatoes, "
final var stew = new ImmutableStew(1, 2, 3, 4);
final var expectedMessage = "Mixing the immutable stew we find: 1 potatoes, "
+ "2 carrots, 3 meat and 4 peppers";

for (int i = 0; i < 20; i++) {
for (var i = 0; i < 20; i++) {
stew.mix();
assertEquals(expectedMessage, appender.getLastMessage());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,9 @@
import ch.qos.logback.classic.Logger;
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.AppenderBase;
import org.slf4j.LoggerFactory;

import java.util.LinkedList;
import java.util.List;
import org.slf4j.LoggerFactory;

/**
* InMemory Log Appender Util.
Expand Down