001    /**
002     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.test;
016    
017    import com.liferay.portal.kernel.messaging.DestinationNames;
018    import com.liferay.portal.util.test.MailServiceTestUtil;
019    
020    import org.junit.runner.Description;
021    
022    /**
023     * @author Manuel de la Pe??a
024     * @author Roberto D??az
025     * @author Shuyang Zhou
026     */
027    public class SynchronousMailTestRule extends SynchronousDestinationTestRule {
028    
029            public static final SynchronousMailTestRule INSTANCE =
030                    new SynchronousMailTestRule();
031    
032            @Override
033            protected void afterClass(
034                    Description description, SyncHandler syncHandler) {
035    
036                    syncHandler.restorePreviousSync();
037    
038                    MailServiceTestUtil.stop();
039            }
040    
041            @Override
042            protected void afterMethod(
043                    Description description, SyncHandler syncHandler) {
044    
045                    super.afterMethod(description, syncHandler);
046    
047                    MailServiceTestUtil.clearMessages();
048            }
049    
050            @Override
051            protected SyncHandler beforeClass(Description description) {
052                    MailServiceTestUtil.start();
053    
054                    SyncHandler syncHandler = new SyncHandler();
055    
056                    syncHandler.replaceDestination(DestinationNames.MAIL);
057    
058                    return syncHandler;
059            }
060    
061            private SynchronousMailTestRule() {
062            }
063    
064    }