Java 11 migration: patterns (t-v) (#1085)
* Moves visitor pattern to java 11 * Moves value-object pattern to java 11 * Moves unit-of-work pattern to java 11 * Moves typeobjectpattern pattern to java 11 * Moves twin pattern to java 11 * Moves trampoline pattern to java 11 * Moves tolerant-reader pattern to java 11 * Moves tls pattern to java 11 * Moves throttling pattern to java 11 * Moves thread-pool pattern to java 11 * Moves template-method pattern to java 11
This commit is contained in:
		
				
					committed by
					
						
						Ilkka Seppälä
					
				
			
			
				
	
			
			
			
						parent
						
							160b737dcc
						
					
				
				
					commit
					50467c9e76
				
			@@ -82,15 +82,18 @@ public final class RainbowFishSerializer {
 | 
			
		||||
   * Read V1 RainbowFish from file.
 | 
			
		||||
   */
 | 
			
		||||
  public static RainbowFish readV1(String filename) throws IOException, ClassNotFoundException {
 | 
			
		||||
    Map<String, String> map = null;
 | 
			
		||||
    Map<String, String> map;
 | 
			
		||||
 | 
			
		||||
    try (var fileIn = new FileInputStream(filename);
 | 
			
		||||
         var objIn = new ObjectInputStream(fileIn)) {
 | 
			
		||||
      map = (Map<String, String>) objIn.readObject();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return new RainbowFish(map.get("name"), Integer.parseInt(map.get("age")), Integer
 | 
			
		||||
        .parseInt(map.get("lengthMeters")),
 | 
			
		||||
        Integer.parseInt(map.get("weightTons")));
 | 
			
		||||
    return new RainbowFish(
 | 
			
		||||
        map.get("name"),
 | 
			
		||||
        Integer.parseInt(map.get("age")),
 | 
			
		||||
        Integer.parseInt(map.get("lengthMeters")),
 | 
			
		||||
        Integer.parseInt(map.get("weightTons"))
 | 
			
		||||
    );
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -23,32 +23,28 @@
 | 
			
		||||
 | 
			
		||||
package com.iluwatar.tolerantreader;
 | 
			
		||||
 | 
			
		||||
import java.io.File;
 | 
			
		||||
import java.io.IOException;
 | 
			
		||||
import org.junit.jupiter.api.AfterEach;
 | 
			
		||||
import org.junit.jupiter.api.BeforeEach;
 | 
			
		||||
import org.junit.jupiter.api.Test;
 | 
			
		||||
 | 
			
		||||
import java.io.File;
 | 
			
		||||
import java.io.IOException;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * 
 | 
			
		||||
 * Application test
 | 
			
		||||
 *
 | 
			
		||||
 */
 | 
			
		||||
public class AppTest {
 | 
			
		||||
 | 
			
		||||
  @Test
 | 
			
		||||
  public void test() throws ClassNotFoundException, IOException {
 | 
			
		||||
    String[] args = {};
 | 
			
		||||
    App.main(args);
 | 
			
		||||
    App.main(new String[]{});
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @BeforeEach
 | 
			
		||||
  @AfterEach
 | 
			
		||||
  public void cleanup() {
 | 
			
		||||
    File file1 = new File("fish1.out");
 | 
			
		||||
    var file1 = new File("fish1.out");
 | 
			
		||||
    file1.delete();
 | 
			
		||||
    File file2 = new File("fish2.out");
 | 
			
		||||
    var file2 = new File("fish2.out");
 | 
			
		||||
    file2.delete();
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -23,16 +23,15 @@
 | 
			
		||||
 | 
			
		||||
package com.iluwatar.tolerantreader;
 | 
			
		||||
 | 
			
		||||
import static org.junit.jupiter.api.Assertions.assertEquals;
 | 
			
		||||
import static org.junit.jupiter.api.Assertions.assertNotSame;
 | 
			
		||||
 | 
			
		||||
import java.io.File;
 | 
			
		||||
import org.junit.Rule;
 | 
			
		||||
import org.junit.jupiter.api.Test;
 | 
			
		||||
import org.junit.jupiter.migrationsupport.rules.EnableRuleMigrationSupport;
 | 
			
		||||
import org.junit.rules.TemporaryFolder;
 | 
			
		||||
 | 
			
		||||
import java.io.File;
 | 
			
		||||
 | 
			
		||||
import static org.junit.jupiter.api.Assertions.assertEquals;
 | 
			
		||||
import static org.junit.jupiter.api.Assertions.assertNotSame;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Date: 12/30/15 - 18:39 PM
 | 
			
		||||
 *
 | 
			
		||||
@@ -62,10 +61,10 @@ public class RainbowFishSerializerTest {
 | 
			
		||||
   */
 | 
			
		||||
  @Test
 | 
			
		||||
  public void testWriteV1ReadV1() throws Exception {
 | 
			
		||||
    final File outputFile = this.testFolder.newFile();
 | 
			
		||||
    final var outputFile = this.testFolder.newFile();
 | 
			
		||||
    RainbowFishSerializer.writeV1(V1, outputFile.getPath());
 | 
			
		||||
 | 
			
		||||
    final RainbowFish fish = RainbowFishSerializer.readV1(outputFile.getPath());
 | 
			
		||||
    final var fish = RainbowFishSerializer.readV1(outputFile.getPath());
 | 
			
		||||
    assertNotSame(V1, fish);
 | 
			
		||||
    assertEquals(V1.getName(), fish.getName());
 | 
			
		||||
    assertEquals(V1.getAge(), fish.getAge());
 | 
			
		||||
@@ -79,10 +78,10 @@ public class RainbowFishSerializerTest {
 | 
			
		||||
   */
 | 
			
		||||
  @Test
 | 
			
		||||
  public void testWriteV2ReadV1() throws Exception {
 | 
			
		||||
    final File outputFile = this.testFolder.newFile();
 | 
			
		||||
    final var outputFile = this.testFolder.newFile();
 | 
			
		||||
    RainbowFishSerializer.writeV2(V2, outputFile.getPath());
 | 
			
		||||
 | 
			
		||||
    final RainbowFish fish = RainbowFishSerializer.readV1(outputFile.getPath());
 | 
			
		||||
    final var fish = RainbowFishSerializer.readV1(outputFile.getPath());
 | 
			
		||||
    assertNotSame(V2, fish);
 | 
			
		||||
    assertEquals(V2.getName(), fish.getName());
 | 
			
		||||
    assertEquals(V2.getAge(), fish.getAge());
 | 
			
		||||
 
 | 
			
		||||
@@ -23,10 +23,10 @@
 | 
			
		||||
 | 
			
		||||
package com.iluwatar.tolerantreader;
 | 
			
		||||
 | 
			
		||||
import org.junit.Test;
 | 
			
		||||
 | 
			
		||||
import static org.junit.Assert.assertEquals;
 | 
			
		||||
 | 
			
		||||
import org.junit.Test;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Date: 12/30/15 - 18:34 PM
 | 
			
		||||
 *
 | 
			
		||||
@@ -39,7 +39,7 @@ public class RainbowFishTest {
 | 
			
		||||
   */
 | 
			
		||||
  @Test
 | 
			
		||||
  public void testValues() {
 | 
			
		||||
    final RainbowFish fish = new RainbowFish("name", 1, 2, 3);
 | 
			
		||||
    final var fish = new RainbowFish("name", 1, 2, 3);
 | 
			
		||||
    assertEquals("name", fish.getName());
 | 
			
		||||
    assertEquals(1, fish.getAge());
 | 
			
		||||
    assertEquals(2, fish.getLengthMeters());
 | 
			
		||||
 
 | 
			
		||||
@@ -23,12 +23,12 @@
 | 
			
		||||
 | 
			
		||||
package com.iluwatar.tolerantreader;
 | 
			
		||||
 | 
			
		||||
import org.junit.Test;
 | 
			
		||||
 | 
			
		||||
import static org.junit.jupiter.api.Assertions.assertEquals;
 | 
			
		||||
import static org.junit.jupiter.api.Assertions.assertFalse;
 | 
			
		||||
import static org.junit.jupiter.api.Assertions.assertTrue;
 | 
			
		||||
 | 
			
		||||
import org.junit.Test;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Date: 12/30/15 - 18:35 PM
 | 
			
		||||
 *
 | 
			
		||||
@@ -41,7 +41,7 @@ public class RainbowFishV2Test {
 | 
			
		||||
   */
 | 
			
		||||
  @Test
 | 
			
		||||
  public void testValues() {
 | 
			
		||||
    final RainbowFishV2 fish = new RainbowFishV2("name", 1, 2, 3, false, true, false);
 | 
			
		||||
    final var fish = new RainbowFishV2("name", 1, 2, 3, false, true, false);
 | 
			
		||||
    assertEquals("name", fish.getName());
 | 
			
		||||
    assertEquals(1, fish.getAge());
 | 
			
		||||
    assertEquals(2, fish.getLengthMeters());
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user