Java 11 migraiton: memento

This commit is contained in:
Anurag Agarwal 2020-04-12 22:21:48 +00:00
parent 93e5570778
commit a00622c656
No known key found for this signature in database
GPG Key ID: CF5E14552DA23F13
5 changed files with 13 additions and 16 deletions

View File

@ -52,9 +52,9 @@ public class App {
* Program entry point.
*/
public static void main(String[] args) {
Stack<StarMemento> states = new Stack<>();
var states = new Stack<StarMemento>();
Star star = new Star(StarType.SUN, 10000000, 500000);
var star = new Star(StarType.SUN, 10000000, 500000);
LOGGER.info(star.toString());
states.add(star.getMemento());
star.timePasses();

View File

@ -71,7 +71,7 @@ public class Star {
StarMemento getMemento() {
StarMementoInternal state = new StarMementoInternal();
var state = new StarMementoInternal();
state.setAgeYears(ageYears);
state.setMassTons(massTons);
state.setType(type);
@ -81,7 +81,7 @@ public class Star {
void setMemento(StarMemento memento) {
StarMementoInternal state = (StarMementoInternal) memento;
var state = (StarMementoInternal) memento;
this.type = state.getType();
this.ageYears = state.getAgeYears();
this.massTons = state.getMassTons();

View File

@ -31,7 +31,7 @@ public enum StarType {
SUN("sun"), RED_GIANT("red giant"), WHITE_DWARF("white dwarf"), SUPERNOVA("supernova"), DEAD(
"dead star"), UNDEFINED("");
private String title;
private final String title;
StarType(String title) {
this.title = title;

View File

@ -26,15 +26,12 @@ package com.iluwatar.memento;
import org.junit.jupiter.api.Test;
/**
*
* Application test
*
*/
public class AppTest {
@Test
public void test() {
String[] args = {};
App.main(args);
App.main(new String[]{});
}
}

View File

@ -23,10 +23,10 @@
package com.iluwatar.memento;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test;
/**
* Date: 12/20/15 - 10:08 AM
*
@ -39,7 +39,7 @@ public class StarTest {
*/
@Test
public void testTimePasses() {
final Star star = new Star(StarType.SUN, 1, 2);
final var star = new Star(StarType.SUN, 1, 2);
assertEquals("sun age: 1 years mass: 2 tons", star.toString());
star.timePasses();
@ -66,16 +66,16 @@ public class StarTest {
*/
@Test
public void testSetMemento() {
final Star star = new Star(StarType.SUN, 1, 2);
final StarMemento firstMemento = star.getMemento();
final var star = new Star(StarType.SUN, 1, 2);
final var firstMemento = star.getMemento();
assertEquals("sun age: 1 years mass: 2 tons", star.toString());
star.timePasses();
final StarMemento secondMemento = star.getMemento();
final var secondMemento = star.getMemento();
assertEquals("red giant age: 2 years mass: 16 tons", star.toString());
star.timePasses();
final StarMemento thirdMemento = star.getMemento();
final var thirdMemento = star.getMemento();
assertEquals("white dwarf age: 4 years mass: 128 tons", star.toString());
star.timePasses();