blob: d3d09bc0f167f3a0b1291529b169a9f795e48570 [file] [log] [blame] [view]
Skyler Kaufman991ae4d2011-04-07 12:30:41 -07001# Code Style Guidelines for Contributors #
2
3The rules below are not guidelines or recommendations, but strict rules.
4Contributions to Android generally *will not be accepted* if they do not
5adhere to these rules.
6
7Not all existing code follows these rules, but all new code is expected to.
8
9[TOC]
10
11## Java Language Rules ##
12
13We follow standard Java coding conventions. We add a few rules:
14
15### Don't Ignore Exceptions ###
16
17Sometimes it is tempting to write code that completely ignores an exception
18like this:
19
20<!--div style="display: inline-block"> <!-- Just to make the code not overlap the ToC -->
21
22 void setServerPort(String value) {
23 try {
24 serverPort = Integer.parseInt(value);
25 } catch (NumberFormatException e) { }
26 }
27
28<!-- /div -->
29
30You must never do this. While you may think that your code will never
31encounter this error condition or that it is not important to handle it,
32ignoring exceptions like above creates mines in your code for someone else to
33trip over some day. You must handle every Exception in your code in some
34principled way. The specific handling varies depending on the case.
35
36*Anytime somebody has an empty catch clause they should have a
37creepy feeling. There are definitely times when it is actually the correct
38thing to do, but at least you have to think about it. In Java you can't escape
39the creepy feeling.* -[James Gosling](http://www.artima.com/intv/solid4.html)
40
41Acceptable alternatives (in order of preference) are:
42
43- Throw the exception up to the caller of your method.
44
45 void setServerPort(String value) throws NumberFormatException {
46 serverPort = Integer.parseInt(value);
47 }
48
49- Throw a new exception that's appropriate to your level of abstraction.
50
51 void setServerPort(String value) throws ConfigurationException {
52 try {
53 serverPort = Integer.parseInt(value);
54 } catch (NumberFormatException e) {
55 throw new ConfigurationException("Port " + value + " is not valid.");
56 }
57 }
58
59- Handle the error gracefully and substitute an appropriate value in the
60catch {} block.
61
62 /** Set port. If value is not a valid number, 80 is substituted. */
63
64 void setServerPort(String value) {
65 try {
66 serverPort = Integer.parseInt(value);
67 } catch (NumberFormatException e) {
68 serverPort = 80; // default port for server
69 }
70 }
71
72- Catch the Exception and throw a new `RuntimeException`. This is dangerous:
73only do it if you are positive that if this error occurs, the appropriate
74thing to do is crash.
75
76 /** Set port. If value is not a valid number, die. */
77
78 void setServerPort(String value) {
79 try {
80 serverPort = Integer.parseInt(value);
81 } catch (NumberFormatException e) {
82 throw new RuntimeException("port " + value " is invalid, ", e);
83 }
84 }
85
86 Note that the original exception is passed to the constructor for
87 RuntimeException. If your code must compile under Java 1.3, you will need to
88 omit the exception that is the cause.
89
90- Last resort: if you are confident that actually ignoring the exception is
91appropriate then you may ignore it, but you must also comment why with a good
92reason:
93
94 /** If value is not a valid number, original port number is used. */
95 void setServerPort(String value) {
96 try {
97 serverPort = Integer.parseInt(value);
98 } catch (NumberFormatException e) {
99 // Method is documented to just ignore invalid user input.
100 // serverPort will just be unchanged.
101 }
102 }
103
104### Don't Catch Generic Exception ###
105
106Sometimes it is tempting to be lazy when catching exceptions and do
107something like this:
108
109 try {
110 someComplicatedIOFunction(); // may throw IOException
111 someComplicatedParsingFunction(); // may throw ParsingException
112 someComplicatedSecurityFunction(); // may throw SecurityException
113 // phew, made it all the way
114 } catch (Exception e) { // I'll just catch all exceptions
115 handleError(); // with one generic handler!
116 }
117
118You should not do this. In almost all cases it is inappropriate to catch
119generic Exception or Throwable, preferably not Throwable, because it includes
120Error exceptions as well. It is very dangerous. It means that Exceptions you
121never expected (including RuntimeExceptions like ClassCastException) end up
122getting caught in application-level error handling. It obscures the failure
123handling properties of your code. It means if someone adds a new type of
124Exception in the code you're calling, the compiler won't help you realize you
125need to handle that error differently. And in most cases you shouldn't be
126handling different types of exception the same way, anyway.
127
128There are rare exceptions to this rule: certain test code and top-level
129code where you want to catch all kinds of errors (to prevent them from showing
130up in a UI, or to keep a batch job running). In that case you may catch
131generic Exception (or Throwable) and handle the error appropriately. You
132should think very carefully before doing this, though, and put in comments
133explaining why it is safe in this place.
134
135Alternatives to catching generic Exception:
136
137- Catch each exception separately as separate catch blocks after a single
138try. This can be awkward but is still preferable to catching all Exceptions.
139Beware repeating too much code in the catch blocks.</li>
140
141- Refactor your code to have more fine-grained error handling, with multiple
142try blocks. Split up the IO from the parsing, handle errors separately in each
143case.
144
145- Rethrow the exception. Many times you don't need to catch the exception at
146this level anyway, just let the method throw it.
147
148Remember: exceptions are your friend! When the compiler complains you're
149not catching an exception, don't scowl. Smile: the compiler just made it
150easier for you to catch runtime problems in your code.
151
152### Don't Use Finalizers ###
153
154Finalizers are a way to have a chunk of code executed
155when an object is garbage collected.
156
157Pros: can be handy for doing cleanup, particularly of external resources.
158
159Cons: there are no guarantees as to when a finalizer will be called,
160or even that it will be called at all.
161
162Decision: we don't use finalizers. In most cases, you can do what
163you need from a finalizer with good exception handling. If you absolutely need
164it, define a close() method (or the like) and document exactly when that
165method needs to be called. See InputStream for an example. In this case it is
166appropriate but not required to print a short log message from the finalizer,
167as long as it is not expected to flood the logs.
168
169### Fully Qualify Imports ###
170
171When you want to use class Bar from package foo,there
172are two possible ways to import it:
173
1741. `import foo.*;`
175
176Pros: Potentially reduces the number of import statements.
177
1781. `import foo.Bar;`
179
180Pros: Makes it obvious what classes are actually used. Makes
181code more readable for maintainers.
182
183Decision: Use the latter for importing all Android code. An explicit
184exception is made for java standard libraries (`java.util.*`, `java.io.*`, etc.)
185and unit test code (`junit.framework.*`)
186
187## Java Library Rules ##
188
189There are conventions for using Android's Java libraries and tools. In some
190cases, the convention has changed in important ways and older code might use a
191deprecated pattern or library. When working with such code, it's okay to
192continue the existing style (see [Consistency](#consistency)). When
193creating new components never use deprecated libraries.
194
195## Java Style Rules ##
196
197### Use Javadoc Standard Comments ###
198
199Every file should have a copyright statement at the top. Then a package
200statement and import statements should follow, each block separated by a blank
201line. And then there is the class or interface declaration. In the Javadoc
202comments, describe what the class or interface does.
203
204 /*
205 * Copyright (C) 2010 The Android Open Source Project
206 *
207 * Licensed under the Apache License, Version 2.0 (the "License");
208 * you may not use this file except in compliance with the License.
209 * You may obtain a copy of the License at
210 *
211 * http://www.apache.org/licenses/LICENSE-2.0
212 *
213 * Unless required by applicable law or agreed to in writing, software
214 * distributed under the License is distributed on an "AS IS" BASIS,
215 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
216 * See the License for the specific language governing permissions and
217 * limitations under the License.
218 */
219
220 package com.android.internal.foo;
221
222 import android.os.Blah;
223 import android.view.Yada;
224
225 import java.sql.ResultSet;
226 import java.sql.SQLException;
227
228 /**
229 * Does X and Y and provides an abstraction for Z.
230 */
231
232 public class Foo {
233 ...
234 }
235
236Every class and nontrivial public method you write *must* contain a
237Javadoc comment with at least one sentence describing what the class or method
238does. This sentence should start with a 3rd person descriptive verb.
239
240Examples:
241
242 /** Returns the correctly rounded positive square root of a double value. */
243 static double sqrt(double a) {
244 ...
245 }
246
247or
248
249 /**
250 * Constructs a new String by converting the specified array of
251 * bytes using the platform's default character encoding.
252 */
253 public String(byte[] bytes) {
254 ...
255 }
256
257You do not need to write Javadoc for trivial get and set methods such as
258`setFoo()` if all your Javadoc would say is "sets Foo". If the method does
259something more complex (such as enforcing a constraint or having an important
260side effect), then you must document it. And if it's not obvious what the
261property "Foo" means, you should document it.
262
263Every method you write, whether public or otherwise, would benefit from
264Javadoc. Public methods are part of an API and therefore require Javadoc.
265
266Android does not currently enforce a specific style for writing Javadoc
267comments, but you should follow the
268[Sun Javadoc conventions](http://java.sun.com/j2se/javadoc/writingdoccomments/).
269
270### Write Short Methods ###
271
272To the extent that it is feasible, methods should be kept small and
273focused. It is, however, recognized that long methods are sometimes
274appropriate, so no hard limit is placed on method length. If a method exceeds
27540 lines or so, think about whether it can be broken up without harming the
276structure of the program.
277
278### Define Fields in Standard Places ###
279
280Fields should be defined either at the top of the file, or immediately before the methods that use them.
281
282### Limit Variable Scope ###
283
284The scope of local variables should be kept to a minimum (*Effective
285Java* Item 29). By doing so, you increase the readability and
286maintainability of your code and reduce the likelihood of error. Each variable
287should be declared in the innermost block that encloses all uses of the
288variable.
289
290Local variables should be declared at the point they are first used. Nearly
291every local variable declaration should contain an initializer. If you don't
292yet have enough information to initialize a variable sensibly, you should
293postpone the declaration until you do.
294
295One exception to this rule concerns try-catch statements. If a variable is
296initialized with the return value of a method that throws a checked exception,
297it must be initialized inside a try block. If the value must be used outside
298of the try block, then it must be declared before the try block, where it
299cannot yet be sensibly initialized:
300
301 // Instantiate class cl, which represents some sort of Set
302 Set s = null;
303 try {
304 s = (Set) cl.newInstance();
305 } catch(IllegalAccessException e) {
306 throw new IllegalArgumentException(cl + " not accessible");
307 } catch(InstantiationException e) {
308 throw new IllegalArgumentException(cl + " not instantiable");
309 }
310
311 // Exercise the set
312 s.addAll(Arrays.asList(args));
313
314But even this case can be avoided by encapsulating the try-catch block in a method:
315
316 Set createSet(Class cl) {
317 // Instantiate class cl, which represents some sort of Set
318 try {
319 return (Set) cl.newInstance();
320 } catch(IllegalAccessException e) {
321 throw new IllegalArgumentException(cl + " not accessible");
322 } catch(InstantiationException e) {
323 throw new IllegalArgumentException(cl + " not instantiable");
324 }
325 }
326
327 ...
328
329 // Exercise the set
330 Set s = createSet(cl);
331 s.addAll(Arrays.asList(args));
332
333Loop variables should be declared in the for statement itself unless there
334is a compelling reason to do otherwise:
335
336 for (int i = 0; i n; i++) {
337 doSomething(i);
338 }
339
340and
341
342 for (Iterator i = c.iterator(); i.hasNext(); ) {
343 doSomethingElse(i.next());
344 }
345
346### Order Import Statements ###
347
348The ordering of import statements is:
349
3501. Android imports
351
3521. Imports from third parties (`com`, `junit`, `net`, `org`)
353
3541. `java` and `javax`
355
356To exactly match the IDE settings, the imports should be:
357
358- Alphabetical within each grouping, with capital letters before lower case letters (e.g. Z before a).
359
360- There should be a blank line between each major grouping (`android`, `com`, `junit`, `net`, `org`, `java`, `javax`).
361
362Originally there was no style requirement on the ordering. This meant that
363the IDE's were either always changing the ordering, or IDE developers had to
364disable the automatic import management features and maintain the imports by
365hand. This was deemed bad. When java-style was asked, the preferred styles
366were all over the map. It pretty much came down to our needing to "pick an
367ordering and be consistent." So we chose a style, updated the style guide, and
368made the IDEs obey it. We expect that as IDE users work on the code, the
369imports in all of the packages will end up matching this pattern without any
370extra engineering effort.
371
372This style was chosen such that:
373
374- The imports people want to look at first tend to be at the top (`android`)
375
376- The imports people want to look at least tend to be at the bottom (`java`)
377
378- Humans can easily follow the style
379
380- IDEs can follow the style
381
382The use and location of static imports have been mildly controversial
383issues. Some people would prefer static imports to be interspersed with the
384remaining imports, some would prefer them reside above or below all other
385imports. Additinally, we have not yet come up with a way to make all IDEs use
386the same ordering.
387
388Since most people consider this a low priority issue, just use your
389judgement and please be consistent.
390
391### Use Spaces for Indentation ###
392
393We use 4 space indents for blocks. We never use tabs. When in doubt, be
394consistent with code around you.
395
396We use 8 space indents for line wraps, including function calls and
397assignments. For example, this is correct:
398
399 Instrument i =
400 someLongExpression(that, wouldNotFit, on, one, line);
401
402and this is not correct:
403
404 Instrument i =
405 someLongExpression(that, wouldNotFit, on, one, line);
406
407### Follow Field Naming Conventions ###
408
409- Non-public, non-static field names start with m.
410
411- Static field names start with s.
412
413- Other fields start with a lower case letter.
414
415- Public static final fields (constants) are ALL_CAPS_WITH_UNDERSCORES.
416
417For example:
418
419 public class MyClass {
420 public static final int SOME_CONSTANT = 42;
421 public int publicField;
422 private static MyClass sSingleton;
423 int mPackagePrivate;
424 private int mPrivate;
425 protected int mProtected;
426 }
427
428### Use Standard Brace Style ###
429
430Braces do not go on their own line; they go on the same line as the code
431before them. So:
432
433 class MyClass {
434 int func() {
435 if (something) {
436 // ...
437 } else if (somethingElse) {
438 // ...
439 } else {
440 // ...
441 }
442 }
443 }
444
445We require braces around the statements for a conditional. Except, if the
446entire conditional (the condition and the body) fit on one line, you may (but
447are not obligated to) put it all on one line. That is, this is legal:
448
449 if (condition) {
450 body();
451 }
452
453and this is legal:
454
455 if (condition) body();
456
457but this is still illegal:
458
459 if (condition)
460 body(); // bad!
461
462### Limit Line Length ###
463
464Each line of text in your code should be at most 100 characters long.
465
466There has been lots of discussion about this rule and the decision remains
467that 100 characters is the maximum.
468
469Exception: if a comment line contains an example command or a literal URL
470longer than 100 characters, that line may be longer than 100 characters for
471ease of cut and paste.
472
473Exception: import lines can go over the limit because humans rarely see
474them. This also simplifies tool writing.
475
476### Use Standard Java Annotations ###
477
478Annotations should precede other modifiers for the same language element.
479Simple marker annotations (e.g. @Override) can be listed on the same line with
480the language element. If there are multiple annotations, or parameterized
481annotations, they should each be listed one-per-line in alphabetical
482order.<
483
484Android standard practices for the three predefined annotations in Java are:
485
486- `@Deprecated`: The @Deprecated annotation must be used whenever the use of the annotated
487element is discouraged. If you use the @Deprecated annotation, you must also
488have a @deprecated Javadoc tag and it should name an alternate implementation.
489In addition, remember that a @Deprecated method is *still supposed to
490work.*
491
492 If you see old code that has a @deprecated Javadoc tag, please add the @Deprecated annotation.
493
494- `@Override`: The @Override annotation must be used whenever a method overrides the
495declaration or implementation from a super-class.
496
497 For example, if you use the @inheritdocs Javadoc tag, and derive from a
498 class (not an interface), you must also annotate that the method @Overrides
499 the parent class's method.
500
501- `@SuppressWarnings`: The @SuppressWarnings annotation should only be used under circumstances
502where it is impossible to eliminate a warning. If a warning passes this
503"impossible to eliminate" test, the @SuppressWarnings annotation *must* be
504used, so as to ensure that all warnings reflect actual problems in the
505code.
506
507 When a @SuppressWarnings annotation is necessary, it must be prefixed with
508 a TODO comment that explains the "impossible to eliminate" condition. This
509 will normally identify an offending class that has an awkward interface. For
510 example:
511
512 // TODO: The third-party class com.third.useful.Utility.rotate() needs generics
513 @SuppressWarnings("generic-cast")
514 List<String> blix = Utility.rotate(blax);
515
516 When a @SuppressWarnings annotation is required, the code should be
517 refactored to isolate the software elements where the annotation applies.
518
519### Treat Acronyms as Words ###
520
521Treat acronyms and abbreviations as words in naming variables, methods, and classes. The names are much more readable:
522
523Good | Bad
524---------------|-------
525XmlHttpRequest | XMLHTTPRequest
526getCustomerId | getCustomerID
527class Html | class HTML
528String url | String URL
529long id | long ID
530
531Both the JDK and the Android code bases are very inconsistent with regards
532to acronyms, therefore, it is virtually impossible to be consistent with the
533code around you. Bite the bullet, and treat acronyms as words.
534
535For further justifications of this style rule, see *Effective Java*
536Item 38 and *Java Puzzlers* Number 68.
537
538### Use TODO Comments ###
539
540Use TODO comments for code that is temporary, a short-term solution, or
541good-enough but not perfect.
542
543TODOs should include the string TODO in all caps, followed by a colon:
544
545 // TODO: Remove this code after the UrlTable2 has been checked in.
546
547and
548
549 // TODO: Change this to use a flag instead of a constant.
550
551If your TODO is of the form "At a future date do something" make sure that
552you either include a very specific date ("Fix by November 2005") or a very
553specific event ("Remove this code after all production mixers understand
554protocol V7.").
555
556### Log Sparingly ###
557
558While logging is necessary it has a significantly negative impact on
559performance and quickly loses its usefulness if it's not kept reasonably
560terse. The logging facilities provides five different levels of logging. Below
561are the different levels and when and how they should be used.
562
563- `ERROR`:
564This level of logging should be used when something fatal has happened,
565i.e. something that will have user-visible consequences and won't be
566recoverable without explicitly deleting some data, uninstalling applications,
567wiping the data partitions or reflashing the entire phone (or worse). This
568level is always logged. Issues that justify some logging at the ERROR level
569are typically good candidates to be reported to a statistics-gathering
570server.
571
572- `WARNING`:
573This level of logging should used when something serious and unexpected
574happened, i.e. something that will have user-visible consequences but is
575likely to be recoverable without data loss by performing some explicit action,
576ranging from waiting or restarting an app all the way to re-downloading a new
577version of an application or rebooting the device. This level is always
578logged. Issues that justify some logging at the WARNING level might also be
579considered for reporting to a statistics-gathering server.
580
581- `INFORMATIVE:`
582This level of logging should used be to note that something interesting to
583most people happened, i.e. when a situation is detected that is likely to have
584widespread impact, though isn't necessarily an error. Such a condition should
585only be logged by a module that reasonably believes that it is the most
586authoritative in that domain (to avoid duplicate logging by non-authoritative
587components). This level is always logged.
588
589- `DEBUG`:
590This level of logging should be used to further note what is happening on the
591device that could be relevant to investigate and debug unexpected behaviors.
592You should log only what is needed to gather enough information about what is
593going on about your component. If your debug logs are dominating the log then
594you probably should be using verbose logging.
595
596 This level will be logged, even
597on release builds, and is required to be surrounded by an `if (LOCAL_LOG)` or `if
598(LOCAL_LOGD)` block, where `LOCAL_LOG[D]` is defined in your class or
599subcomponent, so that there can exist a possibility to disable all such
600logging. There must therefore be no active logic in an `if (LOCAL_LOG)` block.
601All the string building for the log also needs to be placed inside the `if
602(LOCAL_LOG)` block. The logging call should not be re-factored out into a
603method call if it is going to cause the string building to take place outside
604of the `if (LOCAL_LOG)` block.
605
606 There is some code that still says `if
607(localLOGV)`. This is considered acceptable as well, although the name is
608nonstandard.
609
610- `VERBOSE`:
611This level of logging should be used for everything else. This level will only
612be logged on debug builds and should be surrounded by an `if (LOCAL_LOGV)` block
613(or equivalent) so that it can be compiled out by default. Any string building
614will be stripped out of release builds and needs to appear inside the `if (LOCAL_LOGV)` block.
615
616*Notes:*
617
618- Within a given module, other than at the VERBOSE level, an
619error should only be reported once if possible: within a single chain of
620function calls within a module, only the innermost function should return the
621error, and callers in the same module should only add some logging if that
622significantly helps to isolate the issue.
623
624- In a chain of modules, other than at the VERBOSE level, when a
625lower-level module detects invalid data coming from a higher-level module, the
626lower-level module should only log this situation to the DEBUG log, and only
627if logging provides information that is not otherwise available to the caller.
628Specifically, there is no need to log situations where an exception is thrown
629(the exception should contain all the relevant information), or where the only
630information being logged is contained in an error code. This is especially
631important in the interaction between the framework and applications, and
632conditions caused by third-party applications that are properly handled by the
633framework should not trigger logging higher than the DEBUG level. The only
634situations that should trigger logging at the INFORMATIVE level or higher is
635when a module or application detects an error at its own level or coming from
636a lower level.
637
638- When a condition that would normally justify some logging is
639likely to occur many times, it can be a good idea to implement some
640rate-limiting mechanism to prevent overflowing the logs with many duplicate
641copies of the same (or very similar) information.
642
643- Losses of network connectivity are considered common and fully
644expected and should not be logged gratuitously. A loss of network connectivity
645that has consequences within an app should be logged at the DEBUG or VERBOSE
646level (depending on whether the consequences are serious enough and unexpected
647enough to be logged in a release build).
648
649- A full filesystem on a filesystem that is acceessible to or on
650behalf of third-party applications should not be logged at a level higher than
651INFORMATIVE.
652
653- Invalid data coming from any untrusted source (including any
654file on shared storage, or data coming through just about any network
655connections) is considered expected and should not trigger any logging at a
656level higher then DEBUG when it's detected to be invalid (and even then
657logging should be as limited as possible).
658
659- Keep in mind that the `+` operator, when used on Strings,
660implicitly creates a `StringBuilder` with the default buffer size (16
661characters) and potentially quite a few other temporary String objects, i.e.
662that explicitly creating StringBuilders isn't more expensive than relying on
663the default '+' operator (and can be a lot more efficient in fact). Also keep
664in mind that code that calls `Log.v()` is compiled and executed on release
665builds, including building the strings, even if the logs aren't being
666read.
667
668- Any logging that is meant to be read by other people and to be
669available in release builds should be terse without being cryptic, and should
670be reasonably understandable. This includes all logging up to the DEBUG
671level.
672
673- When possible, logging should be kept on a single line if it
674makes sense. Line lengths up to 80 or 100 characters are perfectly acceptable,
675while lengths longer than about 130 or 160 characters (including the length of
676the tag) should be avoided if possible.
677
678- Logging that reports successes should never be used at levels
679higher than VERBOSE.
680
681- Temporary logging that is used to diagnose an issue that's
682hard to reproduce should be kept at the DEBUG or VERBOSE level, and should be
683enclosed by if blocks that allow to disable it entirely at compile-time.
684
685- Be careful about security leaks through the log. Private
686information should be avoided. Information about protected content must
687definitely be avoided. This is especially important when writing framework
688code as it's not easy to know in advance what will and will not be private
689information or protected content.
690
691- `System.out.println()` (or `printf()` for native code) should
692never be used. System.out and System.err get redirected to /dev/null, so your
693print statements will have no visible effects. However, all the string
694building that happens for these calls still gets executed.
695
696- *The golden rule of logging is that your logs may not
697unnecessarily push other logs out of the buffer, just as others may not push
698out yours.*
699
700### Be Consistent ###
701
702Our parting thought: BE CONSISTENT. If you're editing code, take a few
703minutes to look at the code around you and determine its style. If they use
704spaces around their if clauses, you should too. If their comments have little
705boxes of stars around them, make your comments have little boxes of stars
706around them too.
707
708The point of having style guidelines is to have a common vocabulary of
709coding, so people can concentrate on what you're saying, rather than on how
710you're saying it. We present global style rules here so people know the
711vocabulary. But local style is also important. If code you add to a a file
712looks drastically different from the existing code around it, it throws
713readers out of their rhythm when they go to read it. Try to avoid this.</p>
714
715## Javatests Style Rules ##
716
717### Follow Test Method Naming Conventions ###
718
719When naming test methods, you can use an underscore to seperate what is
720being tested from the specific case being tested. This style makes it easier
721to see exactly what cases are being tested.
722
723For example:
724
725 testMethod_specificCase1 testMethod_specificCase2
726
727
728 void testIsDistinguishable_protanopia() {
729 ColorMatcher colorMatcher = new ColorMatcher(PROTANOPIA)
730 assertFalse(colorMatcher.isDistinguishable(Color.RED, Color.BLACK))
731 assertTrue(colorMatcher.isDistinguishable(Color.X, Color.Y))
732 }
733