• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2015 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of 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,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package vogar.android;
18 
19 import com.google.common.base.Joiner;
20 import com.google.common.base.Supplier;
21 import java.io.File;
22 import java.io.IOException;
23 import junit.framework.AssertionFailedError;
24 import org.junit.Before;
25 import org.junit.Rule;
26 import org.mockito.Mock;
27 import vogar.Action;
28 import vogar.Classpath;
29 import vogar.Console;
30 import vogar.HostFileCache;
31 import vogar.Language;
32 import vogar.Mode;
33 import vogar.Run;
34 import vogar.Target;
35 import vogar.Toolchain;
36 import vogar.Vogar;
37 import vogar.commands.Mkdir;
38 import vogar.commands.Rm;
39 import vogar.commands.VmCommandBuilder;
40 
41 /**
42  * Base class for tests of {@link Mode} implementations.
43  */
44 public abstract class AbstractModeTest {
45 
46     @Rule
47     public VogarArgsRule vogarArgsRule = new VogarArgsRule();
48 
49     @Mock protected Console console;
50 
51     protected Mkdir mkdir;
52 
53     protected Rm rm;
54 
55     protected AndroidSdk androidSdk;
56 
57     protected Classpath classpath;
58 
59     protected Run run;
60 
61     protected Supplier<String> deviceUserNameSupplier = new Supplier<String>() {
62         @Override
63         public String get() {
64             return "fred";
65         }
66     };
67 
68     @Before
setUp()69     public void setUp() throws IOException {
70         mkdir = new Mkdir(console);
71         rm = new Rm(console);
72 
73         androidSdk = new AndroidSdk(console, mkdir,
74                 new File[] {new File("classpath")}, "android.jar", "desugar.jar",
75                 new HostFileCache(console, mkdir),
76                 Language.CUR);
77         Target target = createTarget();
78 
79         final Vogar vogar = new Vogar();
80         String[] args = vogarArgsRule.getTestSpecificArgs();
81         if (!vogar.parseArgs(args)) {
82             throw new AssertionFailedError("Parse error in: " + Joiner.on(",").join(args)
83                     + ". Please check stdout.");
84         }
85 
86         run = new Run(vogar, Toolchain.DX, console, mkdir, androidSdk, new Rm(console), target,
87                 new File("runner/dir"));
88 
89         classpath = new Classpath();
90         classpath.addAll(new File("classes"));
91     }
92 
createTarget()93     protected abstract Target createTarget();
94 
newVmCommandBuilder(Mode mode)95     protected VmCommandBuilder newVmCommandBuilder(Mode mode) {
96         Action action = new Action("action", "blah", new File("resources"), new File("source"),
97                 new File("java"));
98         return mode.newVmCommandBuilder(action, new File("/work"));
99     }
100 }
101