|
| 1 | +/** |
| 2 | + * Copyright (C) 2010-2015 eBusiness Information, Excilys Group |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); you may not |
| 5 | + * use this file except in compliance with the License. You may obtain a copy of |
| 6 | + * the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed To in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 12 | + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 13 | + * License for the specific language governing permissions and limitations under |
| 14 | + * the License. |
| 15 | + */ |
| 16 | +package org.androidannotations.generation; |
| 17 | + |
| 18 | +import java.io.File; |
| 19 | + |
| 20 | +import org.androidannotations.AndroidAnnotationProcessor; |
| 21 | +import org.androidannotations.utils.AAProcessorTestHelper; |
| 22 | +import org.junit.Before; |
| 23 | +import org.junit.Test; |
| 24 | + |
| 25 | +public class ContextCompatDrawableTest extends AAProcessorTestHelper { |
| 26 | + |
| 27 | + private static final String DRAWABLE_SIGNATURE = ".*myDrawable = resources_\\.getDrawable\\(drawable\\.myDrawable\\);.*"; |
| 28 | + private static final String DRAWABLE_VIA_SUPPORT_SIGNATURE = ".*myDrawable = ContextCompat\\.getDrawable\\(this, drawable\\.myDrawable\\);.*"; |
| 29 | + |
| 30 | + @Before |
| 31 | + public void setUp() { |
| 32 | + addProcessor(AndroidAnnotationProcessor.class); |
| 33 | + addManifestProcessorParameter(ContextCompatDrawableTest.class, "AndroidManifestForDrawable.xml"); |
| 34 | + } |
| 35 | + |
| 36 | + @Test |
| 37 | + public void activityCompilesWithRegularDrawable() { |
| 38 | + CompileResult result = compileFiles(ActivityWithDrawable.class); |
| 39 | + File generatedFile = toGeneratedFile(ActivityWithDrawable.class); |
| 40 | + |
| 41 | + assertCompilationSuccessful(result); |
| 42 | + assertGeneratedClassMatches(generatedFile, DRAWABLE_SIGNATURE); |
| 43 | + } |
| 44 | + |
| 45 | + @Test |
| 46 | + public void activityCompilesWithContextCompatDrawable() { |
| 47 | + // To simulate android support v4 in classpath, we add |
| 48 | + // android.support.v4.content.ContextCompat |
| 49 | + // in classpath |
| 50 | + CompileResult result = compileFiles(toPath(ContextCompatDrawableTest.class, "ContextCompat.java"), ActivityWithDrawable.class); |
| 51 | + File generatedFile = toGeneratedFile(ActivityWithDrawable.class); |
| 52 | + |
| 53 | + assertCompilationSuccessful(result); |
| 54 | + assertGeneratedClassMatches(generatedFile, DRAWABLE_VIA_SUPPORT_SIGNATURE); |
| 55 | + } |
| 56 | +} |
0 commit comments