< Summary

Class:Tests.PoolManagerTests
Assembly:PoolManagerTests
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/PoolManager/Tests/PoolManagerTests.cs
Covered lines:51
Uncovered lines:1
Coverable lines:52
Total lines:111
Line coverage:98% (51 of 52)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Instantiate(...)0%110100%
IsValid(...)0%2100%
PoolManagerShouldHandleNullArgsGracefully()0%110100%
PooledGameObjectDestroyed()0%330100%
GetPoolableObject()0%110100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/PoolManager/Tests/PoolManagerTests.cs

#LineLine coverage
 1using DCL;
 2using NUnit.Framework;
 3using System.Collections;
 4using DCL.Components;
 5using DCL.Controllers;
 6using DCL.Helpers;
 7using DCL.Models;
 8using Newtonsoft.Json;
 9using UnityEngine;
 10using UnityEngine.TestTools;
 11
 12namespace Tests
 13{
 14    public class PoolManagerTests : IntegrationTestSuite_Legacy
 15    {
 16        public class PooledObjectInstantiator : IPooledObjectInstantiator
 17        {
 518            public GameObject Instantiate(GameObject go) { return GameObject.Instantiate(go); }
 19
 020            public bool IsValid(GameObject original) { return original != null; }
 21        }
 22
 23        [Test]
 24        public void PoolManagerShouldHandleNullArgsGracefully()
 25        {
 126            var thisShouldBeNull = PoolManager.i.GetPoolable(null);
 127            Assert.IsTrue(thisShouldBeNull == null);
 128        }
 29
 30        [UnityTest]
 31        public IEnumerator PooledGameObjectDestroyed()
 32        {
 133            PooledObjectInstantiator instantiator = new PooledObjectInstantiator();
 34
 135            GameObject original = new GameObject("Original");
 36
 137            object id = "testId";
 38
 139            Pool pool = PoolManager.i.AddPool(id, original, instantiator);
 140            Assert.IsNotNull(pool, "Pool instance shouldn't be null.");
 41
 142            PoolableObject po1 = PoolManager.i.Get(id);
 143            Assert.IsNotNull(po1, "Poolable object instance shouldn't be null.");
 144            po1.gameObject.SetActive(true);
 45
 146            Assert.IsTrue(po1.gameObject.activeSelf, "Poolable object should be alive.");
 47
 148            PoolableObject po2 = PoolManager.i.Get(id);
 149            Assert.IsNotNull(po2, "Poolable object instance shouldn't be null.");
 150            po2.gameObject.SetActive(true);
 51
 152            Assert.IsTrue(po2.gameObject.activeSelf, "Poolable object should be alive.");
 53
 154            pool = PoolManager.i.GetPool(id);
 155            Assert.IsNotNull(pool, "Pool instance shouldn't be null.");
 56
 157            Assert.AreEqual(2, pool.usedObjectsCount, "Alive objects count should be 2");
 158            Assert.AreEqual(0, pool.unusedObjectsCount, "Inactive objects count should be 0");
 59
 160            po1.Release();
 161            yield return null;
 62
 163            Assert.AreEqual(1, pool.usedObjectsCount, "Alive objects count should be 1");
 164            Assert.AreEqual(1, pool.unusedObjectsCount, "Inactive objects count should be 1");
 65
 166            PoolManager.i.Cleanup();
 67
 168            Assert.AreEqual(0, pool.usedObjectsCount, "Alive objects count should be 0");
 169            Assert.AreEqual(0, pool.unusedObjectsCount, "Inactive objects count should be 0");
 170        }
 71
 72        [Test]
 73        public void GetPoolableObject()
 74        {
 175            PooledObjectInstantiator instantiator = new PooledObjectInstantiator();
 76
 177            GameObject original = new GameObject("Original");
 78
 179            object id = "testId";
 80
 181            Pool pool = PoolManager.i.AddPool(id, original, instantiator);
 182            Assert.IsNotNull(pool, "Pool instance shouldn't be null.");
 83
 184            PoolableObject po1 = PoolManager.i.Get(id);
 185            Assert.IsNotNull(po1, "Poolable object instance shouldn't be null.");
 86
 187            PoolableObject po2 = PoolManager.i.Get(id);
 188            Assert.IsNotNull(po2, "Poolable object instance shouldn't be null.");
 89
 190            PoolableObject po3 = PoolManager.i.Get(id);
 191            Assert.IsNotNull(po3, "Poolable object instance shouldn't be null.");
 92
 193            Assert.AreEqual(3, pool.usedObjectsCount, "Alive objects count should be 3");
 194            Assert.AreEqual(0, pool.unusedObjectsCount, "Inactive objects count should be 0");
 95
 196            po3.Release();
 97
 198            Assert.AreEqual(2, pool.usedObjectsCount, "Alive objects count should be 2");
 199            Assert.AreEqual(1, pool.unusedObjectsCount, "Inactive objects count should be 1");
 100
 1101            PoolManager.i.ReleaseAllFromPool(id);
 102
 1103            Assert.AreEqual(0, pool.usedObjectsCount, "Alive objects count should be 0");
 1104            Assert.AreEqual(3, pool.unusedObjectsCount, "Inactive objects count should be 3");
 105
 1106            PoolManager.i.RemovePool(id);
 107
 1108            Assert.IsFalse(PoolManager.i.ContainsPool(id), "Pool shouldn't exist after disposal");
 1109        }
 110    }
 111}