@isTest private class EmailComeBackListenTest { static testMethod void testMethod1() { User_FaultInfo__c ca = new User_FaultInfo__c(); ca.ORIGIN__c = 'Web'; ca.SUBJECT__c = 'test'; ca.OFFICE_OWNER__c = 'Beijing'; ca.Product_Type__c = 'NDT'; ca.TYPE__c = 'Service'; ca.LOGISTICS_SHIPMENT_TYPE__c = 'Domestic'; ca.STATUS__c = 'Not Started'; ca.PRIORITY__c = 'High'; insert ca; User_FaultInfo__c cas = [select Name from User_FaultInfo__c where Id =: ca.Id]; List toAddressesList = new List(); toAddressesList.add('dai_prectech@olympus.com.cn'); List ccAddressesList = new List(); ccAddressesList.add('dai_prectech@olympus.com.cn'); Messaging.InboundEmail email = new Messaging.InboundEmail(); email.fromAddress = 'dai_prectech@olympus.com.cn'; email.toAddresses = toAddressesList; email.ccAddresses = ccAddressesList; email.plainTextBody = 'test'; email.subject = 'test~Ctest:'+cas.Name; EmailComeBackListen listen = new EmailComeBackListen(); listen.handleInboundEmail(email, new Messaging.InboundEnvelope()); ca.notSaveEmail__c = true; update ca; listen.handleInboundEmail(email, new Messaging.InboundEnvelope()); } static testMethod void testMethod2() { SWO__c swo = new SWO__c(); swo.Name = 'test2'; swo.QUANTITY__c = 22; swo.ESTIMATED_LABOUR_HOURS__c = 22; swo.LABOUR_RATE__c = 22; insert swo; List toAddressesList = new List(); toAddressesList.add('dai_prectech@olympus.com.cn'); List ccAddressesList = new List(); ccAddressesList.add('dai_prectech@olympus.com.cn'); Messaging.InboundEmail email = new Messaging.InboundEmail(); email.fromAddress = 'dai_prectech@olympus.com.cn'; email.toAddresses = toAddressesList; email.ccAddresses = ccAddressesList; email.plainTextBody = 'test'; email.subject = 'test~Stest:'+swo.Name; EmailComeBackListen listen = new EmailComeBackListen(); listen.handleInboundEmail(email, new Messaging.InboundEnvelope()); swo.notSaveEmail__c = true; update swo; listen.handleInboundEmail(email, new Messaging.InboundEnvelope()); } static testMethod void testMethod3() { SWO__c swo = new SWO__c(); swo.Name = 'test3'; swo.QUANTITY__c = 22; swo.ESTIMATED_LABOUR_HOURS__c = 22; swo.LABOUR_RATE__c = 22; insert swo; Quotes__c quotes = new Quotes__c(); quotes.Name = 'test4'; quotes.SWO__c = swo.Id; quotes.QuotesType__c = '零件报价单'; insert quotes; Quotes__c quo = [select Name from Quotes__c where Id =: quotes.Id]; List toAddressesList = new List(); toAddressesList.add('dai_prectech@olympus.com.cn'); List ccAddressesList = new List(); ccAddressesList.add('dai_prectech@olympus.com.cn'); Messaging.InboundEmail email = new Messaging.InboundEmail(); email.fromAddress = 'dai_prectech@olympus.com.cn'; email.toAddresses = toAddressesList; email.ccAddresses = ccAddressesList; email.plainTextBody = 'test'; email.subject = 'test~Qtest:'+quo.Name; EmailComeBackListen listen = new EmailComeBackListen(); listen.handleInboundEmail(email, new Messaging.InboundEnvelope()); quotes.notSaveEmail__c = true; update quotes; listen.handleInboundEmail(email, new Messaging.InboundEnvelope()); } }