mil.dod.th.ose.core/test/mil/dod/th/ose/core/impl/pm/TestPowerManagerImpl.java
@Test
    public void testGetWakeLocksContextWakeLockState()
    {
        WakeLock lock1 = m_SUT.createWakeLock(TestContext1.class, "lock");
        when(lock1.getId()).thenReturn("lock");
        doReturn(TestContext1.class).when(lock1).getContext();

        WakeLock lock2 = m_SUT.createWakeLock(TestContext2.class, "lock");
        when(lock2.getId()).thenReturn("lock");
        doReturn(TestContext2.class).when(lock2).getContext();

        WakeLock lock3 = m_SUT.createWakeLock(TestContext3.class, "lock");
        when(lock3.getId()).thenReturn("lock");
        doReturn(TestContext3.class).when(lock3).getContext();

        FactoryObject sourceObject = mockFactoryObject();
        WakeLock lock4 = m_SUT.createWakeLock(FactoryObjectProxy.class, sourceObject, "lock");
        when(lock4.getId()).thenReturn("lock");
        when(lock4.getSourceObject()).thenReturn(sourceObject);
        doReturn(FactoryObjectProxy.class).when(lock4).getContext();

        Set<WakeLock> activeLocks = new HashSet<WakeLock>();
        activeLocks.add(lock1);
        Set<WakeLock> inactiveLocks = new HashSet<WakeLock>();
        inactiveLocks.add(lock2);
        inactiveLocks.add(lock4);
        Set<WakeLock> schedLocks = new HashSet<WakeLock>();
        schedLocks.add(lock3);

        when(m_PPM.getActiveWakeLocks()).thenReturn(activeLocks);
        when(m_PPM.getScheduledWakeLocks()).thenReturn(schedLocks);

        Set<WakeLock> returnedLocks = m_SUT.getWakeLocks(TestContext1.class, WakeLockState.Any);
        assertThat(returnedLocks, hasItem(lock1));
        assertThat(returnedLocks.size(), is(1));
        
        returnedLocks = m_SUT.getWakeLocks(TestContext1.class, WakeLockState.Active);
        assertThat(returnedLocks, hasItem(lock1));
        assertThat(returnedLocks.size(), is(1));
        
        returnedLocks = m_SUT.getWakeLocks(TestContext2.class, WakeLockState.Inactive);
        assertThat(returnedLocks, hasItem(lock2));
        assertThat(returnedLocks.size(), is(1));
        
        returnedLocks = m_SUT.getWakeLocks(FactoryObjectProxy.class, WakeLockState.Inactive);
        assertThat(returnedLocks, hasItem(lock4));
        assertThat(returnedLocks.size(), is(1));
        
        returnedLocks = m_SUT.getWakeLocks(TestContext3.class, WakeLockState.Scheduled);
        assertThat(returnedLocks, hasItem(lock3));
        assertThat(returnedLocks.size(), is(1));
        
        // Verify with no PlatformPowerManager
        m_SUT.unsetPlatformPowerManager(m_PPM);

        returnedLocks = m_SUT.getWakeLocks(TestContext1.class, WakeLockState.Active);
        assertThat(returnedLocks.size(), is(0));

        returnedLocks = m_SUT.getWakeLocks(TestContext3.class, WakeLockState.Scheduled);
        assertThat(returnedLocks.size(), is(0));
    }
/**
     * Test method for {@link PowerManagerImpl#getWakeLocks(java.lang.Class, mil.dod.th.core.pm.WakeLockState)} when the
     * {@link PlatformPowerManager} is available.
     * 
     * Each lock should be able to have the same ID since their context is different
     */


Each lock should be able to have the same ID since their context is different
Each lock should be able to have the same ID since their context is different
@Test
    public void testGetWakeLocksContextWakeLockState()
    {
        WakeLock lock1 = m_SUT.createWakeLock(TestContext1.class, "lock");
        when(lock1.getId()).thenReturn("lock");
        doReturn(TestContext1.class).when(lock1).getContext();
        WakeLock lock2 = m_SUT.createWakeLock(TestContext2.class, "lock");
        when(lock2.getId()).thenReturn("lock");
        doReturn(TestContext2.class).when(lock2).getContext();
        WakeLock lock3 = m_SUT.createWakeLock(TestContext3.class, "lock");
        when(lock3.getId()).thenReturn("lock");
        doReturn(TestContext3.class).when(lock3).getContext();
        FactoryObject sourceObject = mockFactoryObject();
        WakeLock lock4 = m_SUT.createWakeLock(FactoryObjectProxy.class, sourceObject, "lock");
        when(lock4.getId()).thenReturn("lock");
        when(lock4.getSourceObject()).thenReturn(sourceObject);
        doReturn(FactoryObjectProxy.class).when(lock4).getContext();
        Set<WakeLock> activeLocks = new HashSet<WakeLock>();
        activeLocks.add(lock1);
        Set<WakeLock> inactiveLocks = new HashSet<WakeLock>();
        inactiveLocks.add(lock2);
        inactiveLocks.add(lock4);
        Set<WakeLock> schedLocks = new HashSet<WakeLock>();
        schedLocks.add(lock3);
        when(m_PPM.getActiveWakeLocks()).thenReturn(activeLocks);
        when(m_PPM.getScheduledWakeLocks()).thenReturn(schedLocks);
        Set<WakeLock> returnedLocks = m_SUT.getWakeLocks(TestContext1.class, WakeLockState.Any);
        assertThat(returnedLocks, hasItem(lock1));
        assertThat(returnedLocks.size(), is(1));
        returnedLocks = m_SUT.getWakeLocks(TestContext1.class, WakeLockState.Active);
        assertThat(returnedLocks, hasItem(lock1));
        assertThat(returnedLocks.size(), is(1));
        returnedLocks = m_SUT.getWakeLocks(TestContext2.class, WakeLockState.Inactive);
        assertThat(returnedLocks, hasItem(lock2));
        assertThat(returnedLocks.size(), is(1));
        returnedLocks = m_SUT.getWakeLocks(FactoryObjectProxy.class, WakeLockState.Inactive);
        assertThat(returnedLocks, hasItem(lock4));
        assertThat(returnedLocks.size(), is(1));
        returnedLocks = m_SUT.getWakeLocks(TestContext3.class, WakeLockState.Scheduled);
        assertThat(returnedLocks, hasItem(lock3));
        assertThat(returnedLocks.size(), is(1));
        m_SUT.unsetPlatformPowerManager(m_PPM);
        returnedLocks = m_SUT.getWakeLocks(TestContext1.class, WakeLockState.Active);
        assertThat(returnedLocks.size(), is(0));
        returnedLocks = m_SUT.getWakeLocks(TestContext3.class, WakeLockState.Scheduled);
        assertThat(returnedLocks.size(), is(0));
    }
@ Test public void testGetWakeLocksContextWakeLockState ( ) { WakeLock lock1 = m_SUT . createWakeLock ( TestContext1 . class , "lock" ) ; when ( lock1 . getId ( ) ) . thenReturn ( "lock" ) ; doReturn ( TestContext1 . class ) . when ( lock1 ) . getContext ( ) ; WakeLock lock2 = m_SUT . createWakeLock ( TestContext2 . class , "lock" ) ; when ( lock2 . getId ( ) ) . thenReturn ( "lock" ) ; doReturn ( TestContext2 . class ) . when ( lock2 ) . getContext ( ) ; WakeLock lock3 = m_SUT . createWakeLock ( TestContext3 . class , "lock" ) ; when ( lock3 . getId ( ) ) . thenReturn ( "lock" ) ; doReturn ( TestContext3 . class ) . when ( lock3 ) . getContext ( ) ; FactoryObject sourceObject = mockFactoryObject ( ) ; WakeLock lock4 = m_SUT . createWakeLock ( FactoryObjectProxy . class , sourceObject , "lock" ) ; when ( lock4 . getId ( ) ) . thenReturn ( "lock" ) ; when ( lock4 . getSourceObject ( ) ) . thenReturn ( sourceObject ) ; doReturn ( FactoryObjectProxy . class ) . when ( lock4 ) . getContext ( ) ; Set < WakeLock > activeLocks = new HashSet < WakeLock > ( ) ; activeLocks . add ( lock1 ) ; Set < WakeLock > inactiveLocks = new HashSet < WakeLock > ( ) ; inactiveLocks . add ( lock2 ) ; inactiveLocks . add ( lock4 ) ; Set < WakeLock > schedLocks = new HashSet < WakeLock > ( ) ; schedLocks . add ( lock3 ) ; when ( m_PPM . getActiveWakeLocks ( ) ) . thenReturn ( activeLocks ) ; when ( m_PPM . getScheduledWakeLocks ( ) ) . thenReturn ( schedLocks ) ; Set < WakeLock > returnedLocks = m_SUT . getWakeLocks ( TestContext1 . class , WakeLockState . Any ) ; assertThat ( returnedLocks , hasItem ( lock1 ) ) ; assertThat ( returnedLocks . size ( ) , is ( 1 ) ) ; returnedLocks = m_SUT . getWakeLocks ( TestContext1 . class , WakeLockState . Active ) ; assertThat ( returnedLocks , hasItem ( lock1 ) ) ; assertThat ( returnedLocks . size ( ) , is ( 1 ) ) ; returnedLocks = m_SUT . getWakeLocks ( TestContext2 . class , WakeLockState . Inactive ) ; assertThat ( returnedLocks , hasItem ( lock2 ) ) ; assertThat ( returnedLocks . size ( ) , is ( 1 ) ) ; returnedLocks = m_SUT . getWakeLocks ( FactoryObjectProxy . class , WakeLockState . Inactive ) ; assertThat ( returnedLocks , hasItem ( lock4 ) ) ; assertThat ( returnedLocks . size ( ) , is ( 1 ) ) ; returnedLocks = m_SUT . getWakeLocks ( TestContext3 . class , WakeLockState . Scheduled ) ; assertThat ( returnedLocks , hasItem ( lock3 ) ) ; assertThat ( returnedLocks . size ( ) , is ( 1 ) ) ; m_SUT . unsetPlatformPowerManager ( m_PPM ) ; returnedLocks = m_SUT . getWakeLocks ( TestContext1 . class , WakeLockState . Active ) ; assertThat ( returnedLocks . size ( ) , is ( 0 ) ) ; returnedLocks = m_SUT . getWakeLocks ( TestContext3 . class , WakeLockState . Scheduled ) ; assertThat ( returnedLocks . size ( ) , is ( 0 ) ) ; }
Test method for {@link PowerManagerImpl#getWakeLocks(java.lang.Class, mil.dod.th.core.pm.WakeLockState)} when the
 {@link PlatformPowerManager} is available.
Test method for { @link PowerManagerImpl#getWakeLocks ( java . lang . Class mil . dod . th . core . pm . WakeLockState ) } when the { @link PlatformPowerManager } is available .
// Verify with no PlatformPowerManager