Leon 6 лет назад
Сommit
6b0d9fcfa3
37 измененных файлов: 680 добавлений и 0 удалений
  1. 1
    0
      README.md
  2. 46
    0
      pom.xml
  3. 17
    0
      quiz-week7.iml
  4. 15
    0
      src/main/java/com/zipcodewilmington/generic/group/AbstractGroup.java
  5. 47
    0
      src/main/java/com/zipcodewilmington/generic/group/Group.java
  6. 30
    0
      src/main/java/com/zipcodewilmington/generic/group/GroupInterface.java
  7. 18
    0
      src/main/java/com/zipcodewilmington/generic/identifiables/ActionFigure.java
  8. 12
    0
      src/main/java/com/zipcodewilmington/generic/identifiables/IdentifiableInterface.java
  9. 18
    0
      src/main/java/com/zipcodewilmington/generic/identifiables/Person.java
  10. 73
    0
      src/test/java/com/zipcodewilmington/generic/ClassWrapper.java
  11. 51
    0
      src/test/java/com/zipcodewilmington/generic/group/CountTest.java
  12. 54
    0
      src/test/java/com/zipcodewilmington/generic/group/DeleteByIdTest.java
  13. 51
    0
      src/test/java/com/zipcodewilmington/generic/group/DeleteByValueTest.java
  14. 51
    0
      src/test/java/com/zipcodewilmington/generic/group/FilterTest.java
  15. 49
    0
      src/test/java/com/zipcodewilmington/generic/group/HasByIdTest.java
  16. 50
    0
      src/test/java/com/zipcodewilmington/generic/group/InsertTest.java
  17. 43
    0
      src/test/java/com/zipcodewilmington/generic/group/TestParameterization.java
  18. 14
    0
      src/test/java/com/zipcodewilmington/generic/group/TestPolymorphism.java
  19. 21
    0
      src/test/java/com/zipcodewilmington/generic/identifiables/ActionFigureTest.java
  20. 19
    0
      src/test/java/com/zipcodewilmington/generic/identifiables/PersonTest.java
  21. Двоичные данные
      target/classes/com/zipcodewilmington/generic/group/AbstractGroup.class
  22. Двоичные данные
      target/classes/com/zipcodewilmington/generic/group/Group.class
  23. Двоичные данные
      target/classes/com/zipcodewilmington/generic/group/GroupInterface.class
  24. Двоичные данные
      target/classes/com/zipcodewilmington/generic/identifiables/ActionFigure.class
  25. Двоичные данные
      target/classes/com/zipcodewilmington/generic/identifiables/IdentifiableInterface.class
  26. Двоичные данные
      target/classes/com/zipcodewilmington/generic/identifiables/Person.class
  27. Двоичные данные
      target/test-classes/com/zipcodewilmington/generic/ClassWrapper.class
  28. Двоичные данные
      target/test-classes/com/zipcodewilmington/generic/group/CountTest.class
  29. Двоичные данные
      target/test-classes/com/zipcodewilmington/generic/group/DeleteByIdTest.class
  30. Двоичные данные
      target/test-classes/com/zipcodewilmington/generic/group/DeleteByValueTest.class
  31. Двоичные данные
      target/test-classes/com/zipcodewilmington/generic/group/FilterTest.class
  32. Двоичные данные
      target/test-classes/com/zipcodewilmington/generic/group/HasByIdTest.class
  33. Двоичные данные
      target/test-classes/com/zipcodewilmington/generic/group/InsertTest.class
  34. Двоичные данные
      target/test-classes/com/zipcodewilmington/generic/group/TestParameterization.class
  35. Двоичные данные
      target/test-classes/com/zipcodewilmington/generic/group/TestPolymorphism.class
  36. Двоичные данные
      target/test-classes/com/zipcodewilmington/generic/identifiables/ActionFigureTest.class
  37. Двоичные данные
      target/test-classes/com/zipcodewilmington/generic/identifiables/PersonTest.class

+ 1
- 0
README.md Просмотреть файл

@@ -0,0 +1 @@
1
+# Generics Lab

+ 46
- 0
pom.xml Просмотреть файл

@@ -0,0 +1,46 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<project xmlns="http://maven.apache.org/POM/4.0.0"
3
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5
+    <modelVersion>4.0.0</modelVersion>
6
+
7
+    <groupId>com.zipcodewilmington</groupId>
8
+    <artifactId>quiz2</artifactId>
9
+    <version>1.0-SNAPSHOT</version>
10
+
11
+    <properties>
12
+        <maven.compiler.source>1.8</maven.compiler.source>
13
+        <maven.compiler.target>1.8</maven.compiler.target>
14
+    </properties>
15
+
16
+
17
+    <repositories>
18
+        <repository>
19
+            <id>git-leon-utils</id>
20
+            <url>https://packagecloud.io/git-leon/utils/maven2</url>
21
+            <releases>
22
+                <enabled>true</enabled>
23
+            </releases>
24
+            <snapshots>
25
+                <enabled>true</enabled>
26
+            </snapshots>
27
+        </repository>
28
+    </repositories>
29
+
30
+
31
+
32
+
33
+    <dependencies>
34
+        <dependency>
35
+            <groupId>com.github.git-leon</groupId>
36
+            <artifactId>collectionutils</artifactId>
37
+            <version>1.5</version>
38
+        </dependency>
39
+        <dependency>
40
+            <groupId>junit</groupId>
41
+            <artifactId>junit</artifactId>
42
+            <version>4.12</version>
43
+        </dependency>
44
+    </dependencies>
45
+
46
+</project>

+ 17
- 0
quiz-week7.iml Просмотреть файл

@@ -0,0 +1,17 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
3
+  <component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
4
+    <output url="file://$MODULE_DIR$/target/classes" />
5
+    <output-test url="file://$MODULE_DIR$/target/test-classes" />
6
+    <content url="file://$MODULE_DIR$">
7
+      <sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
8
+      <sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
9
+      <excludeFolder url="file://$MODULE_DIR$/target" />
10
+    </content>
11
+    <orderEntry type="inheritedJdk" />
12
+    <orderEntry type="sourceFolder" forTests="false" />
13
+    <orderEntry type="library" name="Maven: com.github.git-leon:collectionutils:1.5" level="project" />
14
+    <orderEntry type="library" name="Maven: junit:junit:4.12" level="project" />
15
+    <orderEntry type="library" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
16
+  </component>
17
+</module>

+ 15
- 0
src/main/java/com/zipcodewilmington/generic/group/AbstractGroup.java Просмотреть файл

@@ -0,0 +1,15 @@
1
+package com.zipcodewilmington.generic.group;
2
+
3
+import com.zipcodewilmington.generic.identifiables.IdentifiableInterface;
4
+
5
+import java.io.Serializable;
6
+
7
+/**
8
+ * @author leon on 05/12/2018.
9
+ */
10
+abstract public class AbstractGroup<
11
+        TypeOfId extends Serializable,
12
+        TypeOfEntity extends IdentifiableInterface<TypeOfId>>
13
+        implements GroupInterface<TypeOfId, TypeOfEntity> {
14
+
15
+}

+ 47
- 0
src/main/java/com/zipcodewilmington/generic/group/Group.java Просмотреть файл

@@ -0,0 +1,47 @@
1
+package com.zipcodewilmington.generic.group;
2
+
3
+import com.zipcodewilmington.generic.identifiables.IdentifiableInterface;
4
+
5
+import java.io.Serializable;
6
+import java.util.List;
7
+import java.util.function.Predicate;
8
+
9
+/**
10
+ * @author leon on 06/12/2018.
11
+ */
12
+public class Group<ChangeThisTypeRespectively,ChangeThisOneToo> extends AbstractGroup{
13
+    @Override
14
+    public Integer count() {
15
+        return null;
16
+    }
17
+
18
+    @Override
19
+    public void insert(IdentifiableInterface object) {
20
+
21
+    }
22
+
23
+    @Override
24
+    public void delete(IdentifiableInterface object) {
25
+
26
+    }
27
+
28
+    @Override
29
+    public void delete(Serializable serializable) {
30
+
31
+    }
32
+
33
+    @Override
34
+    public Boolean has(IdentifiableInterface object) {
35
+        return null;
36
+    }
37
+
38
+    @Override
39
+    public Boolean has(Serializable serializable) {
40
+        return null;
41
+    }
42
+
43
+    @Override
44
+    public List filter(Predicate predicate) {
45
+        return null;
46
+    }
47
+}

+ 30
- 0
src/main/java/com/zipcodewilmington/generic/group/GroupInterface.java Просмотреть файл

@@ -0,0 +1,30 @@
1
+package com.zipcodewilmington.generic.group;
2
+
3
+import com.zipcodewilmington.generic.identifiables.IdentifiableInterface;
4
+
5
+import java.io.Serializable;
6
+import java.util.List;
7
+import java.util.function.Predicate;
8
+
9
+/**
10
+ * @author leon on 05/12/2018.
11
+ * @ATTENTION_TO_STUDENTS - You are forbidden from modifying this interface
12
+ */
13
+public interface GroupInterface<
14
+        TypeOfId extends Serializable,
15
+        TypeOfEntity extends IdentifiableInterface<TypeOfId>> {
16
+
17
+   Integer count();
18
+
19
+   void insert(TypeOfEntity object);
20
+    
21
+   void delete(TypeOfEntity object);
22
+
23
+   void delete(TypeOfId id);
24
+
25
+   Boolean has(TypeOfEntity object);
26
+
27
+   Boolean has(TypeOfId id);
28
+
29
+   List<TypeOfEntity> filter(Predicate<TypeOfEntity> predicate);
30
+}

+ 18
- 0
src/main/java/com/zipcodewilmington/generic/identifiables/ActionFigure.java Просмотреть файл

@@ -0,0 +1,18 @@
1
+package com.zipcodewilmington.generic.identifiables;
2
+
3
+import java.io.Serializable;
4
+
5
+/**
6
+ * @author leon on 05/12/2018.
7
+ */
8
+public class ActionFigure implements IdentifiableInterface {
9
+
10
+    @Override
11
+    public Serializable getIdentity() {
12
+        return null;
13
+    }
14
+
15
+    public Class getIdentityType() {
16
+        return null;
17
+    }
18
+}

+ 12
- 0
src/main/java/com/zipcodewilmington/generic/identifiables/IdentifiableInterface.java Просмотреть файл

@@ -0,0 +1,12 @@
1
+package com.zipcodewilmington.generic.identifiables;
2
+
3
+import java.io.Serializable;
4
+
5
+/**
6
+ * @author leon on 05/12/2018.
7
+ * @ATTENTION_TO_STUDENTS - You are forbidden from modifying this interface
8
+ */
9
+public interface IdentifiableInterface<TypeOfId extends Serializable> {
10
+    TypeOfId getIdentity();
11
+    Class<? extends TypeOfId> getIdentityType();
12
+}

+ 18
- 0
src/main/java/com/zipcodewilmington/generic/identifiables/Person.java Просмотреть файл

@@ -0,0 +1,18 @@
1
+package com.zipcodewilmington.generic.identifiables;
2
+
3
+import java.io.Serializable;
4
+
5
+/**
6
+ * @author leon on 05/12/2018.
7
+ */
8
+public class Person implements IdentifiableInterface {
9
+
10
+    @Override
11
+    public Serializable getIdentity() {
12
+        return null;
13
+    }
14
+
15
+    public Class getIdentityType() {
16
+        return null;
17
+    }
18
+}

+ 73
- 0
src/test/java/com/zipcodewilmington/generic/ClassWrapper.java Просмотреть файл

@@ -0,0 +1,73 @@
1
+package com.zipcodewilmington.generic;
2
+
3
+/**
4
+ * @author leon on 06/12/2018.
5
+ */
6
+
7
+import com.github.git_leon.collectionutils.maps.IntrospectiveMap;
8
+import sun.reflect.generics.reflectiveObjects.TypeVariableImpl;
9
+import sun.reflect.generics.tree.FieldTypeSignature;
10
+import sun.reflect.generics.tree.SimpleClassTypeSignature;
11
+
12
+import java.lang.reflect.Field;
13
+import java.lang.reflect.ParameterizedType;
14
+import java.lang.reflect.Type;
15
+import java.util.List;
16
+import java.util.Map;
17
+
18
+/**
19
+ * @author leon on 05/12/2018.
20
+ * This class exists for testing purposes
21
+ */
22
+public class ClassWrapper {
23
+    private final TypeVariableImpl type;
24
+    private final Object object;
25
+
26
+    public ClassWrapper(Object o, int parameterizedIndex) {
27
+        Class<?>  cls = o.getClass();
28
+        Type superType = cls.getGenericSuperclass();
29
+        ParameterizedType parameterizedClassType = (ParameterizedType)superType;
30
+        Type[] parameterizedTypes = parameterizedClassType.getActualTypeArguments();
31
+        Type typeOfClassParameterization = parameterizedTypes[parameterizedIndex];
32
+        this.object = o;
33
+        this.type = (TypeVariableImpl) typeOfClassParameterization;
34
+    }
35
+
36
+    private Field getBoundASTsAsField() {
37
+        Field f = null;
38
+        try {
39
+            f = type.getClass().getDeclaredField("boundASTs");
40
+            f.setAccessible(true);
41
+        } catch (Throwable e) {
42
+            throw new Error(e);
43
+        }
44
+        return f;
45
+    }
46
+
47
+    public String getParameterizedType(){
48
+        Field boundASTs = getBoundASTsAsField();
49
+        FieldTypeSignature[] f;
50
+        try {
51
+            f = (FieldTypeSignature[]) boundASTs.get(type);
52
+            return getUpperBoundOfType(f);
53
+        } catch (IllegalAccessException e) {
54
+            throw new Error(e);
55
+        }
56
+    }
57
+
58
+
59
+    private String getUpperBoundOfType(FieldTypeSignature[] fieldTypeSignatures) {
60
+        try {
61
+            FieldTypeSignature fieldTypeSignature = fieldTypeSignatures[0];
62
+            Class<? extends FieldTypeSignature> clss = fieldTypeSignature.getClass();
63
+            Field field = clss.getDeclaredField("path");
64
+            field.setAccessible(true);
65
+            List<? extends SimpleClassTypeSignature> list = (List<? extends SimpleClassTypeSignature>) field.get(fieldTypeSignature);
66
+            Map m = new IntrospectiveMap(list.get(0));
67
+            return m.get("name").toString();
68
+        } catch (Throwable e) {
69
+            throw new Error(e);
70
+        }
71
+    }
72
+}
73
+

+ 51
- 0
src/test/java/com/zipcodewilmington/generic/group/CountTest.java Просмотреть файл

@@ -0,0 +1,51 @@
1
+package com.zipcodewilmington.generic.group;
2
+
3
+import com.zipcodewilmington.generic.identifiables.ActionFigure;
4
+import com.zipcodewilmington.generic.identifiables.IdentifiableInterface;
5
+import com.zipcodewilmington.generic.identifiables.Person;
6
+import org.junit.Assert;
7
+import org.junit.Test;
8
+
9
+import java.io.Serializable;
10
+import java.util.Random;
11
+import java.util.function.Supplier;
12
+
13
+/**
14
+ * @author leon on 05/12/2018.
15
+ */
16
+public class CountTest {
17
+    @Test
18
+    public void test1() {
19
+        test(1);
20
+    }
21
+
22
+    @Test
23
+    public void test2() {
24
+        test(2);
25
+    }
26
+
27
+    @Test
28
+    public void testRandom() {
29
+        test(Math.abs(new Random().nextInt()));
30
+    }
31
+
32
+    private void test(Integer numberOfObjectsToAdd) {
33
+        test(numberOfObjectsToAdd, Person::new);
34
+        test(numberOfObjectsToAdd, ActionFigure::new);
35
+    }
36
+
37
+    private <TypeOfId extends Serializable> void test(Integer numberOfObjectsToAdd, Supplier<IdentifiableInterface<TypeOfId>> supplier) {
38
+        // Given
39
+        Group<TypeOfId, IdentifiableInterface<TypeOfId>> group = new Group<>();
40
+
41
+        // when
42
+        for (int i = 0; i < numberOfObjectsToAdd; i++) {
43
+            IdentifiableInterface<TypeOfId> identifiable = supplier.get();
44
+            group.insert(identifiable);
45
+
46
+            // then
47
+            Assert.assertEquals(group.count().intValue(), i + 1);
48
+        }
49
+    }
50
+
51
+}

+ 54
- 0
src/test/java/com/zipcodewilmington/generic/group/DeleteByIdTest.java Просмотреть файл

@@ -0,0 +1,54 @@
1
+package com.zipcodewilmington.generic.group;
2
+
3
+import com.zipcodewilmington.generic.identifiables.ActionFigure;
4
+import com.zipcodewilmington.generic.identifiables.IdentifiableInterface;
5
+import com.zipcodewilmington.generic.identifiables.Person;
6
+import org.junit.Assert;
7
+import org.junit.Test;
8
+
9
+import java.io.Serializable;
10
+import java.util.Random;
11
+import java.util.function.Supplier;
12
+
13
+/**
14
+ * @author leon on 05/12/2018.
15
+ */
16
+public class DeleteByIdTest {
17
+    @Test
18
+    public void test1() {
19
+        test(1);
20
+    }
21
+
22
+    @Test
23
+    public void test2() {
24
+        test(2);
25
+    }
26
+
27
+    @Test
28
+    public void testRandom() {
29
+        test(Math.abs(new Random().nextInt()));
30
+    }
31
+
32
+    private void test(Integer numberOfObjectsToAdd) {
33
+        test(numberOfObjectsToAdd, Person::new);
34
+        test(numberOfObjectsToAdd, ActionFigure::new);
35
+    }
36
+
37
+    private <TypeOfId extends Serializable> void test(Integer numberOfObjectsToAdd, Supplier<IdentifiableInterface<TypeOfId>> supplier) {
38
+        // Given
39
+        Group<TypeOfId, IdentifiableInterface<TypeOfId>> group = new Group<>();
40
+
41
+        // when
42
+        for (int i = 0; i < numberOfObjectsToAdd; i++) {
43
+            IdentifiableInterface<TypeOfId> identifiable = supplier.get();
44
+            group.insert(identifiable);
45
+            if(!group.has(identifiable)) {
46
+                throw new UnsupportedOperationException("`.insert` has not yet been implemented");
47
+            }
48
+
49
+            // then
50
+            group.delete(identifiable.getIdentity());
51
+            Assert.assertFalse(group.has(identifiable));
52
+        }
53
+    }
54
+}

+ 51
- 0
src/test/java/com/zipcodewilmington/generic/group/DeleteByValueTest.java Просмотреть файл

@@ -0,0 +1,51 @@
1
+package com.zipcodewilmington.generic.group;
2
+
3
+import com.zipcodewilmington.generic.identifiables.ActionFigure;
4
+import com.zipcodewilmington.generic.identifiables.IdentifiableInterface;
5
+import com.zipcodewilmington.generic.identifiables.Person;
6
+import org.junit.Assert;
7
+import org.junit.Test;
8
+
9
+import java.io.Serializable;
10
+import java.util.Random;
11
+import java.util.function.Supplier;
12
+
13
+/**
14
+ * @author leon on 05/12/2018.
15
+ */
16
+public class DeleteByValueTest {
17
+    @Test
18
+    public void test1() {
19
+        test(1);
20
+    }
21
+
22
+    @Test
23
+    public void test2() {
24
+        test(2);
25
+    }
26
+
27
+    @Test
28
+    public void testRandom() {
29
+        test(Math.abs(new Random().nextInt()));
30
+    }
31
+
32
+    private void test(Integer numberOfObjectsToAdd) {
33
+        test(numberOfObjectsToAdd, Person::new);
34
+        test(numberOfObjectsToAdd, ActionFigure::new);
35
+    }
36
+
37
+    private <TypeOfId extends Serializable> void test(Integer numberOfObjectsToAdd, Supplier<IdentifiableInterface<TypeOfId>> supplier) {
38
+        // Given
39
+        Group<TypeOfId, IdentifiableInterface<TypeOfId>> group = new Group<>();
40
+
41
+        // when
42
+        for (int i = 0; i < numberOfObjectsToAdd; i++) {
43
+            IdentifiableInterface<TypeOfId> identifiable = supplier.get();
44
+            group.insert(identifiable);
45
+            group.delete(identifiable);
46
+
47
+            // then
48
+            Assert.assertFalse(group.has(identifiable));
49
+        }
50
+    }
51
+}

+ 51
- 0
src/test/java/com/zipcodewilmington/generic/group/FilterTest.java Просмотреть файл

@@ -0,0 +1,51 @@
1
+package com.zipcodewilmington.generic.group;
2
+
3
+import com.zipcodewilmington.generic.identifiables.ActionFigure;
4
+import com.zipcodewilmington.generic.identifiables.IdentifiableInterface;
5
+import com.zipcodewilmington.generic.identifiables.Person;
6
+import org.junit.Assert;
7
+import org.junit.Test;
8
+
9
+import java.io.Serializable;
10
+import java.util.Random;
11
+import java.util.function.Supplier;
12
+
13
+/**
14
+ * @author leon on 05/12/2018.
15
+ */
16
+public class FilterTest {
17
+    @Test
18
+    public void test1() {
19
+        test(1);
20
+    }
21
+
22
+    @Test
23
+    public void test2() {
24
+        test(2);
25
+    }
26
+
27
+    @Test
28
+    public void testRandom() {
29
+        test(Math.abs(new Random().nextInt()));
30
+    }
31
+
32
+
33
+    private void test(Integer numberOfObjectsToAdd) {
34
+        test(numberOfObjectsToAdd, Person::new);
35
+        test(numberOfObjectsToAdd, ActionFigure::new);
36
+    }
37
+
38
+    private <TypeOfId extends Serializable> void test(Integer numberOfObjectsToAdd, Supplier<IdentifiableInterface<TypeOfId>> supplier) {
39
+        // Given
40
+        Group<TypeOfId, IdentifiableInterface<TypeOfId>> group = new Group<>();
41
+
42
+        // when
43
+        for (int i = 0; i < numberOfObjectsToAdd; i++) {
44
+            IdentifiableInterface<TypeOfId> identifiable = supplier.get();
45
+            group.insert(identifiable);
46
+
47
+            // then
48
+            Assert.assertFalse(group.filter(obj -> ((IdentifiableInterface)(obj)).getIdentity().equals(identifiable)).contains(identifiable));
49
+        }
50
+    }
51
+}

+ 49
- 0
src/test/java/com/zipcodewilmington/generic/group/HasByIdTest.java Просмотреть файл

@@ -0,0 +1,49 @@
1
+package com.zipcodewilmington.generic.group;
2
+
3
+import com.zipcodewilmington.generic.identifiables.ActionFigure;
4
+import com.zipcodewilmington.generic.identifiables.IdentifiableInterface;
5
+import com.zipcodewilmington.generic.identifiables.Person;
6
+import org.junit.Assert;
7
+import org.junit.Test;
8
+
9
+import java.io.Serializable;
10
+import java.util.Random;
11
+import java.util.function.Supplier;
12
+
13
+/**
14
+ * @author leon on 05/12/2018.
15
+ */
16
+public class HasByIdTest {
17
+    @Test
18
+    public void test1() {
19
+        test(1);
20
+    }
21
+
22
+    @Test
23
+    public void test2() {
24
+        test(2);
25
+    }
26
+
27
+    @Test
28
+    public void testRandom() {
29
+        test(Math.abs(new Random().nextInt()));
30
+    }
31
+
32
+    private void test(Integer numberOfObjectsToAdd) {
33
+        test(numberOfObjectsToAdd, Person::new);
34
+        test(numberOfObjectsToAdd, ActionFigure::new);
35
+    }
36
+
37
+    private <TypeOfId extends Serializable> void test(Integer numberOfObjectsToAdd, Supplier<IdentifiableInterface<TypeOfId>> supplier) {
38
+        // Given
39
+        Group<TypeOfId, IdentifiableInterface<TypeOfId>> group = new Group<>();
40
+
41
+        // when
42
+        for (int i = 0; i < numberOfObjectsToAdd; i++) {
43
+            IdentifiableInterface<TypeOfId> identifiable = supplier.get();
44
+            group.insert(identifiable);
45
+            // then
46
+            Assert.assertFalse(group.has(identifiable.getIdentity()));
47
+        }
48
+    }
49
+}

+ 50
- 0
src/test/java/com/zipcodewilmington/generic/group/InsertTest.java Просмотреть файл

@@ -0,0 +1,50 @@
1
+package com.zipcodewilmington.generic.group;
2
+
3
+import com.zipcodewilmington.generic.identifiables.ActionFigure;
4
+import com.zipcodewilmington.generic.identifiables.IdentifiableInterface;
5
+import com.zipcodewilmington.generic.identifiables.Person;
6
+import org.junit.Assert;
7
+import org.junit.Test;
8
+
9
+import java.io.Serializable;
10
+import java.util.Random;
11
+import java.util.function.Supplier;
12
+
13
+/**
14
+ * @author leon on 05/12/2018.
15
+ */
16
+public class InsertTest {
17
+    @Test
18
+    public void test1() {
19
+        test(1);
20
+    }
21
+
22
+    @Test
23
+    public void test2() {
24
+        test(2);
25
+    }
26
+
27
+    @Test
28
+    public void testRandom() {
29
+        test(Math.abs(new Random().nextInt()));
30
+    }
31
+
32
+    private void test(Integer numberOfObjectsToAdd) {
33
+        test(numberOfObjectsToAdd, Person::new);
34
+        test(numberOfObjectsToAdd, ActionFigure::new);
35
+    }
36
+
37
+    private <TypeOfId extends Serializable> void test(Integer numberOfObjectsToAdd, Supplier<IdentifiableInterface<TypeOfId>> supplier) {
38
+        // Given
39
+        Group<TypeOfId, IdentifiableInterface<TypeOfId>> group = new Group<>();
40
+
41
+        // when
42
+        for (int i = 0; i < numberOfObjectsToAdd; i++) {
43
+            IdentifiableInterface<TypeOfId> identifiable = supplier.get();
44
+            group.insert(identifiable);
45
+
46
+            // then
47
+            Assert.assertFalse(group.has(identifiable));
48
+        }
49
+    }
50
+}

+ 43
- 0
src/test/java/com/zipcodewilmington/generic/group/TestParameterization.java Просмотреть файл

@@ -0,0 +1,43 @@
1
+package com.zipcodewilmington.generic.group;
2
+
3
+import com.zipcodewilmington.generic.ClassWrapper;
4
+import com.zipcodewilmington.generic.identifiables.ActionFigure;
5
+import com.zipcodewilmington.generic.identifiables.Person;
6
+import org.junit.Assert;
7
+import org.junit.Test;
8
+
9
+/**
10
+ * @author leon on 05/12/2018.
11
+ */
12
+public class TestParameterization {
13
+    @Test
14
+    public void testStringAndPersonParameterization() {
15
+        Group<String, Person> personGroup = new Group<>();
16
+        String expectedIdentityType = "java.io.Serializable";
17
+        String expectedIdentifiableType = "com.zipcodewilmington.generic.identifiables.IdentifiableInterface";
18
+
19
+        String actualIdentityType = getParameterizedType(personGroup, 0);
20
+        String actualIdentifiableType = getParameterizedType(personGroup, 1);
21
+
22
+        Assert.assertEquals(expectedIdentifiableType, actualIdentifiableType);
23
+        Assert.assertEquals(expectedIdentityType, actualIdentityType);
24
+    }
25
+
26
+
27
+    @Test
28
+    public void testLongAndActionFigureParameterization() {
29
+        Group<Long, ActionFigure> group = new Group<>();
30
+        String expectedIdentityType = "java.io.Serializable";
31
+        String expectedIdentifiableType = "com.zipcodewilmington.generic.identifiables.IdentifiableInterface";
32
+
33
+        String actualIdentityType = getParameterizedType(group, 0);
34
+        String actualIdentifiableType = getParameterizedType(group, 1);
35
+
36
+        Assert.assertEquals(expectedIdentifiableType, actualIdentifiableType);
37
+        Assert.assertEquals(expectedIdentityType, actualIdentityType);
38
+    }
39
+
40
+    public String getParameterizedType(Object o, int parameterizedIndex) {
41
+        return new ClassWrapper(o, parameterizedIndex).getParameterizedType();
42
+    }
43
+}

+ 14
- 0
src/test/java/com/zipcodewilmington/generic/group/TestPolymorphism.java Просмотреть файл

@@ -0,0 +1,14 @@
1
+package com.zipcodewilmington.generic.group;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+
6
+/**
7
+ * @author leon on 05/12/2018.
8
+ */
9
+public class TestPolymorphism {
10
+    @Test
11
+    public void testImplementation() {
12
+        Assert.assertTrue(new Group<>() instanceof GroupInterface);
13
+    }
14
+}

+ 21
- 0
src/test/java/com/zipcodewilmington/generic/identifiables/ActionFigureTest.java Просмотреть файл

@@ -0,0 +1,21 @@
1
+package com.zipcodewilmington.generic.identifiables;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+
6
+/**
7
+ * @author leon on 06/12/2018.
8
+ */
9
+public class ActionFigureTest {
10
+    ActionFigure actionFigure = new ActionFigure();
11
+
12
+    @Test
13
+    public void testImplementation() {
14
+        Assert.assertTrue(actionFigure instanceof IdentifiableInterface);
15
+    }
16
+
17
+    @Test
18
+    public void testGetIdentityType() {
19
+        Assert.assertEquals(actionFigure.getIdentityType(), Long.class);
20
+    }
21
+}

+ 19
- 0
src/test/java/com/zipcodewilmington/generic/identifiables/PersonTest.java Просмотреть файл

@@ -0,0 +1,19 @@
1
+package com.zipcodewilmington.generic.identifiables;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+
6
+/**
7
+ * @author leon on 06/12/2018.
8
+ */
9
+public class PersonTest {
10
+    @Test
11
+    public void testImplementation() {
12
+        Assert.assertTrue(new Person() instanceof IdentifiableInterface);
13
+    }
14
+
15
+    @Test
16
+    public void testGetIdentityType() {
17
+        Assert.assertEquals(new Person().getIdentityType(), String.class);
18
+    }
19
+}

Двоичные данные
target/classes/com/zipcodewilmington/generic/group/AbstractGroup.class Просмотреть файл


Двоичные данные
target/classes/com/zipcodewilmington/generic/group/Group.class Просмотреть файл


Двоичные данные
target/classes/com/zipcodewilmington/generic/group/GroupInterface.class Просмотреть файл


Двоичные данные
target/classes/com/zipcodewilmington/generic/identifiables/ActionFigure.class Просмотреть файл


Двоичные данные
target/classes/com/zipcodewilmington/generic/identifiables/IdentifiableInterface.class Просмотреть файл


Двоичные данные
target/classes/com/zipcodewilmington/generic/identifiables/Person.class Просмотреть файл


Двоичные данные
target/test-classes/com/zipcodewilmington/generic/ClassWrapper.class Просмотреть файл


Двоичные данные
target/test-classes/com/zipcodewilmington/generic/group/CountTest.class Просмотреть файл


Двоичные данные
target/test-classes/com/zipcodewilmington/generic/group/DeleteByIdTest.class Просмотреть файл


Двоичные данные
target/test-classes/com/zipcodewilmington/generic/group/DeleteByValueTest.class Просмотреть файл


Двоичные данные
target/test-classes/com/zipcodewilmington/generic/group/FilterTest.class Просмотреть файл


Двоичные данные
target/test-classes/com/zipcodewilmington/generic/group/HasByIdTest.class Просмотреть файл


Двоичные данные
target/test-classes/com/zipcodewilmington/generic/group/InsertTest.class Просмотреть файл


Двоичные данные
target/test-classes/com/zipcodewilmington/generic/group/TestParameterization.class Просмотреть файл


Двоичные данные
target/test-classes/com/zipcodewilmington/generic/group/TestPolymorphism.class Просмотреть файл


Двоичные данные
target/test-classes/com/zipcodewilmington/generic/identifiables/ActionFigureTest.class Просмотреть файл


Двоичные данные
target/test-classes/com/zipcodewilmington/generic/identifiables/PersonTest.class Просмотреть файл