LCOV - code coverage report
Current view: top level - server/account - EmailExpander.java (source / functions) Hit Total Coverage
Test: _coverage_report.dat Lines: 4 12 33.3 %
Date: 2022-11-19 15:00:39 Functions: 4 8 50.0 %

          Line data    Source code
       1             : // Copyright (C) 2009 The Android Open Source Project
       2             : //
       3             : // Licensed under the Apache License, Version 2.0 (the "License");
       4             : // you may not use this file except in compliance with the License.
       5             : // You may obtain a copy of the License at
       6             : //
       7             : // http://www.apache.org/licenses/LICENSE-2.0
       8             : //
       9             : // Unless required by applicable law or agreed to in writing, software
      10             : // distributed under the License is distributed on an "AS IS" BASIS,
      11             : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      12             : // See the License for the specific language governing permissions and
      13             : // limitations under the License.
      14             : 
      15             : package com.google.gerrit.server.account;
      16             : 
      17             : /** Expands user name to a local email address, usually by adding a domain. */
      18             : public interface EmailExpander {
      19             :   boolean canExpand(String user);
      20             : 
      21             :   String expand(String user);
      22             : 
      23             :   class None implements EmailExpander {
      24         152 :     public static final None INSTANCE = new None();
      25             : 
      26             :     public static boolean canHandle(String fmt) {
      27         152 :       return fmt == null || fmt.isEmpty();
      28             :     }
      29             : 
      30             :     private None() {}
      31             : 
      32             :     @Override
      33             :     public boolean canExpand(String user) {
      34          38 :       return false;
      35             :     }
      36             : 
      37             :     @Override
      38             :     public String expand(String user) {
      39           0 :       return null;
      40             :     }
      41             :   }
      42             : 
      43             :   class Simple implements EmailExpander {
      44             :     private static final String PLACEHOLDER = "{0}";
      45             : 
      46             :     public static boolean canHandle(String fmt) {
      47         152 :       return fmt != null && fmt.contains(PLACEHOLDER);
      48             :     }
      49             : 
      50             :     private final String lhs;
      51             :     private final String rhs;
      52             : 
      53           0 :     public Simple(String fmt) {
      54           0 :       final int p = fmt.indexOf(PLACEHOLDER);
      55           0 :       lhs = fmt.substring(0, p);
      56           0 :       rhs = fmt.substring(p + PLACEHOLDER.length());
      57           0 :     }
      58             : 
      59             :     @Override
      60             :     public boolean canExpand(String user) {
      61           0 :       return !user.contains(" ");
      62             :     }
      63             : 
      64             :     @Override
      65             :     public String expand(String user) {
      66           0 :       return lhs + user + rhs;
      67             :     }
      68             :   }
      69             : }

Generated by: LCOV version 1.16+git.20220603.dfeb750