1 /*
2  * Copyright (C) 2023 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 android.federatedcompute.common;
18 
19 import static android.federatedcompute.common.TrainingInterval.SCHEDULING_MODE_ONE_TIME;
20 
21 import static com.google.common.truth.Truth.assertThat;
22 
23 import static org.junit.Assert.assertThrows;
24 
25 import androidx.test.ext.junit.runners.AndroidJUnit4;
26 
27 import org.junit.Test;
28 import org.junit.runner.RunWith;
29 
30 @RunWith(AndroidJUnit4.class)
31 public final class ScheduleFederatedComputeRequestTest {
32     private static final String POPULATION_NAME = "population";
33 
34     @Test
buildScheduleFederatedComputeRequest_success()35     public void buildScheduleFederatedComputeRequest_success() {
36         ScheduleFederatedComputeRequest request =
37                 new ScheduleFederatedComputeRequest.Builder()
38                         .setTrainingOptions(
39                                 new TrainingOptions.Builder()
40                                         .setPopulationName(POPULATION_NAME)
41                                         .setTrainingInterval(
42                                                 new TrainingInterval.Builder()
43                                                         .setSchedulingMode(SCHEDULING_MODE_ONE_TIME)
44                                                         .build())
45                                         .build())
46                         .build();
47 
48         assertThat(request.getTrainingOptions().getPopulationName()).isEqualTo(POPULATION_NAME);
49     }
50 
51     @Test
testScheduleFederatedComputeRequestEquals()52     public void testScheduleFederatedComputeRequestEquals() {
53         ScheduleFederatedComputeRequest request1 =
54                 new ScheduleFederatedComputeRequest.Builder()
55                         .setTrainingOptions(
56                                 new TrainingOptions.Builder()
57                                         .setPopulationName(POPULATION_NAME)
58                                         .setTrainingInterval(
59                                                 new TrainingInterval.Builder()
60                                                         .setSchedulingMode(SCHEDULING_MODE_ONE_TIME)
61                                                         .build())
62                                         .build())
63                         .build();
64         ScheduleFederatedComputeRequest request2 =
65                 new ScheduleFederatedComputeRequest.Builder()
66                         .setTrainingOptions(
67                                 new TrainingOptions.Builder()
68                                         .setPopulationName(POPULATION_NAME)
69                                         .setTrainingInterval(
70                                                 new TrainingInterval.Builder()
71                                                         .setSchedulingMode(SCHEDULING_MODE_ONE_TIME)
72                                                         .build())
73                                         .build())
74                         .build();
75 
76         assertThat(request1).isEqualTo(request2);
77     }
78 
79     @Test
buildNullTrainingOptions_failed()80     public void buildNullTrainingOptions_failed() {
81         assertThrows(
82                 NullPointerException.class,
83                 () -> new ScheduleFederatedComputeRequest.Builder().build());
84     }
85 }
86