How to use Sets class of org.mockito.internal.util.collections package

Best Mockito code snippet using org.mockito.internal.util.collections.Sets

Source:AuthenticationCommandHandlerTest.java Github

copy

Full Screen

...28import org.apache.fineract.cn.identity.internal.command.AuthenticationCommandResponse;29import org.apache.fineract.cn.identity.internal.command.PasswordAuthenticationCommand;30import org.apache.fineract.cn.identity.internal.command.RefreshTokenAuthenticationCommand;31import org.apache.fineract.cn.identity.internal.repository.AllowedOperationType;32import org.apache.fineract.cn.identity.internal.repository.ApplicationCallEndpointSets;33import org.apache.fineract.cn.identity.internal.repository.ApplicationPermissionUsers;34import org.apache.fineract.cn.identity.internal.repository.ApplicationPermissions;35import org.apache.fineract.cn.identity.internal.repository.ApplicationSignatures;36import org.apache.fineract.cn.identity.internal.repository.PermissionType;37import org.apache.fineract.cn.identity.internal.repository.PermittableGroups;38import org.apache.fineract.cn.identity.internal.repository.PrivateSignatureEntity;39import org.apache.fineract.cn.identity.internal.repository.PrivateTenantInfoEntity;40import org.apache.fineract.cn.identity.internal.repository.RoleEntity;41import org.apache.fineract.cn.identity.internal.repository.Roles;42import org.apache.fineract.cn.identity.internal.repository.Signatures;43import org.apache.fineract.cn.identity.internal.repository.Tenants;44import org.apache.fineract.cn.identity.internal.repository.UserEntity;45import org.apache.fineract.cn.identity.internal.repository.Users;46import org.apache.fineract.cn.lang.ApplicationName;47import org.apache.fineract.cn.lang.DateConverter;48import org.apache.fineract.cn.lang.security.RsaKeyPairFactory;49import org.junit.Assert;50import org.junit.BeforeClass;51import org.junit.Test;52import org.mockito.Mockito;53import org.slf4j.Logger;54import org.springframework.jms.core.JmsTemplate;55import java.nio.ByteBuffer;56import java.time.Instant;57import java.time.LocalDate;58import java.time.LocalDateTime;59import java.time.ZoneId;60import java.time.format.DateTimeFormatter;61import java.time.temporal.ChronoUnit;62import java.util.*;63import java.util.stream.Collectors;64import java.util.stream.Stream;65import static org.mockito.Matchers.*;66import static org.mockito.Mockito.when;67/**68 * @author Myrle Krantz69 */70public class AuthenticationCommandHandlerTest {71 private static final String USER_NAME = "me";72 private static final String ROLE = "I";73 private static final String PASSWORD = "mine";74 private static final int ITERATION_COUNT = 20;75 private static final String TEST_APPLICATION_NAME = "test-v1";76 private static final long ACCESS_TOKEN_TIME_TO_LIVE = 20;77 private static final long REFRESH_TOKEN_TIME_TO_LIVE = 40;78 private static final int GRACE_PERIOD = 2;79 private static AuthenticationCommandHandler commandHandler;80 @BeforeClass()81 static public void setup()82 {83 RsaKeyPairFactory.KeyPairHolder keyPair = RsaKeyPairFactory.createKeyPair();84 final Users users = Mockito.mock(Users.class);85 final Roles roles = Mockito.mock(Roles.class);86 final PermittableGroups permittableGroups = Mockito.mock(PermittableGroups.class);87 final Signatures signatures = Mockito.mock(Signatures.class);88 final Tenants tenants = Mockito.mock(Tenants.class);89 final HashGenerator hashGenerator = Mockito.mock(HashGenerator.class);90 final TenantAccessTokenSerializer tenantAccessTokenSerializer91 = Mockito.mock(TenantAccessTokenSerializer.class);92 final TenantRefreshTokenSerializer tenantRefreshTokenSerializer93 = Mockito.mock(TenantRefreshTokenSerializer.class);94 final JmsTemplate jmsTemplate = Mockito.mock(JmsTemplate.class);95 final ApplicationName applicationName = Mockito.mock(ApplicationName.class);96 final Gson gson = new Gson();97 final Logger logger = Mockito.mock(Logger.class);98 final TenantRsaKeyProvider tenantRsaKeyProvider = Mockito.mock(TenantRsaKeyProvider.class);99 final ApplicationSignatures applicationSignatures = Mockito.mock(ApplicationSignatures.class);100 final ApplicationPermissions applicationPermissions = Mockito.mock(ApplicationPermissions.class);101 final ApplicationPermissionUsers applicationPermissionUsers = Mockito.mock(ApplicationPermissionUsers.class);102 final ApplicationCallEndpointSets applicationCallEndpointSets = Mockito.mock(ApplicationCallEndpointSets.class);103 commandHandler = new AuthenticationCommandHandler(104 users, roles, permittableGroups, signatures, tenants,105 hashGenerator,106 tenantAccessTokenSerializer, tenantRefreshTokenSerializer, tenantRsaKeyProvider,107 applicationSignatures, applicationPermissions, applicationPermissionUsers, applicationCallEndpointSets,108 jmsTemplate, applicationName,109 gson, logger);110 final PrivateTenantInfoEntity privateTenantInfoEntity = new PrivateTenantInfoEntity();111 privateTenantInfoEntity.setFixedSalt(ByteBuffer.wrap(new SaltGenerator().createRandomSalt()));112 privateTenantInfoEntity.setTimeToChangePasswordAfterExpirationInDays(GRACE_PERIOD);113 when(tenants.getPrivateTenantInfo()).thenReturn(Optional.of(privateTenantInfoEntity));114 final PrivateSignatureEntity privateSignatureEntity = new PrivateSignatureEntity();115 privateSignatureEntity.setKeyTimestamp(keyPair.getTimestamp());116 privateSignatureEntity.setPrivateKeyExp(keyPair.getPrivateKeyExp());117 privateSignatureEntity.setPrivateKeyMod(keyPair.getPrivateKeyMod());118 when(signatures.getPrivateSignature()).thenReturn(Optional.of(privateSignatureEntity));119 final UserEntity userEntity = new UserEntity();120 userEntity.setRole(ROLE);121 userEntity.setIdentifier(USER_NAME);122 userEntity.setIterationCount(ITERATION_COUNT);123 userEntity.setPassword(ByteBuffer.wrap(PASSWORD.getBytes()));124 userEntity.setSalt(ByteBuffer.wrap(new SaltGenerator().createRandomSalt()));125 userEntity.setPasswordExpiresOn(dataStaxNow());126 when(users.get(USER_NAME)).thenReturn(Optional.of(userEntity));127 final List<PermissionType> permissionsList = new ArrayList<>();128 final RoleEntity roleEntity = new RoleEntity(ROLE, permissionsList);129 when(roles.get(ROLE)).thenReturn(Optional.of(roleEntity));130 when(applicationName.toString()).thenReturn(TEST_APPLICATION_NAME);131 final TokenSerializationResult accessTokenSerializationResult = new TokenSerializationResult("blah", LocalDateTime.now(ZoneId.of("UTC")).plusSeconds(ACCESS_TOKEN_TIME_TO_LIVE));132 when(tenantAccessTokenSerializer.build(anyObject())).thenReturn(accessTokenSerializationResult);133 final TokenSerializationResult refreshTokenSerializationResult = new TokenSerializationResult("blah", LocalDateTime.now(ZoneId.of("UTC")).plusSeconds(REFRESH_TOKEN_TIME_TO_LIVE));134 when(tenantRefreshTokenSerializer.build(anyObject())).thenReturn(refreshTokenSerializationResult);135 final TokenDeserializationResult deserialized = new TokenDeserializationResult(USER_NAME, Date.from(Instant.now().plusSeconds(REFRESH_TOKEN_TIME_TO_LIVE)), TEST_APPLICATION_NAME, null);136 when(tenantRefreshTokenSerializer.deserialize(anyObject(), anyObject())).thenReturn(deserialized);137 when(hashGenerator.isEqual(any(), any(), any(), any(), anyInt(), anyInt())).thenReturn(true);138 }139 private static com.datastax.driver.core.LocalDate dataStaxNow() {140 return com.datastax.driver.core.LocalDate.fromDaysSinceEpoch((int) LocalDate.now(ZoneId.of("UTC")).toEpochDay());141 }142 @Test143 public void correctPasswordAuthentication()144 {145 final PasswordAuthenticationCommand command = new PasswordAuthenticationCommand(USER_NAME, PASSWORD);146 final AuthenticationCommandResponse commandResponse = commandHandler.process(command);147 Assert.assertNotNull(commandResponse);148 }149 @Test150 public void correctRefreshTokenAuthentication()151 {152 final String refreshTokenPlaceHolder = "refresh_token";153 final RefreshTokenAuthenticationCommand command = new RefreshTokenAuthenticationCommand(refreshTokenPlaceHolder);154 final LocalDateTime now = LocalDateTime.now(ZoneId.of("UTC"));155 final AuthenticationCommandResponse commandResponse = commandHandler.process(command);156 Assert.assertNotNull(commandResponse);157 Assert.assertNotNull(commandResponse.getRefreshToken());158 Assert.assertEquals(commandResponse.getRefreshToken(), refreshTokenPlaceHolder);159 checkExpiration(commandResponse.getAccessTokenExpiration(), now, ACCESS_TOKEN_TIME_TO_LIVE);160 checkExpiration(commandResponse.getRefreshTokenExpiration(), now, REFRESH_TOKEN_TIME_TO_LIVE);161 }162 private void checkExpiration(final String expirationString, final LocalDateTime now, final long timeToLive) {163 final LocalDateTime expectedExpiration = now.plusSeconds(timeToLive);164 final LocalDateTime parsedExpiration = LocalDateTime.parse(expirationString, DateTimeFormatter.ISO_DATE_TIME);165 final long deltaFromExpected = Math.abs(parsedExpiration.until(expectedExpiration, ChronoUnit.SECONDS));166 Assert.assertTrue("Delta from expected should have been less than 2 second, but was " + deltaFromExpected +167 ". Expiration string was " + expirationString + ". Now was " + now + ".",168 deltaFromExpected <= 2);169 }170 @Test171 public void correctDeterminationOfPasswordExpiration()172 {173 final LocalDateTime passwordExpirationFromToday = LocalDateTime.now(ZoneId.of("UTC"));174 Assert.assertTrue(AuthenticationCommandHandler.pastExpiration(Optional.of(passwordExpirationFromToday)));175 final LocalDateTime passwordExpirationFromYesterday = passwordExpirationFromToday.minusDays(1);176 Assert.assertTrue(AuthenticationCommandHandler.pastExpiration(Optional.of(passwordExpirationFromYesterday)));177 final LocalDateTime passwordExpirationFromTommorrow = passwordExpirationFromToday.plusDays(1);178 Assert.assertFalse(AuthenticationCommandHandler.pastExpiration(Optional.of(passwordExpirationFromTommorrow)));179 }180 @Test181 public void correctDeterminationOfPasswordGracePeriod()182 {183 final LocalDateTime passwordExpirationFromToday = LocalDateTime.now(ZoneId.of("UTC"));184 Assert.assertFalse(AuthenticationCommandHandler.pastGracePeriod(Optional.of(passwordExpirationFromToday), GRACE_PERIOD));185 final LocalDateTime nowJustWithinPasswordExpirationAndGracePeriod = passwordExpirationFromToday.minusDays(GRACE_PERIOD - 1);186 Assert.assertFalse(AuthenticationCommandHandler.pastGracePeriod(Optional.of(nowJustWithinPasswordExpirationAndGracePeriod), GRACE_PERIOD));187 final LocalDateTime nowJustOutsideOfPasswordExpirationAndGracePeriod = passwordExpirationFromToday.minusDays(GRACE_PERIOD);188 Assert.assertTrue(AuthenticationCommandHandler.pastGracePeriod(Optional.of(nowJustOutsideOfPasswordExpirationAndGracePeriod), GRACE_PERIOD));189 }190 @Test191 public void matchingFormatOfDates() {192 final Instant now = Instant.now();193 final Date nowDate = Date.from(now);194 final LocalDateTime nowLocalDateTime = LocalDateTime.ofInstant(now, ZoneId.of("UTC"));195 final LocalDate nowLocalDate = nowLocalDateTime.toLocalDate();196 final String dateString = DateConverter.toIsoString(nowDate);197 final String localDateTimeString = DateConverter.toIsoString(nowLocalDateTime);198 final String localDateString = DateConverter.toIsoString(nowLocalDate);199 Assert.assertEquals(dateString, localDateTimeString);200 Assert.assertTrue(localDateTimeString.startsWith(localDateString.substring(0, localDateString.length()-1))); //(removing Z)201 }202 @Test203 public void intersectSets() {204 final Set<AllowedOperationType> intersectionWithNull205 = AuthenticationCommandHandler.intersectSets(new HashSet<>(), null);206 Assert.assertTrue(intersectionWithNull.isEmpty());207 final Set<AllowedOperationType> intersectionWithEqualSet208 = AuthenticationCommandHandler.intersectSets(Collections.singleton(AllowedOperationType.CHANGE),209 Collections.singleton(AllowedOperationType.CHANGE));210 Assert.assertEquals(Collections.singleton(AllowedOperationType.CHANGE), intersectionWithEqualSet);211 final Set<AllowedOperationType> intersectionWithAll212 = AuthenticationCommandHandler.intersectSets(AllowedOperationType.ALL,213 AllowedOperationType.ALL);214 Assert.assertEquals(AllowedOperationType.ALL, intersectionWithAll);215 final Set<AllowedOperationType> intersectionWithNonOverlappingSet216 = AuthenticationCommandHandler.intersectSets(Collections.singleton(AllowedOperationType.DELETE),217 Collections.singleton(AllowedOperationType.CHANGE));218 Assert.assertTrue(intersectionWithNonOverlappingSet.isEmpty());219 final Set<AllowedOperationType> intersectionWithSubSet220 = AuthenticationCommandHandler.intersectSets(AllowedOperationType.ALL,221 Collections.singleton(AllowedOperationType.CHANGE));222 Assert.assertEquals(Collections.singleton(AllowedOperationType.CHANGE), intersectionWithSubSet);223 final Set<AllowedOperationType> intersectionWithPartiallyOverlapping = AuthenticationCommandHandler.intersectSets(224 Stream.of(AllowedOperationType.CHANGE, AllowedOperationType.DELETE).collect(Collectors.toSet()),225 Stream.of(AllowedOperationType.CHANGE, AllowedOperationType.READ).collect(Collectors.toSet()));226 Assert.assertEquals(Collections.singleton(AllowedOperationType.CHANGE), intersectionWithPartiallyOverlapping);227 }228 @Test229 public void transformToSearchablePermissions()230 {231 Map<String, Set<AllowedOperationType>> x = AuthenticationCommandHandler.transformToSearchablePermissions(Arrays.asList(232 new PermissionType("x", new HashSet<>(AllowedOperationType.ALL)),233 new PermissionType("y", new HashSet<>(Collections.singletonList(AllowedOperationType.CHANGE)))));234 Assert.assertEquals(AllowedOperationType.ALL, x.get("x"));235 }236}...

Full Screen

Full Screen

Source:GeoAreasHandlerTests.java Github

copy

Full Screen

...15import org.infobip.mobile.messaging.util.StringUtils;16import org.junit.Test;17import org.mockito.ArgumentCaptor;18import org.mockito.Mockito;19import org.mockito.internal.util.collections.Sets;20import org.mockito.invocation.InvocationOnMock;21import org.mockito.stubbing.Answer;22import java.util.Arrays;23import java.util.Collections;24import java.util.HashMap;25import java.util.List;26import java.util.Map;27import static junit.framework.Assert.assertEquals;28import static junit.framework.Assert.assertNotNull;29import static junit.framework.Assert.assertNotSame;30import static junit.framework.Assert.assertTrue;31/**32 * @author sslavin33 * @since 14/03/2017.34 */35public class GeoAreasHandlerTests extends MobileMessagingTestCase {36 private GeoAreasHandler geoAreasHandler;37 private GeoNotificationHelper geoNotificationHelper;38 private GeoReporter geoReporter;39 private MessageStore messageStore;40 private ArgumentCaptor<GeoReport[]> geoReportCaptor;41 private ArgumentCaptor<Map<Message, GeoEventType>> geoNotificationCaptor;42 @Override43 public void setUp() throws Exception {44 super.setUp();45 enableMessageStoreForReceivedMessages();46 geoNotificationHelper = Mockito.mock(GeoNotificationHelper.class);47 geoReporter = Mockito.mock(GeoReporter.class);48 messageStore = Mockito.mock(MessageStore.class);49 geoAreasHandler = new GeoAreasHandler(contextMock, mobileMessagingCore, geoNotificationHelper, geoReporter, new GeofencingHelper(context));50 geoReportCaptor = ArgumentCaptor.forClass(GeoReport[].class);51 geoNotificationCaptor = new ArgumentCaptor<>();52 }53 @Test54 public void test_should_report_transition() {55 // Given56 Message m = createMessage(context, "SomeSignalingMessageId", "SomeCampaignId", true, createArea("SomeAreaId"));57 Mockito.when(messageStore.findAll(Mockito.any(Context.class))).thenReturn(Collections.singletonList(m));58 Mockito.when(geoReporter.reportSync(Mockito.any(GeoReport[].class))).thenReturn(new GeoReportingResult(new Exception()));59 GeoTransition transition = GeoHelper.createTransition(123.0, 456.0, "SomeAreaId");60 time.set(789);61 // When62 geoAreasHandler.handleTransition(transition);63 // Then64 Mockito.verify(geoReporter, Mockito.times(1)).reportSync(geoReportCaptor.capture());65 GeoReport report = geoReportCaptor.getValue()[0];66 assertEquals("SomeAreaId", report.getArea().getId());67 assertEquals("SomeCampaignId", report.getCampaignId());68 assertEquals("SomeSignalingMessageId", report.getSignalingMessageId());69 assertNotSame("SomeSignalingMessageId", report.getMessageId());70 assertTrue(StringUtils.isNotBlank(report.getMessageId()));71 assertEquals(789, report.getTimestampOccurred().longValue());72 assertEquals(123.0, report.getTriggeringLocation().getLat());73 assertEquals(456.0, report.getTriggeringLocation().getLng());74 }75 @Test76 public void test_should_notify_messages_with_generated_ids_if_report_unsuccessful() {77 // Given78 Message m = createMessage(context, "SomeSignalingMessageId", "SomeCampaignId", true, createArea("SomeAreaId"));79 Mockito.when(messageStore.findAll(Mockito.any(Context.class))).thenReturn(Collections.singletonList(m));80 Mockito.when(geoReporter.reportSync(Mockito.any(GeoReport[].class))).thenReturn(new GeoReportingResult(new Exception()));81 GeoTransition transition = GeoHelper.createTransition(123.0, 456.0, "SomeAreaId");82 time.set(789);83 // When84 geoAreasHandler.handleTransition(transition);85 // Then86 Mockito.verify(geoNotificationHelper, Mockito.times(1)).notifyAboutGeoTransitions(geoNotificationCaptor.capture());87 Map.Entry<Message, GeoEventType> notification = geoNotificationCaptor.getValue().entrySet().iterator().next();88 assertEquals(GeoEventType.entry, notification.getValue());89 Message message = notification.getKey();90 assertNotSame("SomeSignalingMessageId", message.getMessageId());91 assertTrue(StringUtils.isNotBlank(message.getMessageId()));92 Geo geo = GeoDataMapper.geoFromInternalData(message.getInternalData());93 assertNotNull(geo);94 assertEquals("SomeCampaignId", geo.getCampaignId());95 assertEquals(123.0, geo.getTriggeringLatitude());96 assertEquals(456.0, geo.getTriggeringLongitude());97 assertEquals("SomeAreaId", geo.getAreasList().get(0).getId());98 }99 @Test100 public void test_should_notify_messages_with_server_ids_if_report_successful() {101 // Given102 Message m = createMessage(context, "SomeSignalingMessageId", "SomeCampaignId", true, createArea("SomeAreaId"));103 Mockito.when(messageStore.findAll(Mockito.any(Context.class))).thenReturn(Collections.singletonList(m));104 Mockito.when(geoReporter.reportSync(Mockito.any(GeoReport[].class))).thenAnswer(new Answer<GeoReportingResult>() {105 @Override106 public GeoReportingResult answer(InvocationOnMock invocation) throws Throwable {107 final GeoReport[] reports = (GeoReport[]) invocation.getArguments()[0];108 EventReportResponse eventReportResponse = new EventReportResponse();109 eventReportResponse.setMessageIds(new HashMap<String, String>() {{110 put(reports[0].getMessageId(), "SomeServerMessageId");111 }});112 return new GeoReportingResult(eventReportResponse);113 }114 });115 GeoTransition transition = GeoHelper.createTransition(123.0, 456.0, "SomeAreaId");116 time.set(789);117 // When118 geoAreasHandler.handleTransition(transition);119 // Then120 Mockito.verify(geoNotificationHelper, Mockito.times(1)).notifyAboutGeoTransitions(geoNotificationCaptor.capture());121 Map.Entry<Message, GeoEventType> notification = geoNotificationCaptor.getValue().entrySet().iterator().next();122 assertEquals(GeoEventType.entry, notification.getValue());123 Message message = notification.getKey();124 Geo geo = GeoDataMapper.geoFromInternalData(message.getInternalData());125 assertNotNull(geo);126 assertEquals("SomeServerMessageId", message.getMessageId());127 assertEquals("SomeCampaignId", geo.getCampaignId());128 assertEquals(123.0, geo.getTriggeringLatitude());129 assertEquals(456.0, geo.getTriggeringLongitude());130 assertEquals("SomeAreaId", geo.getAreasList().get(0).getId());131 }132 @Test133 public void test_should_save_messages_with_generated_ids_if_report_unsuccessful() {134 // Given135 Message m = createMessage(context, "SomeSignalingMessageId", "SomeCampaignId", true, createArea("SomeAreaId"));136 Mockito.when(messageStore.findAll(Mockito.any(Context.class))).thenReturn(Collections.singletonList(m));137 Mockito.when(geoReporter.reportSync(Mockito.any(GeoReport[].class))).thenReturn(new GeoReportingResult(new Exception()));138 GeoTransition transition = GeoHelper.createTransition(123.0, 456.0, "SomeAreaId");139 time.set(789);140 // When141 geoAreasHandler.handleTransition(transition);142 // Then143 Message message = geoAreasHandler.getMobileMessagingCore().getMessageStore().findAll(context).get(0);144 Geo geo = GeoDataMapper.geoFromInternalData(message.getInternalData());145 assertNotNull(geo);146 assertNotSame("SomeSignalingMessageId", message.getMessageId());147 assertTrue(StringUtils.isNotBlank(message.getMessageId()));148 assertEquals("SomeCampaignId", geo.getCampaignId());149 assertEquals(123.0, geo.getTriggeringLatitude());150 assertEquals(456.0, geo.getTriggeringLongitude());151 assertEquals("SomeAreaId", geo.getAreasList().get(0).getId());152 }153 @Test154 public void test_should_save_messages_with_server_ids_if_report_successful() {155 // Given156 Message m = createMessage(context, "SomeSignalingMessageId", "SomeCampaignId", true, createArea("SomeAreaId"));157 Mockito.when(messageStore.findAll(Mockito.any(Context.class))).thenReturn(Collections.singletonList(m));158 Mockito.when(geoReporter.reportSync(Mockito.any(GeoReport[].class))).thenAnswer(new Answer<GeoReportingResult>() {159 @Override160 public GeoReportingResult answer(InvocationOnMock invocation) throws Throwable {161 final GeoReport[] reports = (GeoReport[]) invocation.getArguments()[0];162 EventReportResponse eventReportResponse = new EventReportResponse();163 eventReportResponse.setMessageIds(new HashMap<String, String>() {{164 put(reports[0].getMessageId(), "SomeServerMessageId");165 }});166 return new GeoReportingResult(eventReportResponse);167 }168 });169 GeoTransition transition = GeoHelper.createTransition(123.0, 456.0, "SomeAreaId");170 time.set(789);171 // When172 geoAreasHandler.handleTransition(transition);173 // Then174 Message message = geoAreasHandler.getMobileMessagingCore().getMessageStore().findAll(context).get(0);175 Geo geo = GeoDataMapper.geoFromInternalData(message.getInternalData());176 assertNotNull(geo);177 assertNotSame("SomeSignalingMessageId", message.getMessageId());178 assertTrue(StringUtils.isNotBlank(message.getMessageId()));179 assertEquals("SomeCampaignId", geo.getCampaignId());180 assertEquals(123.0, geo.getTriggeringLatitude());181 assertEquals(456.0, geo.getTriggeringLongitude());182 assertEquals("SomeAreaId", geo.getAreasList().get(0).getId());183 }184 @Test185 public void test_should_notify_messages_only_for_active_campaigns() throws InterruptedException {186 // Given187 Area area = createArea("areaId1");188 Mockito.when(messageStore.findAll(Mockito.any(Context.class))).thenReturn(Arrays.asList(189 createMessage(context, "signalingMessageId1", "campaignId1", true, area),190 createMessage(context, "signalingMessageId2", "campaignId2", true, area),191 createMessage(context, "signalingMessageId3", "campaignId3", true, area)));192 EventReportResponse response = new EventReportResponse();193 response.setSuspendedCampaignIds(Sets.newSet("campaignId1"));194 response.setFinishedCampaignIds(Sets.newSet("campaignId2"));195 Mockito.when(geoReporter.reportSync(Mockito.any(GeoReport[].class))).thenReturn(new GeoReportingResult(response));196 GeoTransition transition = GeoHelper.createTransition("areaId1");197 // When198 geoAreasHandler.handleTransition(transition);199 // Then200 Mockito.verify(geoNotificationHelper, Mockito.times(1)).notifyAboutGeoTransitions(geoNotificationCaptor.capture());201 assertEquals(1, geoNotificationCaptor.getValue().size());202 Map.Entry<Message, GeoEventType> notification = geoNotificationCaptor.getValue().entrySet().iterator().next();203 assertEquals(GeoEventType.entry, notification.getValue());204 Message message = notification.getKey();205 Geo geo = GeoDataMapper.geoFromInternalData(message.getInternalData());206 assertNotNull(geo);207 assertNotSame("signalingMessageId3", message.getMessageId());208 assertTrue(StringUtils.isNotBlank(message.getMessageId()));209 assertEquals("campaignId3", geo.getCampaignId());210 assertEquals("areaId1", geo.getAreasList().get(0).getId());211 }212 @Test213 public void test_should_generate_messages_only_for_active_campaigns() throws InterruptedException {214 // Given215 Area area = createArea("areaId1");216 Mockito.when(messageStore.findAll(Mockito.any(Context.class))).thenReturn(Arrays.asList(217 createMessage(context, "signalingMessageId1", "campaignId1", true, "some url", area),218 createMessage(context, "signalingMessageId2", "campaignId2", true, "some url", area),219 createMessage(context, "signalingMessageId3", "campaignId3", true, "some url", area)));220 EventReportResponse response = new EventReportResponse();221 response.setSuspendedCampaignIds(Sets.newSet("campaignId1"));222 response.setFinishedCampaignIds(Sets.newSet("campaignId2"));223 Mockito.when(geoReporter.reportSync(Mockito.any(GeoReport[].class))).thenReturn(new GeoReportingResult(response));224 GeoTransition transition = GeoHelper.createTransition("areaId1");225 // When226 geoAreasHandler.handleTransition(transition);227 // Then228 List<Message> messages = geoAreasHandler.getMobileMessagingCore().getMessageStore().findAll(context);229 assertEquals(1, messages.size());230 Message message = messages.get(0);231 Geo geo = GeoDataMapper.geoFromInternalData(message.getInternalData());232 assertNotNull(geo);233 assertNotSame("signalingMessageId3", message.getMessageId());234 assertEquals("some url", message.getContentUrl());235 assertTrue(StringUtils.isNotBlank(message.getMessageId()));236 assertEquals("campaignId3", geo.getCampaignId());...

Full Screen

Full Screen

Source:JDBCDatabaseCommunicationEngineTest.java Github

copy

Full Screen

...192 when(sqlStatementContext.getTablesContext().getSchemaNames()).thenReturn(Collections.emptyList());193 JDBCDatabaseCommunicationEngine engine =194 DatabaseCommunicationEngineFactory.getInstance().newBinaryProtocolInstance(sqlStatementContext, "schemaName", Collections.emptyList(), backendConnection);195 engine.add(resultSet);196 Collection<?> actual = getField(engine, "cachedResultSets");197 assertThat(actual.size(), is(1));198 assertThat(actual.iterator().next(), is(resultSet));199 }200 201 @Test202 public void assertCloseCorrectly() throws SQLException {203 SQLStatementContext<?> sqlStatementContext = mock(SQLStatementContext.class, RETURNS_DEEP_STUBS);204 when(sqlStatementContext.getTablesContext().getSchemaNames()).thenReturn(Collections.emptyList());205 JDBCDatabaseCommunicationEngine engine =206 DatabaseCommunicationEngineFactory.getInstance().newBinaryProtocolInstance(sqlStatementContext, "schemaName", Collections.emptyList(), backendConnection);207 Collection<ResultSet> cachedResultSets = getField(engine, "cachedResultSets");208 cachedResultSets.add(resultSet);209 Collection<Statement> cachedStatements = getField(engine, "cachedStatements");210 cachedStatements.add(statement);211 engine.close();212 verify(resultSet).close();213 verify(statement).close();214 assertTrue(cachedResultSets.isEmpty());215 assertTrue(cachedStatements.isEmpty());216 }217 218 @Test219 public void assertCloseResultSetsWithExceptionThrown() throws SQLException {220 SQLStatementContext<?> sqlStatementContext = mock(SQLStatementContext.class, RETURNS_DEEP_STUBS);221 when(sqlStatementContext.getTablesContext().getSchemaNames()).thenReturn(Collections.emptyList());222 JDBCDatabaseCommunicationEngine engine =223 DatabaseCommunicationEngineFactory.getInstance().newBinaryProtocolInstance(sqlStatementContext, "schemaName", Collections.emptyList(), backendConnection);224 Collection<ResultSet> cachedResultSets = getField(engine, "cachedResultSets");225 SQLException sqlExceptionByResultSet = new SQLException("ResultSet");226 doThrow(sqlExceptionByResultSet).when(resultSet).close();227 cachedResultSets.add(resultSet);228 Collection<Statement> cachedStatements = getField(engine, "cachedStatements");229 SQLException sqlExceptionByStatement = new SQLException("Statement");230 doThrow(sqlExceptionByStatement).when(statement).close();231 cachedStatements.add(statement);232 SQLException actual = null;233 try {234 engine.close();235 } catch (final SQLException ex) {236 actual = ex;237 }238 verify(resultSet).close();239 verify(statement).close();240 assertTrue(cachedResultSets.isEmpty());241 assertTrue(cachedStatements.isEmpty());242 assertNotNull(actual);243 assertThat(actual.getNextException(), is(sqlExceptionByResultSet));244 assertThat(actual.getNextException().getNextException(), is(sqlExceptionByStatement));245 }246 247 @SuppressWarnings("unchecked")248 @SneakyThrows249 private <T> T getField(final JDBCDatabaseCommunicationEngine target, final String fieldName) {250 Field field = JDBCDatabaseCommunicationEngine.class.getDeclaredField(fieldName);251 field.setAccessible(true);252 return (T) field.get(target);253 }254}...

Full Screen

Full Screen

Source:DataPointRevokedConsentsJobProcessorImplTest.java Github

copy

Full Screen

...23import org.mockito.ArgumentCaptor;24import org.mockito.Captor;25import org.mockito.InjectMocks;26import org.mockito.Mock;27import org.mockito.internal.util.collections.Sets;28import org.mockito.junit.MockitoJUnitRunner;29import com.elasticpath.domain.customer.Customer;30import com.elasticpath.domain.datapolicy.ConsentAction;31import com.elasticpath.domain.datapolicy.CustomerConsent;32import com.elasticpath.domain.datapolicy.DataPoint;33import com.elasticpath.domain.datapolicy.DataPolicy;34import com.elasticpath.domain.datapolicy.RetentionType;35import com.elasticpath.service.datapolicy.DataPointService;36import com.elasticpath.service.datapolicy.DataPointValueService;37import com.elasticpath.service.datapolicy.job.DataPointValueJob;38/**39 * Tests for {@link DataPointRevokedConsentsJobProcessorImpl}.40 */41@SuppressWarnings("unchecked")42@RunWith(MockitoJUnitRunner.class)43public class DataPointRevokedConsentsJobProcessorImplTest {44 private static final Integer ZERO_DAYS_RETENTION_PERIOD = 0;45 @InjectMocks46 private final DataPointValueJob dataPointValueJob = new DataPointRevokedConsentsJobProcessorImpl();47 @Mock48 private DataPointValueService dataPointValueService;49 @Mock50 private DataPointService dataPointService;51 @Captor52 private ArgumentCaptor<Map<String, ? extends Collection<DataPoint>>> dataPointValueServiceCaptor;53 @Test54 public void verifyNothingHappensWhenNoRevokedConsents() {55 when(dataPointService.findWithRevokedConsentsLatest()).thenReturn(Collections.emptyMap());56 dataPointValueJob.process();57 verifyZeroInteractions(dataPointValueService);58 }59 @Test60 public void verifyJobRemovesAllDataPolicyDataPointValuesForRevokedConsents() {61 Customer customer = buildCustomer();62 CustomerConsent customerConsent = buildCustomerConsent(ConsentAction.REVOKED);63 customerConsent.setCustomerGuid(customer.getGuid());64 DataPolicy dataPolicy = buildDataPolicy(RetentionType.FROM_CREATION_DATE, ZERO_DAYS_RETENTION_PERIOD);65 dataPolicy.getDataPoints().add(buildDataPoint(true, DATAPOINT_KEY_1));66 dataPolicy.getDataPoints().add(buildDataPoint(true, DATAPOINT_KEY_2));67 customerConsent.setDataPolicy(dataPolicy);68 Map<String, Map<DataPoint, Set<DataPolicy>>> customerDataPointDataPolicyMap = new HashMap<>();69 Map<DataPoint, Set<DataPolicy>> dataPointSetMap = new HashMap<>();70 dataPointSetMap.put(dataPolicy.getDataPoints().get(0), Sets.newSet(dataPolicy));71 dataPointSetMap.put(dataPolicy.getDataPoints().get(1), Sets.newSet(dataPolicy));72 customerDataPointDataPolicyMap.put(customerConsent.getCustomerGuid(), dataPointSetMap);73 when(dataPointService.findWithRevokedConsentsLatest()).thenReturn(customerDataPointDataPolicyMap);74 dataPointValueJob.process();75 verify(dataPointValueService).getValues(dataPointValueServiceCaptor.capture());76 verify(dataPointValueService).removeValues(any());77 Map<String, ? extends Collection<DataPoint>> value = dataPointValueServiceCaptor.getValue();78 assertThat(value)79 .hasSize(1);80 assertThat(value.get(customer.getGuid()))81 .hasSize(2);82 }83}...

Full Screen

Full Screen

Source:PropertyAndSetterInjection.java Github

copy

Full Screen

...12import org.mockito.internal.configuration.injection.filter.TerminalMockCandidateFilter;13import org.mockito.internal.configuration.injection.filter.TypeBasedCandidateFilter;14import org.mockito.internal.exceptions.Reporter;15import org.mockito.internal.util.collections.ListUtil;16import org.mockito.internal.util.collections.Sets;17import org.mockito.internal.util.reflection.FieldInitializationReport;18import org.mockito.internal.util.reflection.FieldInitializer;19import org.mockito.internal.util.reflection.SuperTypesLastSorter;20public class PropertyAndSetterInjection extends MockInjectionStrategy {21 private final MockCandidateFilter mockCandidateFilter = new TypeBasedCandidateFilter(new NameBasedCandidateFilter(new TerminalMockCandidateFilter()));22 private final ListUtil.Filter<Field> notFinalOrStatic = new ListUtil.Filter<Field>() {23 public boolean isOut(Field field) {24 return Modifier.isFinal(field.getModifiers()) || Modifier.isStatic(field.getModifiers());25 }26 };27 public boolean processInjection(Field field, Object obj, Set<Object> set) {28 FieldInitializationReport initializeInjectMocksField = initializeInjectMocksField(field, obj);29 Object fieldInstance = initializeInjectMocksField.fieldInstance();30 boolean z = false;31 for (Class fieldClass = initializeInjectMocksField.fieldClass(); fieldClass != Object.class; fieldClass = fieldClass.getSuperclass()) {32 z |= injectMockCandidates(fieldClass, fieldInstance, Sets.newMockSafeHashSet((Iterable<Object>) set));33 }34 return z;35 }36 private FieldInitializationReport initializeInjectMocksField(Field field, Object obj) {37 try {38 return new FieldInitializer(obj, field).initialize();39 } catch (MockitoException e) {40 if (e.getCause() instanceof InvocationTargetException) {41 throw Reporter.fieldInitialisationThrewException(field, e.getCause().getCause());42 }43 throw Reporter.cannotInitializeForInjectMocksAnnotation(field.getName(), e.getMessage());44 }45 }46 private boolean injectMockCandidates(Class<?> cls, Object obj, Set<Object> set) {...

Full Screen

Full Screen

Source:CollectionControllerTest.java Github

copy

Full Screen

...9import org.springframework.data.mongodb.core.MongoOperations;10import org.testng.annotations.BeforeMethod;11import org.testng.annotations.DataProvider;12import org.testng.annotations.Test;13import com.google.common.collect.Sets;14public class CollectionControllerTest15{16 private CollectionController collectionController;17 private MongoOperations mongoOperations;18 @BeforeMethod19 public void setUp() throws Exception20 {21 collectionController = new CollectionController();22 mongoOperations = mock(MongoOperations.class);23 Whitebox.setInternalState(collectionController, "mongodb", mongoOperations);24 }25 @Test(dataProvider = "collections_products_and_version")26 public void getCollections_returns_products_and_versions(Set<String> input, Set<String> expectedOutput) throws IOException27 {28 Mockito.when(mongoOperations.getCollectionNames()).thenReturn(input);29 Set<String> actualCollections = collectionController.getCollections();30 assertEquals(actualCollections, expectedOutput);31 }32 @DataProvider33 public Object[][] collections_products_and_version() {34 return new Object[][] {35 {Collections.singleton("product_version"), Collections.singleton("product_version")},36 {Collections.singleton("productWithoutVersion"), Collections.emptySet()},37 {Collections.singleton("system.indexes"), Collections.emptySet()},38 {Collections.singleton("product_version.chunks"), Collections.emptySet()},39 {Collections.singleton("product_version.files"), Collections.emptySet()}40 };41 }42 @Test(dataProvider = "products_products_and_version")43 public void getProducts(Set<String> input, Set<String> expectedOutput) throws IOException44 {45 Mockito.when(mongoOperations.getCollectionNames()).thenReturn(input);46 Set<String> products = collectionController.getProducts();47 assertEquals(products, expectedOutput);48 }49 @DataProvider50 public Object[][] products_products_and_version() {51 return new Object[][] {52 {Collections.singleton("productA_version"), Collections.singleton("productA")},53 {Sets.newHashSet("productA_version", "productB_version"), Sets.newHashSet("productA", "productB")},54 {Sets.newHashSet("productA_version1","productA_version2", "productB_version"),55 Sets.newHashSet("productA", "productB")},56 };57 }58}...

Full Screen

Full Screen

Source:HierarchicalQuoteServiceTest.java Github

copy

Full Screen

1package io.github.jonestimd.finance.stockquote;2import java.math.BigDecimal;3import java.util.Arrays;4import java.util.Collections;5import com.google.common.collect.Sets;6import io.github.jonestimd.finance.stockquote.StockQuoteService.Callback;7import org.junit.Test;8import org.junit.runner.RunWith;9import org.mockito.Mock;10import org.mockito.junit.MockitoJUnitRunner;11import org.mockito.stubbing.Answer;12import static org.mockito.Mockito.*;13@RunWith(MockitoJUnitRunner.class)14public class HierarchicalQuoteServiceTest {15 @Mock16 private StockQuoteService service1;17 @Mock18 private StockQuoteService service2;19 @Mock20 private Callback callback;21 @Test22 public void callsServicesInOrder() throws Exception {23 doAnswer(getAnswer("S1", BigDecimal.ONE)).when(service1).getPrices(anyCollection(), any(Callback.class));24 doAnswer(getAnswer("S3", BigDecimal.TEN)).when(service2).getPrices(anyCollection(), any(Callback.class));25 HierarchicalQuoteService service = new HierarchicalQuoteService(Arrays.asList(service1, service2));26 service.getPrices(Arrays.asList("S1", "S2", "S3"), callback);27 verify(service1).getPrices(eq(Sets.newHashSet("S1", "S2", "S3")), any(Callback.class));28 verify(service2).getPrices(eq(Sets.newHashSet("S2", "S3")), any(Callback.class));29 verify(callback).accept(Collections.singletonMap("S1", BigDecimal.ONE), null, null, null);30 verify(callback).accept(Collections.singletonMap("S3", BigDecimal.TEN), null, null, null);31 }32 @Test33 public void quitsWhenAllPricesFound() throws Exception {34 doAnswer(getAnswer("S1", BigDecimal.ONE)).when(service1).getPrices(anyCollection(), any(Callback.class));35 HierarchicalQuoteService service = new HierarchicalQuoteService(Arrays.asList(service1, service2));36 service.getPrices(Arrays.asList("S1"), callback);37 verify(service1).getPrices(eq(Sets.newHashSet("S1")), any(Callback.class));38 verifyNoInteractions(service2);39 verify(callback).accept(Collections.singletonMap("S1", BigDecimal.ONE), null, null, null);40 }41 private Answer getAnswer(String symbol, BigDecimal price) {42 return invocation -> {43 Callback internal = (Callback) invocation.getArguments()[1];44 internal.accept(Collections.singletonMap(symbol, price), null, null, null);45 return null;46 };47 }48}...

Full Screen

Full Screen

Source:RegisteredPushButtonTest.java Github

copy

Full Screen

1package com.emirovschi.midps2.calc.gui.controls;2import com.emirovschi.midps2.calc.gui.ButtonRegister;3import org.junit.Test;4import org.mockito.internal.util.collections.Sets;5import java.util.Collections;6import static org.junit.Assert.assertEquals;7import static org.mockito.Mockito.mock;8import static org.mockito.Mockito.verify;9public class RegisteredPushButtonTest10{11 private RegisteredPushButton button = new RegisteredPushButton() {};12 @Test13 public void shouldRegisterItSelf() throws Exception14 {15 final ButtonRegister register = mock(ButtonRegister.class);16 button.setRegister(register);17 verify(register).register(button);18 }19 @Test20 public void shouldGetEmptyKeySet() throws Exception21 {22 assertEquals(Collections.emptySet(), button.getKeys());23 }24 @Test25 public void shouldSetKeyChar() throws Exception26 {27 button.setKeys("+");28 assertEquals(Sets.newSet('+'), button.getKeys());29 }30 @Test31 public void shouldSetKeySpecial() throws Exception32 {33 button.setKeys("\\13");34 assertEquals(Sets.newSet((char) 13), button.getKeys());35 }36 @Test37 public void shouldSetKeyCharAndSpecial() throws Exception38 {39 button.setKeys("+,\\13");40 assertEquals(Sets.newSet('+', (char) 13), button.getKeys());41 }42}...

Full Screen

Full Screen

Sets

Using AI Code Generation

copy

Full Screen

1import org.mockito.internal.util.collections.Sets;2import java.util.Set;3public class SetsExample {4 public static void main(String[] args) {5 Set<String> set1 = Sets.newSet("one", "two", "three");6 Set<String> set2 = Sets.newSet("one", "two", "three");7 Set<String> set3 = Sets.newSet("one", "two", "three", "four");8 System.out.println("set1.equals(set2) = " + set1.equals(set2));9 System.out.println("set1.equals(set3) = " + set1.equals(set3));10 }11}12set1.equals(set2) = true13set1.equals(set3) = false

Full Screen

Full Screen

Sets

Using AI Code Generation

copy

Full Screen

1import org.mockito.internal.util.collections.Sets;2import java.util.Set;3public class SetsExample {4 public static void main(String[] args) {5 Set<String> set1 = Sets.newSet("one", "two", "three");6 Set<String> set2 = Sets.newSet("one", "two", "three", "four");7 Set<String> set3 = Sets.newSet("one", "two", "three");8 System.out.println("Is set1 contains all elements of set2? " + set1.containsAll(set2));9 System.out.println("Is set2 contains all elements of set1? " + set2.containsAll(set1));10 System.out.println("Is set1 contains all elements of set3? " + set1.containsAll(set3));11 System.out.println("Is set3 contains all elements of set1? " + set3.containsAll(set1));12 }13}14import java.util.Set;15import java.util.HashSet;16public class SetExample {17 public static void main(String[] args) {18 Set<String> set = new HashSet<String>();19 set.add("one");20 set.add("two");21 set.add("three");22 set.add("three");23 System.out.println(set);24 }25}26import java.util.Set;27import java.util.HashSet;28public class SetExample {29 public static void main(String[] args) {30 Set<String> set = new HashSet<String>();31 set.add("one");32 set.add("two");33 set.add("three");

Full Screen

Full Screen

Sets

Using AI Code Generation

copy

Full Screen

1import org.mockito.internal.util.collections.Sets;2import java.util.Set;3public class SetsExample {4 public static void main(String[] args) {5 Set<String> set1 = Sets.newSet("A", "B", "C");6 Set<String> set2 = Sets.newSet("B", "C", "D");7 System.out.println("Set 1: " + set1);8 System.out.println("Set 2: " + set2);9 System.out.println("Set 1 union Set 2: " + Sets.union(set1, set2));10 System.out.println("Set 1 intersection Set 2: " + Sets.intersection(set1, set2));11 System.out.println("Set 1 difference Set 2: " + Sets.difference(set1, set2));12 System.out.println("Set 2 difference Set 1: " + Sets.difference(set2, set1));13 }14}

Full Screen

Full Screen

Sets

Using AI Code Generation

copy

Full Screen

1import org.mockito.internal.util.collections.Sets;2import java.util.Set;3import java.util.HashSet;4import java.util.Iterator;5public class SetsTest {6 public static void main(String[] args) {7 Set set1 = new HashSet();8 set1.add("A");9 set1.add("B");10 set1.add("C");11 Set set2 = new HashSet();12 set2.add("C");13 set2.add("D");14 set2.add("E");15 System.out.println("Set1: " + set1);16 System.out.println("Set2: " + set2);17 Set union = Sets.union(set1, set2);18 System.out.println("Union: " + union);19 Set intersection = Sets.intersection(set1, set2);20 System.out.println("Intersection: " + intersection);21 Set difference = Sets.difference(set1, set2);22 System.out.println("Difference: " + difference);23 }24}

Full Screen

Full Screen

Sets

Using AI Code Generation

copy

Full Screen

1import org.mockito.internal.util.collections.Sets;2import java.util.Set;3public class SetTest {4 public static void main(String[] args) {5 Set<String> set1 = Sets.newSet("a", "b", "c");6 Set<String> set2 = Sets.newSet("a", "b", "c");7 System.out.println(set1.equals(set2));8 }9}10Collections.sort() method in Java with Examples11Collections.binarySearch() method in Java with Examples12Collections.frequency() method in Java with Examples13Collections.disjoint() method in Java with Examples14Collections.addAll() method in Java with Examples15Collections.max() method in Java with Examples16Collections.min() method in Java with Examples17Collections.nCopies() method in Java with Examples18Collections.copy() method in Java with Examples19Collections.replaceAll() method in Java with Examples20Collections.indexOfSubList() method in Java with Examples21Collections.lastIndexOfSubList() method in Java with Examples22Collections.rotate() method in Java with Examples23Collections.shuffle() method in Java with Examples24Collections.reverse() method in Java with Examples25Collections.swap() method in Java with Examples26Collections.fill() method in Java with Examples27Collections.singleton() method in Java with Examples

Full Screen

Full Screen

Sets

Using AI Code Generation

copy

Full Screen

1import org.mockito.internal.util.collections.Sets;2import java.util.Set;3public class SetsDemo {4 public static void main(String[] args) {5 Set<String> set = Sets.newSet("one", "two", "three");6 System.out.println(set);7 }8}

Full Screen

Full Screen

Sets

Using AI Code Generation

copy

Full Screen

1package com.automationrhapsody.mockito;2import java.util.HashSet;3import java.util.Set;4import org.mockito.internal.util.collections.Sets;5public class SetsExample {6public static void main(String[] args) {7Set<String> set1 = new HashSet<>();8set1.add("one");9set1.add("two");10Set<String> set2 = new HashSet<>();11set2.add("one");12set2.add("three");13System.out.println("set1: " + set1);14System.out.println("set2: " + set2);15Set<String> union = Sets.union(set1, set2);16System.out.println("union: " + union);17Set<String> intersection = Sets.intersection(set1, set2);18System.out.println("intersection: " + intersection);19}20}

Full Screen

Full Screen

Sets

Using AI Code Generation

copy

Full Screen

1import org.mockito.internal.util.collections.Sets;2public class SetsDemo {3 public static void main(String[] args) {4 Set<String> set1 = new HashSet<String>();5 set1.add("a");6 set1.add("b");7 set1.add("c");8 set1.add("d");9 Set<String> set2 = new HashSet<String>();10 set2.add("b");11 set2.add("c");12 set2.add("d");13 set2.add("e");14 Set<String> set3 = new HashSet<String>();15 set3.add("b");16 set3.add("c");17 set3.add("d");18 set3.add("e");19 Set<String> set4 = new HashSet<String>();20 set4.add("a");21 set4.add("b");22 set4.add("c");23 set4.add("d");24 System.out.println("set1 and set2 are disjoint: " + Sets.isSet1DisjointFromSet2(set1, set2));25 System.out.println("set2 and set3 are disjoint: " + Sets.isSet1DisjointFromSet2(set2, set3));26 System.out.println("set1 and set4 are disjoint: " + Sets.isSet1DisjointFromSet2(set1, set4));27 System.out.println("set1 and set2 are equal: " + Sets.isSet1EqualToSet2(set1, set2));28 System.out.println("set2 and set3 are equal: " + Sets.isSet1EqualToSet2(set2, set3));29 System.out.println("set1 and set4 are equal: " + Sets.isSet1EqualToSet2(set1, set4));30 }31}

Full Screen

Full Screen

Sets

Using AI Code Generation

copy

Full Screen

1import org.mockito.internal.util.collections.Sets;2public class SetsExample {3 public static void main(String args[]) {4 Set<String> set = Sets.newSet("one", "two", "three");5 System.out.println(set);6 }7}

Full Screen

Full Screen

Sets

Using AI Code Generation

copy

Full Screen

1import org.mockito.internal.util.collections.Sets;2import java.util.Set;3public class TestSets {4 public static void main(String[] args) {5 Set<String> set1 = Sets.newSet("one", "two");6 Set<String> set2 = Sets.newSet("three", "four");7 Set<String> set3 = Sets.newSet("one", "two", "three", "four");8 Set<String> set4 = Sets.newSet("one", "two", "three", "four");9 System.out.println("set1 = " + set1);10 System.out.println("set2 = " + set2);11 System.out.println("set3 = " + set3);12 System.out.println("set4 = " + set4);13 System.out.println("set3.equals(set4) = " + set3.equals(set4));14 }15}16set3.equals(set4) =

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Mockito automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used methods in Sets

Test Your Web Or Mobile Apps On 3000+ Browsers

Signup for free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful