Migrate ExperimentEnrollmentManagerTest to JUnit 5
This commit is contained in:
		
							parent
							
								
									5dc8086968
								
							
						
					
					
						commit
						14bfa83bb8
					
				| 
						 | 
					@ -5,62 +5,62 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
package org.whispersystems.textsecuregcm.experiment;
 | 
					package org.whispersystems.textsecuregcm.experiment;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import org.junit.Before;
 | 
					 | 
				
			||||||
import org.junit.Test;
 | 
					 | 
				
			||||||
import org.whispersystems.textsecuregcm.configuration.dynamic.DynamicConfiguration;
 | 
					 | 
				
			||||||
import org.whispersystems.textsecuregcm.configuration.dynamic.DynamicExperimentEnrollmentConfiguration;
 | 
					 | 
				
			||||||
import org.whispersystems.textsecuregcm.storage.Account;
 | 
					 | 
				
			||||||
import org.whispersystems.textsecuregcm.storage.DynamicConfigurationManager;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import java.util.Collections;
 | 
					 | 
				
			||||||
import java.util.Optional;
 | 
					 | 
				
			||||||
import java.util.Set;
 | 
					 | 
				
			||||||
import java.util.UUID;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import static org.junit.Assert.assertFalse;
 | 
					import static org.junit.Assert.assertFalse;
 | 
				
			||||||
import static org.junit.Assert.assertTrue;
 | 
					import static org.junit.Assert.assertTrue;
 | 
				
			||||||
import static org.mockito.Mockito.mock;
 | 
					import static org.mockito.Mockito.mock;
 | 
				
			||||||
import static org.mockito.Mockito.when;
 | 
					import static org.mockito.Mockito.when;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class ExperimentEnrollmentManagerTest {
 | 
					import java.util.Collections;
 | 
				
			||||||
 | 
					import java.util.Optional;
 | 
				
			||||||
 | 
					import java.util.Set;
 | 
				
			||||||
 | 
					import java.util.UUID;
 | 
				
			||||||
 | 
					import org.junit.jupiter.api.BeforeEach;
 | 
				
			||||||
 | 
					import org.junit.jupiter.api.Test;
 | 
				
			||||||
 | 
					import org.whispersystems.textsecuregcm.configuration.dynamic.DynamicConfiguration;
 | 
				
			||||||
 | 
					import org.whispersystems.textsecuregcm.configuration.dynamic.DynamicExperimentEnrollmentConfiguration;
 | 
				
			||||||
 | 
					import org.whispersystems.textsecuregcm.storage.Account;
 | 
				
			||||||
 | 
					import org.whispersystems.textsecuregcm.storage.DynamicConfigurationManager;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private DynamicExperimentEnrollmentConfiguration experimentEnrollmentConfiguration;
 | 
					class ExperimentEnrollmentManagerTest {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private ExperimentEnrollmentManager experimentEnrollmentManager;
 | 
					  private DynamicExperimentEnrollmentConfiguration experimentEnrollmentConfiguration;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private Account account;
 | 
					  private ExperimentEnrollmentManager experimentEnrollmentManager;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private static final UUID ACCOUNT_UUID = UUID.randomUUID();
 | 
					  private Account account;
 | 
				
			||||||
    private static final String EXPERIMENT_NAME = "test";
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Before
 | 
					  private static final UUID ACCOUNT_UUID = UUID.randomUUID();
 | 
				
			||||||
    public void setUp() {
 | 
					  private static final String EXPERIMENT_NAME = "test";
 | 
				
			||||||
        final DynamicConfigurationManager dynamicConfigurationManager = mock(DynamicConfigurationManager.class);
 | 
					 | 
				
			||||||
        final DynamicConfiguration dynamicConfiguration = mock(DynamicConfiguration.class);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        experimentEnrollmentConfiguration = mock(DynamicExperimentEnrollmentConfiguration.class);
 | 
					  @BeforeEach
 | 
				
			||||||
        experimentEnrollmentManager = new ExperimentEnrollmentManager(dynamicConfigurationManager);
 | 
					  void setUp() {
 | 
				
			||||||
        account = mock(Account.class);
 | 
					    final DynamicConfigurationManager dynamicConfigurationManager = mock(DynamicConfigurationManager.class);
 | 
				
			||||||
 | 
					    final DynamicConfiguration dynamicConfiguration = mock(DynamicConfiguration.class);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        when(dynamicConfigurationManager.getConfiguration()).thenReturn(dynamicConfiguration);
 | 
					    experimentEnrollmentConfiguration = mock(DynamicExperimentEnrollmentConfiguration.class);
 | 
				
			||||||
        when(dynamicConfiguration.getExperimentEnrollmentConfiguration(EXPERIMENT_NAME)).thenReturn(Optional.of(experimentEnrollmentConfiguration));
 | 
					    experimentEnrollmentManager = new ExperimentEnrollmentManager(dynamicConfigurationManager);
 | 
				
			||||||
        when(account.getUuid()).thenReturn(ACCOUNT_UUID);
 | 
					    account = mock(Account.class);
 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Test
 | 
					    when(dynamicConfigurationManager.getConfiguration()).thenReturn(dynamicConfiguration);
 | 
				
			||||||
    public void testIsEnrolled() {
 | 
					    when(dynamicConfiguration.getExperimentEnrollmentConfiguration(EXPERIMENT_NAME))
 | 
				
			||||||
        assertFalse(experimentEnrollmentManager.isEnrolled(account.getUuid(), EXPERIMENT_NAME));
 | 
					        .thenReturn(Optional.of(experimentEnrollmentConfiguration));
 | 
				
			||||||
        assertFalse(experimentEnrollmentManager.isEnrolled(account.getUuid(), EXPERIMENT_NAME + "-unrelated-experiment"));
 | 
					    when(account.getUuid()).thenReturn(ACCOUNT_UUID);
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        when(experimentEnrollmentConfiguration.getEnrolledUuids()).thenReturn(Set.of(ACCOUNT_UUID));
 | 
					  @Test
 | 
				
			||||||
        assertTrue(experimentEnrollmentManager.isEnrolled(account.getUuid(), EXPERIMENT_NAME));
 | 
					  void testIsEnrolled() {
 | 
				
			||||||
 | 
					    assertFalse(experimentEnrollmentManager.isEnrolled(account.getUuid(), EXPERIMENT_NAME));
 | 
				
			||||||
 | 
					    assertFalse(experimentEnrollmentManager.isEnrolled(account.getUuid(), EXPERIMENT_NAME + "-unrelated-experiment"));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        when(experimentEnrollmentConfiguration.getEnrolledUuids()).thenReturn(Collections.emptySet());
 | 
					    when(experimentEnrollmentConfiguration.getEnrolledUuids()).thenReturn(Set.of(ACCOUNT_UUID));
 | 
				
			||||||
        when(experimentEnrollmentConfiguration.getEnrollmentPercentage()).thenReturn(0);
 | 
					    assertTrue(experimentEnrollmentManager.isEnrolled(account.getUuid(), EXPERIMENT_NAME));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        assertFalse(experimentEnrollmentManager.isEnrolled(account.getUuid(), EXPERIMENT_NAME));
 | 
					    when(experimentEnrollmentConfiguration.getEnrolledUuids()).thenReturn(Collections.emptySet());
 | 
				
			||||||
 | 
					    when(experimentEnrollmentConfiguration.getEnrollmentPercentage()).thenReturn(0);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        when(experimentEnrollmentConfiguration.getEnrollmentPercentage()).thenReturn(100);
 | 
					    assertFalse(experimentEnrollmentManager.isEnrolled(account.getUuid(), EXPERIMENT_NAME));
 | 
				
			||||||
        assertTrue(experimentEnrollmentManager.isEnrolled(account.getUuid(), EXPERIMENT_NAME));
 | 
					
 | 
				
			||||||
    }
 | 
					    when(experimentEnrollmentConfiguration.getEnrollmentPercentage()).thenReturn(100);
 | 
				
			||||||
 | 
					    assertTrue(experimentEnrollmentManager.isEnrolled(account.getUuid(), EXPERIMENT_NAME));
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue